# installed version of R print(R.Version()) # system information print(Sys.info()) # known package repositories print(options()$repos) # package type to download for installing/updating print(options()$pkgType) # known library locations print(.libPaths())
# add sslib repository to front of existing list
options(repos=c("ftp://ftp.gns.cri.nz/pub/davidh/sslib/r-repo",
options()$repos))
# set package type for installing/updating
if (Sys.info()["sysname"]=="Windows") pkg.type <- "win.binary"
if (Sys.info()["sysname"]=="Linux") pkg.type <- "source"
# add a local library location (edit path below appropriately)
# you need to create the directory first
# can be useful if you do not have admin rights
# see help page for .libPaths() for more details
if (Sys.info()["sysname"]=="Windows") .libPaths("c:/My Stuff/R-local/libs")
if (Sys.info()["sysname"]=="Linux") .libPaths("/home/david/R-local/libs")
Note the use of / in the Windows paths too. R is developed in a UNIX environment where \ is used as a control character. This convention is also consistent with internet URLs.
Changed system settings can be saved in an R profile file, further details in topic Startup in the R base package. One firstly creates an R script as above.
One needs to distinguish whether the revised settings are for all users of the computer (system), or just personal.
/etc/R/Rprofile.siteOther UNIX environments will have a similar location.
/home/david/.Rprofile
C:\Program Files\R\R-3.4.1\etc\Rprofile.site
.Rprofilein the current directory, or home directory; see topic
Startup in the R base package for more discussion.
Some of the above options can be made, alternatively, by setting or resetting the system environment variables. For an overview of the settings that R uses at startup, see the topic Startup in the R base package. A list of recognised environment variables is given in topic EnvVar in the R base package.
Environment variables can be set within R using the function Sys.setenv, which is also part of the R base package. The environment variables can be stored in a number of places, so things could become messy if one is not systematic. For example, in a UNIX bash like environment, personal user libraries could be defined by placing
export R_LIBS_USER="/home/david/R-Local"into the
.bashrc file. The same can be achieved in Windows 10:Variable=R_LIBS_USER, Value=C:\R\libs