I am running R on Windows, not as an administrator. When I install a package, the following command doesn\'t work:
> install.packages(\"zoo\")
Installing
If you want to change your library path permanently (without calling .libPath() every time when entering in R, this works for me:
create .Rprofile under your home directory. (~/.Rprofile)
type
.libPaths(c( .libPaths(), "your new path" ))
in .Rprofile file, save.
open R (any directory) and check, just type .libPaths()
, you can find your libaray path is updated!
I managed to solve the problem by placing the code in the .Rprofile
file in the default working directory.
First, I found the location of the default working directory
> getwd()
[1] "C:/Users/me/Documents"
Then I used a text editor to write a simple .Rprofile
file with the following line in it
.libPaths("C:/software/Rpackages")
Finally, when I start R
and run .libPaths()
I get the desired output:
> .libPaths()
[1] "C:/software/Rpackages" "C:/Program Files/R/R-2.15.2/library"
[3] "C:/Program Files/RStudio/R/library"
If your default package library has been changed after installing a new version of R or by any other means, you can append both the libraries to use all the packages with the help of the commands below. Get the existing library path :
.libPaths()
Now,set the existing and the old path :
.libPaths(c(.libPaths(), "~/yourOldPath"))
Hope it helps.
The proper solution is to set environment variable R_LIBS_USER
to the value of the file path to your desired library folder as opposed to getting RStudio to recognize a Rprofile.site file.
To set environment variable R_LIBS_USER
in Windows, go to the Control Panel (System Properties -> Advanced system properties -> Environment Variables -> User Variables) to a desired value (the path to your library folder), e.g.
Variable name: R_LIBS_USER
Variable value: C:/software/Rpackages
If for some reason you do not have access to the control panel, you can try running rundll32 sysdm.cpl,EditEnvironmentVariables
from the command line on Windows and add the environment variable from there.
Setting R_LIBS_USER will ensure that the library shows up first in .libPaths() regardless of starting RStudio directly or by right-clicking an file and "Open With" to start RStudio.
The Rprofile solution can work if RStudio is always started by clicking the RStudio shortcut. In this case, setting the default working directory to the directory that houses your Rprofile will be sufficient. The Rprofile solution does not work when clicking on a file to start RStudio because that changes the working directory away from the default working directory.
just change the default folder for your R libraries in a directory with no Administrator rights, e.g.
.libPaths("C:/R/libs")
Since most of the answers here are related to Windows & Mac OS, (and considering that I also struggled with this) I decided to post the process that helped me solve this problem on my Arch Linux setup.
Step 1:
Renviron
(which is the configuration file where the settings for the user libraries are set)./etc/R/
/usr/lib/R/etc/
Renviron
config files stored at 1 & 2 (above) are hot-linked to each other (which means changes made to one file will automatically be applied [ in the same form / structure ] to the other file when the file being edited is saved - [ you also need sudo
rights for saving the file post-edit ] ).Step 2:
/etc/R/
) and open the Renviron
file with your favourite text editor.Renviron
file search for the R_LIBS_USER
tag and update the text in the curly braces section to your desired directory path. R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/4.0'}
R_LIBS_USER=${R_LIBS_USER-'~/Apps/R/rUserLibs'}
Step 3:
Renviron
file you've just edited ... DONE !!