I have installed R using below line in my docker file. Please suggest how do I specify now packages to be installed in my docker file.
RUN yum -y install R-core R-devel
I'm doing something like this:
RUN R -e "install.packages('methods',dependencies=TRUE, repos='http://cran.rstudio.com/')"\ && R -e "install.packages('jsonlite',dependencies=TRUE, repos='http://cran.rstudio.com/')" \ && R -e "install.packages('tseries',dependencies=TRUE, repos='http://cran.rstudio.com/')"
Is this the right way to do?
Go into R, click on Packages (at the top of the R console), then click on "Install package(s) from local zip files", then find the zip file with arm from wherever you just saved it. Do the same thing to install each of the other packages you want to install.
RStudio R Docker Images. RStudio creates and distributes an opinionated set of R binaries for different Linux distributions. These Docker images are built to use those R binaries. The images are intentionally minimal, their primary purpose is to serve as the basis for other images requiring R.
As suggested by @Cameron Kerr's comment, Rscript does not give you a build failure. As of now, the recommended way is to do as the question suggests.
RUN R -e "install.packages('methods',dependencies=TRUE, repos='http://cran.rstudio.com/')" RUN R -e "install.packages('jsonlite',dependencies=TRUE, repos='http://cran.rstudio.com/')" RUN R -e "install.packages('tseries',dependencies=TRUE, repos='http://cran.rstudio.com/')"
If you're fairly certain of no package failures then use this one-liner -
RUN R -e "install.packages(c('methods', 'jsonlite', 'tseries'), dependencies=TRUE, repos='http://cran.rstudio.com/')"
EDIT: If you're don't use the Base-R image, you can use rocker-org
's r-ver
or r-studio
or tidyverse
images. Here's the repo. Here's an example Dockerfile -
FROM rocker/tidyverse:latest # Install R packages RUN install2.r --error \ methods \ jsonlite \ tseries
The --error
flag is optional, it makes install.packages()
throw an error if the package installation fails (which will cause the docker build
command to fail). By default, install.packages()
only throws a warning, which means that a Dockerfile can build successfully even if it has failed to install the package.
All rocker-org
's basically installs the littler
package for the install2.R
functionality
Yes, your solution should work. I came across the same problem and found the solution here https://github.com/glamp/r-docker/blob/master/Dockerfile.
In short, use: RUN Rscript -e "install.packages('PACKAGENAME')"
. I have tried it and it works.
As others have mentioned in the comments, this solution will not raise an error if the package could not be installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With