dockerfiler
dockerfiler copied to clipboard
Add options(warn = 2) to Dockerfile
remotes::install will not make the Dockerfile fail if there is an error. options(warn = 2) solves that.
[node1] (local) [email protected] ~
$ echo "FROM rocker/tidyverse:latest" >> Dockerfile
[node1] (local) [email protected] ~
$ echo "RUN Rscript -e 'remotes::install_cran(\"pouetpouet\")'" >> Dockerfile
[node1] (local) [email protected] ~
$ docker build -t pouet .
Sending build context to Docker daemon 47MB
Step 1/2 : FROM rocker/tidyverse:latest
---> b17fba18db1d
Step 2/2 : RUN Rscript -e 'remotes::install_cran("pouetpouet")'
---> Running in c1e4ba816fc5
Installing 1 packages: pouetpouet
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
Warning message:
package 'pouetpouet' is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Removing intermediate container c1e4ba816fc5
---> caaeea9ce5aa
Successfully built caaeea9ce5aa
Successfully tagged pouet:latest
vs
[node1] (local) [email protected] ~
$ echo "FROM rocker/tidyverse:latest" >> Dockerfile
[node1] (local) [email protected] ~
$ echo "RUN Rscript -e 'options(warn=2);remotes::install_cran(\"pouetpouet\")'" >> Dockerfile
[node1] (local) [email protected] ~
$ docker build -t pouet .
Sending build context to Docker daemon 47MB
Step 1/2 : FROM rocker/tidyverse:latest
---> b17fba18db1d
Step 2/2 : RUN Rscript -e 'options(warn=2);remotes::install_cran("pouetpouet")'
---> Running in 7a0ce0031ffa
Installing 1 packages: pouetpouet
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
Error: Failed to install 'pouetpouet' from CRAN:
(converted from warning) package 'pouetpouet' is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
Execution halted
The command '/bin/sh -c Rscript -e 'options(warn=2);remotes::install_cran("pouetpouet")'' returned a non-zero code: 1
[node1] (local) [email protected] ~
Not sure it will be enough for all.
RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
# Add option to warn and stop
RUN R -e 'options(warn = 2);remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone

Docker continues...
Same with Rscript
Step 46/52 : RUN Rscript -e 'options(warn = 2);remotes::install_local(upgrade="never")'
---> Running in 09e43edd13e4
Error : Could not copy `/build_zone` to `/tmp/Rtmpv66clL/file771f45e69`
Removing intermediate container 09e43edd13e4
---> 1653bab57384
Step 47/52 : RUN rm -rf /build_zone
---> Running in 4ad3b57dfd3a
Well, my error is already an error. Do not have to convert warning to error... But this error does not lead to stop building container
Maybe you can use this at the beginning of the Dockerfile:
# Transform warns as errors
RUN echo "options(warn = 2);" >> $R_HOME/etc/Rprofile.site
Then set back by removing the last line
# Remove option to warn and stop
RUN head -n -1 $R_HOME/etc/Rprofile.site
# or this one if you are not sure other lines are added during the installation process
RUN echo "options(warn = -1);" >> $R_HOME/etc/Rprofile.site