How to Configure R - dummies

How to Configure R

By Andrie de Vries, Joris Meys

Apart from accepting the options in the installation procedure for R, you can change a number of startup options by adapting the file. This file is located inside the installation directory, in the subfolder …/R-n.n.n/etc (for example, …/R-2.14.1/etc). The file is sourced by R at startup, so all R code in this file is carried out.

The default installation of R contains a perfectly valid file, so you have to change this only if you want to personalize your startup. is a normal text file, so you can edit it as you would any other text file. The file already contains some options that are commented out, so you get a good idea of what’s possible when you open the file in a text editor (such as Notepad). Be sure to check the Help page ?options to get more information on all possible options.

You can personalize R further by adding a code file called .Rprofile to your personal home folder. You can find this folder from within R by setting the working directory to “~/”, like this:

> setwd("~/")
> getwd()
[1] "C:/Users/Joris FA Meys/Documents

Adding an .Rprofile file isn’t necessary, but R will always look for one, either in the folder from which you call R or in the user’s home directory. Whereas an file is linked to a specific installation of R, the .Rprofile file can differ for every user on the same system.

If you update R, you can leave the .Rprofile file where it is and the new R version will automatically find it and apply the options you specified there. So, after updating R to the latest version, you have to adapt the again only if you want to personalize it.

Functions you define or objects you create with code in won’t be visible if you use ls(), although you can use them without trouble. This also means you can’t delete them easily from the workspace.

An or .Rprofile file may look like the following example:

# Sample profile file
# Set CRAN mirror to a default location
options(repos = "")
# R interactive prompt
options(prompt="R: ")
# sets work directory back to original
go.home <- function() setwd("D:/MyWorkspace")

With this file, R will start up with a different prompt (R: instead of >) and set the server from the UK as the default server from which to install packages. You also define the go.home() function, which you can use at any point to set your working directory back to your home directory (D:/MyWorkspace, in this example.