使用Docker文件安装R软件包 [英] Install R packages using docker file

查看:591
本文介绍了使用Docker文件安装R软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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 图片。这是存储库。这是一个示例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

-错误标志是可选的,它使 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 基本上是安装 littler > install2.R 功能

这篇关于使用Docker文件安装R软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