I do all my R development in Emacs via org-mode and ESS. All of my R projects are managed out of a single org-mode document (studies.org). Each project has a header and is tangled to its own project directory. This looks something like:

* A study in R
  :header-args: :tangle ~/org/studies/study_in_R

  #+BEGIN_SRC R :session *R* :dir :results silent



As I develop each project, I build functions that get moved to my function library (code.org). This gets tangled each time I save it and contains every (reusable) function I have ever written. It looks something like this:

* AppleScript
* Emacs Lisp
* Python
* R
  :header-args: :tangle ~/Code/R.R

  * Function 1
  * Function 2
* Shell
* Settings

Recently, I discovered Packrat and its successor renv. I love the idea of ring-fencing my projects into virtual environments. But I'm struggling with the implementation.

So here are a couple of questions:

  1. What is the best way to migrate my legacy R packages into the renv packages cache?
  2. And what about my R function library? Should I tangle this into one giant omniverse which gets installed into all of my R projects? Or would that defeat the purpose of segmenting my packages? If I leave it as is (tangled to ~/Code/R.R and loaded through .Rprofile) is renv smart enough to pick out library() calls from different functions that my projects reference from R.R?
  3. If I am developing my code in studies.org (which is not in my projects directory) and this is referencing additional functions from code.org (also not in my projects directory) how does renv::hydrate() know to auto-add dependencies to my project? Do I need to tangling r projects to their respective project folders first?
  4. There are some packages that I may want to share with all projects (roxygen2, devtools, usethis, etc.). How should I install these to my packages cache? And how should I reference them in my projects? Can I identify a default or base set of packages that are auto-added to every project? If I just install these with install.packages() will this get the job done?
  5. How do I manage multiple versions of R? pyenv does a fantastic job of managing multiple versions of python. And conda conveniently treats python and R as any other package... If I want a specific version of R in my project, is there a way to renv::install(r@3.4.4)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.