Loads binary packages at install time, which traps some environment compatibility problems. The package is removed from the packrat library and never reaches the packrat cache.
Fixes #712
The following Dockerfile examples show failures occurring at restore-time; the "runtime" script.R is never executed.
This first example shows how an install-time package load can identify missing system dependencies.
Dockerfile.packrat identifying missing (jags) system dependencies
```dockerfile
FROM rstudio/r-base:4.3-jammy AS base
RUN apt-get update && apt-get -y install pkg-config
ARG REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/jammy/latest
RUN echo "options(repos = c(CRAN = '${REPOSITORY}'))" >> /opt/R/4.3.0/lib/R/etc/Rprofile.site
RUN R -s -e "install.packages('remotes')"
FROM base as setup
ARG PACKRAT_REF="aron-renv-binary-package-validation"
RUN R -s -e "remotes::install_github('rstudio/packrat', '${PACKRAT_REF}')"
FROM setup AS installation
RUN mkdir /content \
&& echo "library(rjags)" > /content/script.R \
&& echo "options(download.file.method = 'curl', download.file.extra = paste('-s -L -f -A ', shQuote(getOption('HTTPUserAgent'))))" > /content/.Rprofile
WORKDIR /content
ENV RENV_INSTALL_TEST_LOAD=True
RUN R -s -e "packrat::init(enter = FALSE, infer.dependencies = FALSE)"
# install by R of rjags into the packrat library..
RUN R -s -e "install.packages('rjags')"
RUN R -s -e "packrat::snapshot()"
RUN rm -rf packrat/lib* packrat/src
# installation by packrat of rjags into the packrat library.
RUN R -s -e "packrat::restore()"
RUN R -s -f "script.R"
```
> [installation 7/8] RUN R -s -e "packrat::restore()":
#15 8.501 Loading required package: coda
#15 8.501 Error: package or namespace load failed for ‘rjags’:
#15 8.501 .onLoad failed in loadNamespace() for 'rjags', details:
#15 8.501 call: dyn.load(file, DLLpath = DLLpath, ...)
#15 8.501 error: unable to load shared object '/content/packrat/lib/x86_64-pc-linux-gnu/4.3.0/rjags/libs/rjags.so':
#15 8.501 libjags.so.4: cannot open shared object file: No such file or directory
#15 8.501 Execution halted
#15 8.530 FAILED
#15 8.532 Error: error testing if 'rjags' can be loaded [error code 1]
#15 8.533 Execution halted
This second example shows how an install-time package load can identify incompatible base system libraries.
Dockerfile.packrat-crosswired showing incompatible base libraries
```dockerfile
FROM rstudio/r-base:4.3-bionic AS base
RUN apt-get update && apt-get -y install pkg-config
ARG REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/bionic/latest
RUN echo "options(repos = c(CRAN = '${REPOSITORY}'))" >> /opt/R/4.3.0/lib/R/etc/Rprofile.site
RUN R -s -e "install.packages('remotes')"
FROM base as setup
ARG PACKRAT_REF="aron-renv-binary-package-validation"
RUN R -s -e "remotes::install_github('rstudio/packrat', '${PACKRAT_REF}')"
FROM setup AS installation
RUN mkdir /content \
&& echo "library(fastmap)" > /content/script.R \
&& echo "options(download.file.method = 'curl', download.file.extra = paste('-s -L -f -A ', shQuote(getOption('HTTPUserAgent'))))" > /content/.Rprofile
WORKDIR /content
ENV RENV_INSTALL_TEST_LOAD=True
RUN R -s -e "packrat::init(enter = FALSE, infer.dependencies = FALSE)"
# install by R of fastmap into the packrat library..
RUN R -s -e "install.packages('fastmap')"
RUN R -s -e "packrat::snapshot()"
RUN rm -rf packrat/lib* packrat/src
# installation by packrat of fastmap into the packrat library using a BAD repository
ARG JAMMY_REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/jammy/latest
RUN R -s -e "packrat::set_lockfile_metadata(repos = c(CRAN = '${JAMMY_REPOSITORY}'))"
RUN R -s -e "packrat::restore()"
RUN R -s -f "script.R"
```
Loads binary packages at install time, which traps some environment compatibility problems. The package is removed from the packrat library and never reaches the packrat cache.
Fixes #712
The following Dockerfile examples show failures occurring at restore-time; the "runtime" script.R is never executed.
This first example shows how an install-time package load can identify missing system dependencies.
Dockerfile.packrat identifying missing (jags) system dependencies ```dockerfile FROM rstudio/r-base:4.3-jammy AS base RUN apt-get update && apt-get -y install pkg-config ARG REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/jammy/latest RUN echo "options(repos = c(CRAN = '${REPOSITORY}'))" >> /opt/R/4.3.0/lib/R/etc/Rprofile.site RUN R -s -e "install.packages('remotes')" FROM base as setup ARG PACKRAT_REF="aron-renv-binary-package-validation" RUN R -s -e "remotes::install_github('rstudio/packrat', '${PACKRAT_REF}')" FROM setup AS installation RUN mkdir /content \ && echo "library(rjags)" > /content/script.R \ && echo "options(download.file.method = 'curl', download.file.extra = paste('-s -L -f -A ', shQuote(getOption('HTTPUserAgent'))))" > /content/.Rprofile WORKDIR /content ENV RENV_INSTALL_TEST_LOAD=True RUN R -s -e "packrat::init(enter = FALSE, infer.dependencies = FALSE)" # install by R of rjags into the packrat library.. RUN R -s -e "install.packages('rjags')" RUN R -s -e "packrat::snapshot()" RUN rm -rf packrat/lib* packrat/src # installation by packrat of rjags into the packrat library. RUN R -s -e "packrat::restore()" RUN R -s -f "script.R" ```
This second example shows how an install-time package load can identify incompatible base system libraries.
Dockerfile.packrat-crosswired showing incompatible base libraries ```dockerfile FROM rstudio/r-base:4.3-bionic AS base RUN apt-get update && apt-get -y install pkg-config ARG REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/bionic/latest RUN echo "options(repos = c(CRAN = '${REPOSITORY}'))" >> /opt/R/4.3.0/lib/R/etc/Rprofile.site RUN R -s -e "install.packages('remotes')" FROM base as setup ARG PACKRAT_REF="aron-renv-binary-package-validation" RUN R -s -e "remotes::install_github('rstudio/packrat', '${PACKRAT_REF}')" FROM setup AS installation RUN mkdir /content \ && echo "library(fastmap)" > /content/script.R \ && echo "options(download.file.method = 'curl', download.file.extra = paste('-s -L -f -A ', shQuote(getOption('HTTPUserAgent'))))" > /content/.Rprofile WORKDIR /content ENV RENV_INSTALL_TEST_LOAD=True RUN R -s -e "packrat::init(enter = FALSE, infer.dependencies = FALSE)" # install by R of fastmap into the packrat library.. RUN R -s -e "install.packages('fastmap')" RUN R -s -e "packrat::snapshot()" RUN rm -rf packrat/lib* packrat/src # installation by packrat of fastmap into the packrat library using a BAD repository ARG JAMMY_REPOSITORY=https://packagemanager.rstudio.com/cran/__linux__/jammy/latest RUN R -s -e "packrat::set_lockfile_metadata(repos = c(CRAN = '${JAMMY_REPOSITORY}'))" RUN R -s -e "packrat::restore()" RUN R -s -f "script.R" ```