Ryan Peek on Customizing Your R Setup

November 2, 2012

(This article was first published on Noam Ross - R, and kindly contributed to R-bloggers)

Ryan Peek showed us how to use an .Rprofile file to customize your R setup. Here are his instructions and script:

For Windows

  • To change profile for R, go here:

    C:\Program Files\R\R-2.15.1\etc (or whatever version you are using)

  • Edit the “Rprofile.site” file
  • Restart R

For Macs

  • Create your Rprofile file. -use TextEdit or another editor to create a file called Rprofile.txt

  • In a terminal window, type:

    >> cp Rprofile.txt .Rprofile

    (which copies the visible Rprofile.txt to the invisible .Rprofile)

    • You can check this by doing >ls -la again to see it in the directory listing.
  • Restart R

Note that you can save .Rprofile in your home directory, or, if you are using R Studio, in a project directory. In the latter case, the profile will only be loaded when you load that project.

Things to put in the .Rprofile file:

Set a local CRAN Mirror:

local({r <- getOption("repos")
       r["CRAN"] <- "http://cran.cnr.berkeley.edu/"

Set machine-specific options: If you use Dropbox or something similar to sync R files across computers, you can use Sys.info() to set options specifically for your machine. This code sets the root path differently for different machines:

if(Sys.info()[4]=="Work-PC") {
} else if(Sys.info()[4]=="Mac.local") {
} else {

Set a welcome message and load a file of other useful functions: Anything in the .First function is run on startup

.First <- function(){
    cat("\nWelcome to R!\n",sep="")
        cat("RbasicFunctions_example.r was loaded, providing the following functions:\n\n",sep="")
        cat("use  'print.functions()'  to view\n",sep="")

Helper functions

Here’s Ryan’s file, called above as RbasicFunctions_example.r, which has his helper functions. Running print.functions() will display a list of these with short explanations:

A lot of other useful options for R profile files are found in this Stack Overflow discussion

To leave a comment for the author, please follow the link and comment on their blog: Noam Ross - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)