Library is not writable
Solution 1:
For R version 3.2.2 (2015-08-14) this problem should be dealt with since R suggests within the installation process a different path to store your R libraries. The installation looks like this: (Here 'random' is used as an example package)
install.packages('random')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("random") :
'lib = "/usr/local/lib/R/site-library"' is not writable
Would you like to use a personal library instead? (y/n) y
Would you like to create a personal library
~/R/pc-linux-gnu-library/3.2
to install packages into? (y/n) y
So during the installation answering both questions with 'y' should install the package correctly.
Update 18/01/19
In case you don't want to store your R packages in an additional file:
As Antoine-Sac and Robert TheSim point out you can add yourself to the staff group in order to be able to write to 'site-library'. (Click on the names to see their important additions)
Before this update I mentioned in this comment the option of changing the permission of the folder 'site-library' using 'chmod o+w' in order to be able to write to it. Assuming security issues but unable to tell at the time I warned about it but have primarily been waiting for somone to clear this up. Antoine-Sac and Robert TheSim have done so in the meantime. Thanks!
Solution 2:
add yourself to the group called 'staff'
sudo usermod -a -G staff your_user_name
replace your_user_name with your login username, then logoff and relogin.
DO NOT use chmod 777 which is a breach of security and btw. a complete non-sense!!!
Solution 3:
If you are on Windows, you can run R (or RStudio) as an administrator.
Close your R, then go to the R or RStudio icon, right-click and "open as administrator". It works perfectly, all error messages while installing packages are gone forever.