11

I'm trying to work out why my .libPath is different between command-line R and RStudio Desktop (NOTE: this is not a duplicate of this question as that fix involved stuff specific to RStudio Server which I don't have).

When I use R on the command-line (linux):

> .libPaths()
[1] "/home/mathematicalcoffee/R/library"  "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"             "/usr/lib/R/library"           

When I use RStudio Desktop (linux, same machine):

[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"       "/usr/lib/R/library"            "/usr/lib/rstudio/R/library"  

Now I have set $R_LIBS_USER to ~/R/library in my bash profile, so R-command-line picks it up as my preferred libPath.

The problem is in RStudio Desktop when I do:

Sys.getenv('R_LIBS_USER')
# "~/R/x86_64-pc-linux-gnu-library/2.15"

So why has RStudio Desktop changed my R_LIBS_USER? How can I change it back? (I don't use an .Rprofile file). (In the question I linked above the solution for RStudio Server was to modify /etc/rstudio/rsession.conf, but I don't have that as I've got RStudio Desktop. Also, I believe RStudio should be respecting my R_LIBS_USER environment variable.)

4
  • 4
    Try setting R_LIBS_USER inside your $R_HOME/etc/Renviron file.
    – flodel
    Commented Apr 17, 2013 at 1:19
  • Thanks @flodel, that worked. Guess RStudio wasn't reading my .bashrc Commented Apr 17, 2013 at 2:09
  • @DWin OK. I was about to delete the question to reask over at the rstudio support but now it won't let me because it has answers. Am happy for it to be closed Commented Apr 17, 2013 at 2:10
  • @mathematical.coffee It skips reading .bashrc but does respect what is in .profile if that helps you at all.
    – Dason
    Commented Apr 17, 2013 at 2:48

2 Answers 2

12

You write:

Now I have set $R_LIBS_USER to ~/R/library in my bash profile,

Do you by chance call RStudio from a gui icon, ie without invoking your ~/.bash_profile ? Maybe you can try calling a wrapper instead which sets it?

For what it is worth, .libPaths() returns the same thing under RStudio Desktop and Server (though Server appends its internal directory), R on the command-line and via ESS for me.

Edit: And in general, do read help(Startup) which will be time well-spent. The comment by @flodel is quite appropriate. If you get lost dealing with this consistently at the system level, you can always turn to R, either at its system-level (via Renviron and Renviron.site) or via the ~/R/ directory.

1

Just to document here in case someone finds it useful, according to ArchWiki we can define R_LIBS_USER in ~/.Renviron, which I feel is a more convenient way to define specific variables for R.

Not the answer you're looking for? Browse other questions tagged or ask your own question.