Introduction

Containerit is also available itself as a ready-to-use Docker image. This is useful if you do not want to install a full stack of packages in your local machine, but still trace a specific R session/script/document.

tl;dr - pull image and show Dockerfile on console

The following example pulls the geospatial variant of the containerit images and prints out the created Dockerfile to the console.

## 
## R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
## Copyright (C) 2017 The R Foundation for Statistical Computing
## Platform: x86_64-pc-linux-gnu (64-bit)
## 
## R is free software and comes with ABSOLUTELY NO WARRANTY.
## You are welcome to redistribute it under certain conditions.
## Type 'license()' or 'licence()' for distribution details.
## 
## R is a collaborative project with many contributors.
## Type 'contributors()' for more information and
## 'citation()' on how to cite R or R packages in publications.
## 
## Type 'demo()' for some demos, 'help()' for on-line help, or
## 'help.start()' for an HTML browser interface to help.
## Type 'q()' to quit R.
## 
## > df <- dockerfile(); print(df);
## INFO [2018-03-26 20:22:40] Going online? TRUE  ... to retrieve system dependencies (sysreq-api)
## INFO [2018-03-26 20:22:40] Trying to determine system requirements for the package(s) 'futile.logger, lambda.r, Rcpp, futile.options, semver' from sysreq online DB
## INFO [2018-03-26 20:22:41] Adding CRAN packages: futile.logger, futile.options, lambda.r, Rcpp, semver
## INFO [2018-03-26 20:22:41] Created Dockerfile-Object based on sessionInfo
## FROM rocker/r-ver:3.4.3
## LABEL maintainer="root"
## RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
##  && apt-get install -y NULL
## RUN ["install2.r", "futile.logger", "futile.options", "lambda.r", "Rcpp", "semver"]
## WORKDIR /payload/
## CMD ["R"]
## > 
## > 
## 
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Debian GNU/Linux 9 (stretch)
## 
## Matrix products: default
## BLAS: /usr/lib/openblas-base/libblas.so.3
## LAPACK: /usr/lib/libopenblasp-r0.2.19.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] containerit_0.2.4   futile.logger_1.4.3
## 
## loaded via a namespace (and not attached):
##  [1] compiler_3.4.3       rjson_0.2.15         magrittr_1.5        
##  [4] tools_3.4.3          lambda.r_1.2         Rcpp_0.12.15        
##  [7] futile.options_1.0.0 stringi_1.1.6        stringr_1.3.0       
## [10] semver_0.2.0        
## 
##                                             CRAN 
## "https://mran.microsoft.com/snapshot/2018-02-28"

Control output

By default the containerit images print the session info before R is terminated. You can disable this by setting the environment variable CONTAINERIT_SILENT. Combined with the --quiet option for R, this reduces the output to merely the Dockerfile

## > df <- dockerfile(); print(df);
## INFO [2018-03-26 20:22:44] Going online? TRUE  ... to retrieve system dependencies (sysreq-api)
## INFO [2018-03-26 20:22:44] Trying to determine system requirements for the package(s) 'futile.logger, lambda.r, Rcpp, futile.options, semver' from sysreq online DB
## INFO [2018-03-26 20:22:45] Adding CRAN packages: futile.logger, futile.options, lambda.r, Rcpp, semver
## INFO [2018-03-26 20:22:45] Created Dockerfile-Object based on sessionInfo
## FROM rocker/r-ver:3.4.3
## LABEL maintainer="root"
## RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
##  && apt-get install -y NULL
## RUN ["install2.r", "futile.logger", "futile.options", "lambda.r", "Rcpp", "semver"]
## WORKDIR /payload/
## CMD ["R"]
## > 
## >

You can set the futile.logger threshold with the environment variable CONTAINERIT_FLOG_THRESHOLD to ERROR, WARN or DEBUG; default is INFO.

## > df <- dockerfile(); print(df);
## FROM rocker/r-ver:3.4.3
## LABEL maintainer="root"
## RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
##  && apt-get install -y NULL
## RUN ["install2.r", "futile.logger", "futile.options", "lambda.r", "Rcpp", "semver"]
## WORKDIR /payload/
## CMD ["R"]
## > 
## >

Save file

You can of course also mount a directory with write permissions and save the Dockerfile. The default directory in the container is /containerit, so you can mount to this location and write the Dockerfile object:

