Skip to content

Rprofile

Matthew L. Bendall edited this page Apr 20, 2021 · 1 revision

R allows you to create an Rprofile, which defines standard settings when you are using R. (Similar in concept to a .bashrc file). Your Rprofile is written in R and is sourced whenever R is started up.

R user library

Users are not allowed to install R packages into the system library. However, it is easy to create a personal library for installing any packages you choose. Here are instructions on how to set this up:

Step 1: In your home directory, create a directory where R packages will be installed. R will create subdirectories within this directory depending on the version of R you are running.

mkdir .Rlibs

Now you want R to add this directory to the path on startup. You do this by adding a few lines your your Rprofile that determine the version of R you are running and selects (or creates) the appropriate directory.

Step 2: If needed, create a file called .Rprofile in your home directory using a text editor of your choice. Add the following lines to this file:

# Add user path to .libPaths
libdir <- paste0("~/.Rlibs/",R.Version()$major,".",R.Version()$minor)
if (!file.exists(libdir)) dir.create(libdir)
.libPaths(libdir)
rm(libdir)

Set default CRAN mirror

To avoid selecting CRAN mirror, add this to your .Rprofile:

# Set default repository
options("repos" = c(CRAN = "http://cran.r-project.org/"))
Clone this wiki locally