Load Packages Automatically in RStudio

[This article was first published on Data and Analysis with R, at Work, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I recently finished a long stretch of work on a particular project that required me to draw upon four R packages.  Each time I got back to my work on the project, I’d have to load the packages manually, as needed.  It got really annoying and constantly made me wonder whether there was some way that I could just get these packages loaded automatically every time I switched to that project in R Studio so that I didn’t have to waste my time.

I finally got around to looking for an answer, and found it on an R Studio suggestions forum.  You create a .Rprofile file in your project directory within R Studio (see example below) or from a text editor, and then just type the library commands that call the R packages that you want.  Save it, and now every time you switch to your project in R Studio, the packages most relevant to your project will be loaded automatically!  See an example below of making the file from within R Studio:

> file.edit("~/Desktop/foo/.Rprofile")
# This opens up a script window, within which you can enter in your library commands
library(ggplot2)
library(scales)
library(plyr)
library(reshape2)

Easy!


To leave a comment for the author, please follow the link and comment on their blog: Data and Analysis with R, at Work.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)