Skip to content
Custom functions to source when starting R
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


R has features to allow you to customize the start-up protocols. These are often used to automatically load packages or custom functions that you use regularly, or to change default settings. These settings can be saved in a file that is saved in your R directory.

For some examples, check out:

Your File

After creating your profile script, you need to add it to your R program directory.

In the Windows environment you can usually add your file to your R directory at:

C:\Program Files\R\R-3.3.1\etc

Sourcing External Functions

The script includes a function called .First. R will automatically run this function on start-up.

This is a good place to load packages that you regularly use. You can also use it to source an external script.

I have started placing my preferred customization steps into a script on GitHub, as it is easy to update and maintain, and I can retain the same user experience across many different computers. I have included a line to source this script in the .First function. This links to the source-me.R script in this repository.

.First <- function(){
 library( dplyr )
 source( "" )

Example Script

# Things you might want to change

# do not convert strings to factors automatically
options( stringsAsFactors=FALSE )

# do not use scientific convention except for large numbers
options( scipen=8 )

# set your mirror so you do not get asked when installing packages
local({r <- getOption("repos")
      r["CRAN"] <- ""

# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")

# set the default help type
# options(help_type="text")

# set a site library
# <- file.path(chartr("\\", "/", R.home()), "site-library")

# set a CRAN mirror
# local({r <- getOption("repos")
#       r["CRAN"] <- "http://my.local.cran"
#       options(repos=r)})

# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
#  if (interactive()) 
#    fortunes::fortune()

.First <- function(){
 library( dplyr )
 source( "" )
You can’t perform that action at this time.