1

I'm using hosted RStudio on linux centos. When I try to install packages I get a non zero exit status error. I've already installed R-devel.

From reading the output to r console when trying to install packages it looks my user cannot access the default library path.

I read this SO post about adding a new library directory and even making it the default one.

Within RStudio GUI, in the bottom right pane I created a new directory "mylibs".

I tried adding to libPaths() per the SO post:

.libPaths( c( .libPaths(), "~/mylibs") )

Then I typed .libPaths().

.libPaths()
[1] "/home/rstudio/R/x86_64-redhat-linux-gnu-library/3.4"
[2] "/usr/lib64/R/library"                               
[3] "/usr/share/R/library"   

So it looked like that failed. I wondered if I had not specified the correct directory. So, in RStudio I typed getwd() which shows that I'm in "/home/rstudio". So, I then tried: .libPaths( c( .libPaths(), "~/home/rstudio/mylibs") )

However, when I checked .libPaths() there was no change, the same 3 shown above.

How can I add mylibs dir to .libPaths() so that I can download and install packages?

Doug Fir
  • 19,971
  • 47
  • 169
  • 299
  • Does the "~/mylibs" folder actually exist. The `.libPaths()` function won't add a folder if it doesn't exist. Also, just to be clear, the `~` will expand to your home directory (not the current working directory). If the folder you are trying to specify is not in your home directory, you don't need that part. It would be better to use a fully qualified path (start with "/"). – MrFlick Oct 04 '18 at 19:09

1 Answers1

2

Calling .libPaths() prepends as order is from left to right. On this CentOS machine:

R> .libPaths()
[1] "/home/USER/R/x86_64-redhat-linux-gnu-library/3.4" "/usr/local/lib/R/site-library"
[3] "/usr/lib64/R/library"                             "/usr/share/R/library"  
R>
R> .libPaths("/tmp")   # adding in session
R> .libPaths()
[1] "/tmp"                  "/usr/local/lib/R/site-library"
[3] "/usr/lib64/R/library"  "/usr/share/R/library"         
R> 

You can govern what gets in there via the different "dot" files read at startup, ie .Renviron, .Rprofile and more. See help(Startup) for all the gory details.

Edit: Regarding @MtFlick's comment:

R> .libPaths("/DoesNotExist")
R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib64/R/library"   
[3] "/usr/share/R/library"         
R> 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725