Code to accompany talk at R/Medicine 2020.
Slides at: https://vincentmajor.github.io/reproducible_RStudio_projects/
Building on the fantastic work by the rocker group, particularly their version stable images on Docker Hub for any recent R version (e.g. 3.4.1). These versioned images contain a RStudio version that enables you to use RStudio in the browser.
These rocker images also update the CRAN repo to a MRAN snapshot when that R version was last current.
To simplify everything I recommend:
- mounting a folder of source code,
- adding your UID to ease permissions issues
- initializing a
packrat
project within the mounted source directory
Launch Docker with:
$ docker run -d -e USERID=$UID -e PASSWORD=fake -v $(pwd):/work -p 7009:8787 rocker/rstudio:3.4.1
Within R:
> install.packages("packrat")
> packrat::init("/work")
> packrat::on("/work")
Run:
$ bash run_example.sh
In a browser, go to localhost:7009 and login with rstudio/fake. Run:
> setwd('/work')
> install.packages('packrat')
> packrat::restore('/work')
and then run the example_code.R
Each new Docker container won't have anything installed and will need packrat
to be installed before resuming work. To prevent this you can install packrat
into the Docker image you use.
The pull_and_build.sh script does exactly this by taking an argument RVERSION
, pulling that rocker/rstudio image, installing packrat
, and creating a new image: rstudio_packrat:RVERSION
.