Ryan Peek on Customizing Your R Setup

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

For Windows

For Macs

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