问题
I just updated to R (3.4.1 "Single Candle") on my Linux Mint 18.1 Cinnamon machine and I attempted to install a package. R returned the following:
> install.packages('ggplot2')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("ggplot2") :
'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
NA
to install packages into? (y/n) y
Error in install.packages("ggplot2") : unable to create ‘NA’
I have encountered the 'lib not writable' output before but typically it offers a solution like this one:
Would you like to create a personal library
~/R/x86_64-pc-linux-gnu-library/3.4
to install packages into? (y/n) y
Any ideas why the personal library is suggesting NA? Is there a way to manually override this?
回答1:
After July 8, 2017 this will resolve all problems
sudo apt-get update
回答2:
I don't know what's causing this problem (i'm also experiencing it on Ubuntu 16.04), but here's a quick workaround:
.libPaths(c("/home/your_username/R/x86_64-pc-linux-gnu-library/3.4/", .libPaths()))
Of course, you can replace "/home/your_username/..."
for any another directory (that will store your personal library).
This solution makes install.packages()
and library()
work. Waiting for a full fix!
EDIT: I should note that this solution is not persistent. That is, it won't last after restarting R. You can fix this by adding the same line of code described above to the /home/your_username/.Rprofile
file.
回答3:
Looking at the details in @Dirk 's comment (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=866768) this is a planned behaviour so that packages are installed once for all users of the system.
The solution is to make /usr/local/lib/R/
writable for all users, rather than to re-instate the old behaviour of having a personal package library for every individual user.
Open up a terminal and:
- Navigate to
/usr/local/lib/
withcd /usr/local/lib/
- Change the owner:group so that all users can write to the folder. I happen to have a group on my computer that all users are a member of, so I used that, but see https://askubuntu.com/questions/66718/how-to-manage-users-and-groups for help with setting up a group if necessary
- To change ownership use
sudo chown owner:group -R R/
.owner
is an any user, it doesn't really matter.group
is the key one; make sure anyone wanting to use R on your system is a member of this group.-R
is recursive (i.e. do it to all files and folders inR/
). - If you need to change group permissions, use
chmod -R 775 R/
. This gives the owner and group read, write, and execute permissions, and gives all others read and execute permissions.
Now restart R and you should be able to install packages to your this shared location.
回答4:
My solution was the following:
In the file /usr/lib/R/etc/Renviron
there is a configuration of R.
In lines 43-45 there is:
# edd Jun 2017 Comment-out R_LIBS_USER
#R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
##R_LIBS_USER=${R_LIBS_USER-'~/Library/R/3.4/library'}
I have uncommented R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/3.4'}
, restarted RStudio and now it works.
EDIT: Looking at the comments, it seems like a planned behaviour. Here is another solution.
回答5:
The same happened to me while running the installation procedure for some Bioconductor packages.
Then I realized also I could write this (or similar) on the bash command line:
export R_LIBS_USER=$HOME/R/x86_64-pc-linux-gnu-library/3.4 && R
or
export R_LIBS_USER=$HOME/R/x86_64-pc-linux-gnu-library/3.4 && rstudio
and then run upgrade.packages()
(or install.packages()
, or biocLite()
) inside R.
This way the change is temporary, and you don't have to update any config files.
This shell command is useless if subsequently a command in .Renvironor
.Rprofile` sets R_USER_LIBS to a different location during R startup (-check your configuration).
Sticking with in $HOME/R/x86_64-pc-linux-gnu-library/3.X can be desirable if you have already lots of packages in this location, you want them upgraded/installed there. I have lots of Bioconductor packages in there, and I don't want them to download again, some of these packages download huge "Omics" datasets when used. Maybe the partition where /usr/local/lib/R resides has too little disk space or is on a slow drive.
回答6:
May be this is a bug of R 3.4.1, and my solution is change the line of
R_LIBS_SITE=${R_LIBS_SITE-'/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library'}
in /etc/R/Renviron
file into
R_LIBS_SITE=${R_LIBS_SITE-'~/R/x86_64-pc-linux-gnu-library/3.4.1:/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library'}
来源:https://stackoverflow.com/questions/44861967/r-3-4-1-single-candle-personal-library-path-error-unable-to-create-na