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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With