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:

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:

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

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


← Chris Hamm on using plot.new() for better combined plots | All posts | Dynamics of Coupled Nutrient Cycling and Acclimation: 3 Modeling Papers →