Skip to content

Commit

Permalink
Use rocker/rstudio:3.5.3 as base image
Browse files Browse the repository at this point in the history
  • Loading branch information
joelnitta committed Apr 18, 2019
1 parent 054e701 commit 8684207
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
@@ -1,14 +1,15 @@
# Only run this after making packrat/packrat.lock by
# running install_packages.R

FROM rocker/tidyverse:3.5.3
FROM rocker/rstudio:3.5.3

RUN apt-get update

COPY ./packrat/packrat.lock packrat/

RUN install2.r packrat

RUN Rscript -e 'packrat::restore()'

# .Rprofile doesn't get parsed by Rstudio, so modify Rprofile.site instead
# This is needed so R uses packrat libraries by default
# Modify Rprofile.site so R loads packrat library by default
RUN echo '.libPaths("/packrat/lib/x86_64-pc-linux-gnu/3.5.3")' >> /usr/local/lib/R/etc/Rprofile.site
22 changes: 11 additions & 11 deletions README.md
@@ -1,6 +1,7 @@
## Installing R packages to a Docker image with packrat

This is a minimal example that installs a single package each from CRAN, bioconductor, and github to a Docker image using packrat.
This is a minimal example that installs a single package each from CRAN,
bioconductor, and github to a Docker image using packrat.

### Setup

Expand All @@ -9,20 +10,19 @@ project directory.

### First step: make packrat/packrat.lock file

Launch `rocker/tidyverse` with tag set to same version we will use in
the `Dockerfile`, and this directory mounted.
Launch `rocker/rstudio` (or any other [rocker image](https://www.rocker-project.org/)
of your choice) with tag set to same version we will use in the `Dockerfile`,
and this directory mounted.

Here I'm using `rocker/tidyverse` because it comes with RStudio server, so we can
edit code in the container directly with RStudio. However, `rocker/tidyverse`
comes with `tidyverse` pre-installed, so if you want to track those packages
properly you would have to install them like the other example packages in
`install_packages.R`.
Note that the rocker images come with various packages pre-installed,
so if you want to track those packages properly you would have to install them
like the other example packages in `install_packages.R`.

````
docker run -it -e PASSWORD=cleverpw -v /path/to/project/:/home/rstudio/project rocker/tidyverse:3.5.3 bash
docker run -it -e DISABLE_AUTH=true -v /path/to/project/:/home/rstudio/project rocker/rstudio:3.5.3 bash
````

Inside the docker container, run the script to install R packages
Inside the docker container, run the script to install R packages
with `packrat`. Exit when done.

```
Expand All @@ -35,7 +35,7 @@ but the main reason is to write `packrat/packrat.lock`.

### Second step: actually build the image

Now we can use `packrat.lock` to restore (i.e., install) packages when we
Now we can use `packrat.lock` to restore (i.e., install) packages when we
build the image.

```
Expand Down
7 changes: 3 additions & 4 deletions install_packages.R
Expand Up @@ -2,11 +2,10 @@

### Initialize packrat ###

# rocker/tidyverse comes with packrat, so we don't need to install it.
# Uncomment the next line if using an image that doesn't already have packrat.
# install.packages("packrat", repos = "https://cran.rstudio.com/")
# Install packrat
install.packages("packrat", repos = "https://cran.rstudio.com/")

# Don't let packrat try to find packages to install itself.
# Initialize packrat, but don't let it try to find packages to install itself.
packrat::init(
infer.dependencies = FALSE,
enter = TRUE,
Expand Down

0 comments on commit 8684207

Please sign in to comment.