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 :PROPERTIES: :header-args: :tangle ~/org/studies/study_in_R :END: #+BEGIN_SRC R :session *R* :dir :results silent setwd("~/org/studies/study_in_R") #+END_SRC
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 :PROPERTIES: :header-args: :tangle ~/Code/R.R :END: * 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:
- What is the best way to migrate my legacy R packages into the
- And what about my R function library? Should I tangle this into one giant
omniversewhich 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.Rand loaded through
renvsmart enough to pick out
library()calls from different functions that my projects reference from
- 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?
- There are some packages that I may want to share with all projects (
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?
- How do I manage multiple versions of R?
pyenvdoes a fantastic job of managing multiple versions of python. And
condaconveniently treats python and R as any other package... If I want a specific version of R in my project, is there a way to