In my experience, creating a file named Renviron.site did not work on all my Windows machines, whereas naming the same file .Renviron instead did work everywhere. Not sure why. So if you're having difficulty with the above suggestions, then try .Renviron for a name.
Please do not hesitate to critically comment about my suggestion, because while I am describing what has worked for me, it may have difficulties I am not aware of.
In my experience, the following has worked:
Both Windows and Linux Platform:
Setting R paths
Find out the default paths:
.libPaths()
Set the path temporarily (in a R script)
.libPaths( "F:/Rlib" )
where F could be the letter associated with, say, a USB drive.
Query paths (both Windows and Linux):
Sys.getenv('R_LIBS_USER')
Sys.getenv('R_LIBS')
Sys.getenv('R_USER')
Sys.getenv('R_DOC_DIR')
Sys.getenv('HOME')
Try also:
normalizePath("~")
Try also:
getwd()
setwd(dir)
getwd returns an absolute filepath representing the current working directory of the R process
setwd(dir) is used to set the working directory to dir.
Windows (Tested on: 7x64)
Create an environment file named .Renviron
place it in the working directory or home directory:
"C:/Users/username/Documents"
Some users have reported that the .Renviron file needed to be in "c:/users/username/" instead. If you're not sure where to place it, save the desktop history and see where the .Rhistory file is located. Then place your .Renviron file in the same location. To save history savehistory()
# Windows .Renviron file:
R_LIBS_USER="C:/R/library"
R_USER="C:/R"
R_DOC_DIR="C:/R"
HOME="C:"
Set global PATH
My Computer / Properties / Advanced System Settings / Environment Variables --> user variables --> Path --> Edit
c:\R;c:\R\library;
Linux (Tested on kUbuntu 12.10)
Create an environment file named Renviron.site
place it in:
/etc/R/
Query the paths to check that your system is reading the Renviron.site file.
# Linux Renviron.site file:
R_LIBS_USER="~/R/library"
R_USER="~/R"
R_DOC_DIR="~/R"
#HOME="/home" # may not be needed
Remark: afaik the file is read from bottom to top, so HOME is defined at the bottom. In my setup ~ is correctly assigned to /home/ so I omit that last line anyway.
If you use RStudio, you may also want to add an rsession.conf file in the RStudio program directory. The following has worked for me:
# Windows 7:
r-libs-user="C:/R/library"
# Kubuntu 12:
# r-libs-user=~/R/%p-library/%v