"hydrating" a packrat repository on a new computer?



I wrote a paper for a special reproducible issue of Computational Statistics. All the materials are actually available here, https://github.com/COSTDataExpo2013/AmeliaMN, including a packrat directory with the versions of packages I was using the last time I modified the code (~3 years ago). For example, dplyr version 0.4.1. I'd like to use these old package versions when I run the code, so I don't have to refactor everything. I think this is essentially the intended use-case of packrat!

In the intervening time, I moved institutions and no longer had the code on my computer. But, since everything is on GitHub I thought I'd be fine! I used the RStudio GUI to create a New Project from Version Control, and all the files were successfully populated onto my computer. But, the Version Control project creation walkthrough does not have a "use packrat with this package" checkbox. I would guess that ordinarily, RStudio would be looking for some sort of flag in the Rproj file or similar, to decide whether to use packrat or not. My packrat directory only has a src subdirectory, not a lib subdirectory, so I wonder if packrat has changed in the intervening years and I didn't have the right files there to flag it as a packrat directory? I do see an option to "git ignore packrat library," so maybe I actually have the right files, but not the right options elsewhere. Whatever the case, my project did not start out with "use packrat with this project" checked in the Project Options. I've tried a couple things, but can't seem to "hydrate" the project on my new computer.

Can someone give me some guidance about how to get all the old versions of packages hooked up correctly on my new computer? I tried adding the packrat directory to the "Local repositories" box in the Project Options, but that doesn't seem to have done it.


If you have packrat/packrat.lock, you should be good to go! packrat::restore() from the project root should get you started! You will need to be able to compile packages from source, but that is a pretty usual requirement in R.

EDIT: Also, if you want your RStudio to automatically do this type of thing on startup, you just need to add the default packrat .Rprofile to version control in the future. It sources the packrat/init.R script to do this automatically when you start your R session.


Ah, that helps! What is my recourse when one of the packages fails? In this case, it seems like Rcpp isn't installing properly. I don't know that I actually need Rcpp (probably just got wrapped into packrat because I had it on my old computer...) so is there a way to remove that as a package?

EDIT: Seems like Rcpp is a dependency for something I actually do need, and my issue is probably C++ related on the new machine. I'll struggle with this a bit more.


Yeah, this is where packrat can become painful :slight_smile: Rcpp is necessary to build dplyr, for instance, so it got roped in as a dependency. You can remove it, but then your installation of dplyr will likely fail. One of the challenging things about R package management over time is that building packages from source is a firm requirement. Do you have more information you can share about how the package is failing to install? What operating system are you on? There is a fair amount of information out on the web on getting your system building packages from source.