17 Dependency Management
How do I make sure that all my software and configurations needed for a projects are portable?
renv captures package versions and sources as well as R version.
renv
also records python versions and virtual environments for projects that used both languages.- The capsule package can be useful when you want version control/depedency management but not the full weight of
renv
. Sometimes,renv
can be an impediment for smaller and highly collaborative projects, that is where capsule can be useful. Ultimately, capsule will allow to setuprenv
for a project when it gets to a stable state.
- The capsule package can be useful when you want version control/depedency management but not the full weight of
Docker allows you to create virtual machines, meaning you can capture all system dependencies in addition to the dependencies captured in
renv
. It works for essentially any programming language and is extremely flexible.Makefiles can automate a complex, multipart project. Here’s a lesson on them from Software Carpentry
R packages can be a useful project output. We have some in-house R packages to provide access to internal data and generate reports, and may be developing more for external audiences. Hadley Wickham’s R Packages Book provides guidance for these, and we expect our packages to be up to rOpenSci standards.
17.1 GCC and mac silicon
- R package installation can be especially tricky on Mac computers with Apple Silicon. Below are some steps to get package install set ups.
Install the R compilation tool chain https://mac.thecoatlessprofessor.com/macrtools/. If any issues with FORTRAN, follow instructions for downloading FORTRAN compiler here for Apple silicon Macs: https://mac.r-project.org/tools/
Install gcc
brew install gcc
. This requires having brew set up.Make sure homebrew is in terminal path. Add it by
export PATH=$PATH:/opt/homebrew/bin
.Create
~/.R/Makevars
and insert the following. This will need to be updated depending on gcc version.
CXX14FLAGS += -O3 -arch arm64 -ftemplate-depth-256
FC = /opt/homebrew/Cellar/gcc/13.2.0/bin/gfortran
F77 = /opt/homebrew/Cellar/gcc/13.2.0/bin/gfortran
FLIBS = -L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/13
RStudio may have a bug in accessing the correct terminal path. The workaround is to copy your terminal path (
echo $PATH
) into.Renviron
per instructions here: https://community.rstudio.com/t/how-to-get-rstudio-ide-to-use-the-correct-terminal-path-in-mac-os-x/131528/6Some packages may need additional help for R to find the correct paths. For
units
:remotes::install_version(package = "units", version = "0.8-5", configure.args = "--with-udunits2-lib=/opt/homebrew/Cellar/udunits/2.2.28/lib --with-udunits2-include=/opt/homebrew/Cellar/udunits/2.2.28/include")
17.2
Historically some projects used Packrat or checkpoint to fix R package versions. These systems have been superceded by renv
.