0

Is it possible to install different package versions within a R personal library for one specific version of R; and then to be able to load the exact package version withing a script?

I am trying to make sure I have the exact package version binaries for Windows backed up offsite for each project, so that if I need to reproduce in future, I can then paste these back into the personal library folder, under the relevant R version. So potentially, you could have two package versions within the same R version folder under R\win-library. However I notice there is no version number attached to each packages folder, so I'm not sure how R would identify each version.

CK7
  • 229
  • 1
  • 11

1 Answers1

1

It sounds like you want to spend some time learning about packrat. It allows a user to have a separate library of packages for each project so there aren't any issues with reproducibility later in the future due to a package updating and possibly breaking other code.

Here is a link to some intro documentation: https://rstudio.github.io/packrat/

Dason
  • 60,663
  • 9
  • 131
  • 148
  • I've been looking at it, but wondering if it isn't going to create unnecessary duplication each time it creates a private library, and also I wonder whether it is perhaps safer to just stick with the binaries instead of recreating from source each time. Also considered checkpoint() but it seems to load everything available on a certain date on Cran rather than specific versions you have used in your code (would be handy if you could specify the exact package version when loading libraries in code and it could pick this up when scanning your code in the project folder). – CK7 May 15 '19 at 13:55
  • Also, should point out it creates a unique .Rprofile for each project which might be an issue, unless you stay with packrat for each project. – CK7 May 15 '19 at 14:07
  • @CK7 Well with checkpoint you would just specify the date you start the project and then all the versions will match up even if you have to reinstall later. And yes... if you use packrat the idea is that you use it for the duration of the project. A unique .Rprofile is how I believe it does the 'magic' it needs to to make sure you point to the package's private library. I guess I'm not really understanding what your objection to these approaches are – Dason May 15 '19 at 15:00
  • Right it looks as though checkpoint might be closer to what I need. My main objection is that it installs all the packages available from the snapshot of Cran on a certain day. During a project you may install packages months apart sometimes. – CK7 May 15 '19 at 15:45
  • @CK7 - maybe but if you use checkpoint it will install the older version and things are much more likely to work well together if you're installing versions that were all present on CRAN at the same time. If you want to use the package version that you installed months later instead I'm not understanding why you think checkpoint is closer to what you need because packrat would happily do that for you. – Dason May 15 '19 at 15:56
  • I'll try packrat as well then. I tried checkpoint () but it fails to load the officer package, and gives me various error messages. – CK7 May 15 '19 at 19:15