## > df <- dockerfile(); write(df);
## INFO [2018-03-26 20:22:53] Writing dockerfile to /containerit/Dockerfile
## > 
## > 
## Directory contents:
## total 4
## -rw-r--r-- 1 root root 251 Mar 26 22:22 Dockerfile

Or you can use full paths, as shown below. The next example also sets the user of the container, so that the file on the host has a more convenient user and permissions.

## > df <- dockerfile(); write(df, file = '/my_dir/Dockerfile');
## INFO [2018-03-26 20:22:57] Writing dockerfile to /my_dir/Dockerfile
## > 
## > 
## Directory contents:
## total 4
## -rw-r--r-- 1 daniel daniel 254 Mar 26 22:22 Dockerfile

Example: package script

## > setwd('/data'); scriptFile <- 'script.R'; write(dockerfile(from = scriptFile, cmd = CMD_Rscript(basename(scriptFile))));
## INFO [2018-03-26 20:23:00] Executing R script file in script.R locally.
## INFO [2018-03-26 20:23:00] Creating an R session with the following arguments:
##   R  --silent --vanilla -e "source(file = \"/data/script.R\", echo = TRUE)" -e "info <- sessionInfo()" -e "save(list = \"info\", file = \"/tmp/Rtmp3GoEsu/rdata-sessioninfo1756b5f00\")"
## > source(file = "/data/script.R", echo = TRUE)
## 
## > install.packages("fortunes", repos = "http://cran.r-project.org")
## Installing package into ‘/usr/local/lib/R/site-library’
## (as ‘lib’ is unspecified)
## trying URL 'http://cran.r-project.org/src/contrib/fortunes_1.5-4.tar.gz'
## Content type 'application/x-gzip' length 192938 bytes (188 KB)
## ==================================================
## downloaded 188 KB
## 
## * installing *source* package ‘fortunes’ ...
## ** package ‘fortunes’ successfully unpacked and MD5 sums checked
## ** R
## ** inst
## ** preparing package for lazy loading
## ** help
## *** installing help indices
## ** building package indices
## ** installing vignettes
## ** testing if installed package can be loaded
## * DONE (fortunes)
## 
## The downloaded source packages are in
##  ‘/tmp/Rtmpfq43nC/downloaded_packages’
## 
## > fortunes::fortune()
## 
## It was simple, but you know, it's always simple when you've done it.
##    -- Simone Gabbriellini (after solving a problem with a trick suggested on
##       the list)
##       R-help (August 2005)
## 
## > info <- sessionInfo()
## > save(list = "info", file = "/tmp/Rtmp3GoEsu/rdata-sessioninfo1756b5f00")
## > 
## > 
## INFO [2018-03-26 20:23:03] Going online? TRUE  ... to retrieve system dependencies (sysreq-api)
## INFO [2018-03-26 20:23:03] Trying to determine system requirements for the package(s) 'fortunes' from sysreq online DB
## INFO [2018-03-26 20:23:04] Adding CRAN packages: fortunes
## INFO [2018-03-26 20:23:04] Created Dockerfile-Object based on script.R
## INFO [2018-03-26 20:23:04] Writing dockerfile to /data/Dockerfile
## Warning message:
## In getImageForVersion(r_version) :
##   No Docker image found for the given R version. You might want to specify a custom Docker image or 
##   use one of the following supported version tags (maybe check the internet connection if no suggestions appear). 
##  devel latest 3.4.4 3.4.1 3.3.1 3.2.0 3.3.2 3.1 3.1.0 3.3.0
## > 
## > 
## 
## R version 3.4.2 (2017-09-28)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Debian GNU/Linux 9 (stretch)
## 
## Matrix products: default
## BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] containerit_0.2.3   futile.logger_1.4.3
## 
## loaded via a namespace (and not attached):
## [1] compiler_3.4.2       rjson_0.2.15         magrittr_1.5        
## [4] tools_3.4.2          lambda.r_1.2         futile.options_1.0.0
## [7] stringi_1.1.5        stringr_1.2.0       
## 
##                                             CRAN 
## "https://mran.microsoft.com/snapshot/2017-10-31" 
## FROM rocker/r-ver:3.4.2
## LABEL maintainer="rstudio"
## RUN ["install2.r", "fortunes"]
## WORKDIR /payload/
## COPY ["script.R", "script.R"]
## CMD ["R", "--vanilla", "-f", "script.R"]

Build image

With the following commands you can build an image from the local source code. The following command executed in the containerit source directory creates an image containerit:

You can try the predetect feature by packaging the R Markdown file of the spacetime vignette: