8

I am working with a "factory fresh" version of RStudio on Windows 7. R is installed under C:/Program Files which means the default libraries are stored here, and the two locations contained in .libPaths() on startup are both within this folder.

I want to work with another R library (igraph). Since the C:\Program Files folder is write-protected, I have set up another area to work in: C:\Users\nick\R and installed the igraph library in C:\Users\nick\R\library. I can manually add this location to the .libPaths() variable and use the library with no problems.

However, my problem is getting RStudio to automatically add this location to the .libPaths() variable on startup. I read that I could add the relevant command to my .Rprofile file - but I couldn't find any such file (presumably they are not automatically created when RStudio is installed). I then created a file called .Rprofile containing only this command. This only seemed to work when the .Rprofile file was saved in C:\Users\nick\Documents (which is the path stored in both the R_USER and HOME environmental variables). What I would like is to have the .Rprofile file stored in C:\Users\nick\R.

I have read all the information in ?Startup and it talks about where to store commands that run on startup. But I just can't make this work. For example there seems to be no way to change the location of the home directory without reading a file stored in the home directory. I don't seem to have any .Renviron files and creating these myself doesn't seem to work either.

I would really appreciate an answer in simple terms that explains how I could go about changing where the .Rprofile file is read from.

Nick
  • 366
  • 1
  • 4
  • 10
  • Does [this](http://stackoverflow.com/questions/15217758/remove-a-library-from-libpaths-permanently-without-rprofile-site/15218299#15218299) help? – agstudy Mar 05 '13 at 14:20
  • It looks like it might if I understood it :-) Am I supposed to run an R_LIBS=xxx command using cmd in Windows (i.e. outside of R)? – Nick Mar 05 '13 at 14:33
  • yous set windows environment variable. (panel settings...) – agstudy Mar 05 '13 at 14:35
  • Thanks - this has done the trick for adding a new library path. My specific issue appears to be solved. Would still be interested in how the .Rprofile file can be relocated though – Nick Mar 05 '13 at 15:00
  • .Rprofile is set through R_USER at the begining of session. SO what is your question? – agstudy Mar 05 '13 at 15:01
  • In that case I suppose the question must be how to change what is stored in R_USER. Can this also be done through windows control panel? – Nick Mar 05 '13 at 15:20

1 Answers1

2

In Windows, you set the R_USER profile by opening up a command line and running:

SETX R_PROFILE_USER "C:/.../.Rprofile"

Where (obviously) the path is the path to your desired .Rpofile. In R, you can check that it worked:

Sys.getenv("R_PROFILE_USER")

Should return the path you specified. Note that you likely need to have all R sessions closed before setting the R_USER variable.