Using to Startup R Studio

The .Rprofile file

By default R looks for and runs .Rprofile files in the three locations described above, in a specific order. .Rprofile files are simply R scripts that run each time R runs and they can be found within R_HOMEHOME and the project’s home directory, found with getwd(). To check if you have a site-wide .Rprofile, which will run for all users on start-up, run:

site_path = R.home(component = "home")
fname = file.path(site_path, "etc", "")

The above code checks for the presence of in that directory. As outlined above, the .Rprofile located in your home directory is user-specific. Again, we can test whether this file exists using


We can use R to create and edit .Rprofile (warning: do not overwrite your previous .Rprofile – we suggest you try project-specific .Rprofilefirst):

if(!file.exists("~/.Rprofile")) # only create if not already there
  file.create("~/.Rprofile")    # (don't overwrite it)

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

# Things you might want to change

# 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(){
cat(“\nWelcome, Nick, at”, date(), “\n”)

.Last <- function(){
cat(“\nGoodbye, Nick, at “, date(), “\n”)

#run at start