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)