Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options(warn = 2) to Dockerfile #9

Open
ColinFay opened this issue Jul 22, 2021 · 2 comments
Open

Add options(warn = 2) to Dockerfile #9

ColinFay opened this issue Jul 22, 2021 · 2 comments

Comments

@ColinFay
Copy link
Member

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] ~
@statnmap
Copy link
Member

statnmap commented Aug 2, 2021

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

image

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

@statnmap
Copy link
Member

statnmap commented Aug 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants