setting your working directory permanently in R

June 24, 2012

(This article was first published on geo-affine » R, and kindly contributed to R-bloggers)

Most of us R users are using a special working directory for the daily work in R. But I was bothered in typing everytime


in my command line prior using R. Also using this line at the first position in scripts was not pleasent enough.
So how to get around this? There is a special file in R for adjusting your startup-parameters. It is called “”. In a linux environment you may type:

sudo gedit /etc/R/

In a Windows OS you just need to search for the file mentioned above and open it up in an editor of your choice.
You will be confronted with the following lines:

##						Emacs please make this -*- R -*-
## empty for R on Debian
## Copyright (C) 2008 Dirk Eddelbuettel and GPL'ed
## see help(Startup) for documentation on ~/.Rprofile and

# ## Example of .Rprofile
# options(width=65, digits=5)
# options(show.signif.stars=FALSE)
# setHook(packageEvent("grDevices", "onLoad"),
#         function(...) grDevices::ps.options(horizontal=FALSE))
# set.seed(1234)
 .First <- function() cat("\n   Welcome to R!\n\n")
 .Last <- function()  cat("\n   Goodbye!\n\n")

# ## Example of
# local({
#  # add MASS to the default packages, set a CRAN mirror
#  old <- getOption("defaultPackages"); r <- getOption("repos")
#  r["CRAN"] <- "http://my.local.cran"
#  options(defaultPackages = c(old, "MASS"), repos = r)

Between the lines 14 and 15 you can set your start-up parameters. So by filling in


the startup directory will be set permanently to your desired working directory. Of course you can also add lines like

library("sp", "rgdal")

to increase your workflow. ENJOY!

To leave a comment for the author, please follow the link and comment on their blog: geo-affine » R. 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...

Tags: , , , , , , , , ,

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)