使用 docker 文件安装 R 包 [英] Install R packages using docker file
问题描述
我已经在我的 docker 文件中使用以下行安装了 R.请建议我现在如何指定要安装在我的 docker 文件中的软件包.
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
我正在做这样的事情:
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/')"
这是正确的做法吗?
推荐答案
正如@Cameron Kerr 的评论所建议的,Rscript 不会给您构建失败.到目前为止,推荐的方法是按照问题的建议进行操作.
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/')"
如果你不使用 Base-R 镜像,你可以使用 rocker-org
的 r-ver
或 r-studio
或 tidyverse
图像.这是 repo.这是一个示例 Dockerfile -
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
--error
标志是可选的,它使 install.packages()
如果包安装失败(这将导致 docker build
命令失败).默认情况下,install.packages()
只会抛出一个警告,这意味着即使安装包失败,Dockerfile 也可以构建成功.
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.
所有 rocker-org
基本上都是 为 install2.R
功能安装 littler
包
All rocker-org
's basically installs the littler
package for the install2.R
functionality
这篇关于使用 docker 文件安装 R 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!