Ron Cohen
Ron Cohen

Reputation: 2925

R Studio - Reload Packages

New to R. Using R Studio 0.99.467. I have multiple projects. I know that I can save/load data for each in .RData files. I would like, however, to save each as a complete "project" including packages. Currently I have to manually reload distinct packages for each project. I understand that this can be done via library() calls in .Rprofile, but this (I think) would load all packages for all projects as opposed to only loading the packages needed for each project. I know one can save/load the Workspace, but my understanding is that this does not reload packages. Is there a way to save/load everything for a project, including packages, so that I can "snapshot" an entire project and resume work on it later? Thanks!

Upvotes: 0

Views: 197

Answers (1)

Jonathan
Jonathan

Reputation: 8812

Two things:

  1. R reads .Rprofile not only from your home directory, but also from the current directory when it starts (full documentation on startup behavior can be found here). Conveniently, RStudio starts R in the project directory when you open a project, so you can put a .Rprofile in your project's directory for commands you want to run every time you open that specific project.

  2. If you want to be able to manage packages for each project separately (so your project's packages and versions thereof stick with it), there's an R package called Packrat that does just that, and it integrates with RStudio. More here: http://rstudio.github.io/packrat/

Upvotes: 1

Related Questions