gpt4 book ai didi

r - 使用 Dockerfile 安装 R 包

转载 作者:行者123 更新时间:2023-12-03 03:06:40 34 4
gpt4 key购买 nike

我正在尝试使用 Dockerfile 安装 R 软件包。

我安装了镜像Rocker/Rstudio .

Dockerfile的内容是:

# Base image https://hub.docker.com/r/rocker/rstudio
FROM rocker/rstudio:latest

## Create directories
RUN mkdir -p /rstudio
RUN mkdir -p /rscripts


##Install R packages
RUN R -e "install.packages(c('rvest', 'jsonlite', 'data.table' ,'stringr'), repos = 'http://cran.us.r-project.org')"

然后,我通过执行以下操作构建图像:docker build -t my_r_image 。镜像已构建,但未安装软件包,因为我收到此警告:

Installing packages into ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified) Warning: unable to access index for repository http://cran.us.r-project.org/src/contrib: cannot open URL 'http://cran.us.r-project.org/src/contrib/PACKAGES'

我尝试将 http://cran.us.r-project.org 替换为 = 'http://cran.rstudio.com/')"但我收到类似的错误,指出它无法访问存储库的索引。

有人知道我做错了什么吗?

edit1:请参阅我执行此操作时得到的以下输出:

.libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/local/lib/R/library"

install.packages(c('rvest', 'jsonlite', 'data.table' ,'stringr'), repos = 'http://cran.us.r-project.org')
Warning in install.packages :
unable to access index for repository https://mran.microsoft.com/snapshot/2019-10-15/src/contrib:
cannot open URL 'https://mran.microsoft.com/snapshot/2019-10-15/src/contrib/PACKAGES'
Installing packages into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages :
unable to access index for repository http://cran.us.r-project.org/src/contrib:
cannot open URL 'http://cran.us.r-project.org/src/contrib/PACKAGES'
Warning in install.packages :
packages ‘rvest’, ‘jsonlite’, ‘data.table’, ‘stringr’ are not available (for R version 3.6.1)

最佳答案

奇怪的是,使用完全相同的 Dockerfile,我使用 rocker/tidyverse 存储库而不是 rocker/rstudio 安装软件包没有任何问题。有谁知道这是为什么吗?

关于r - 使用 Dockerfile 安装 R 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58435329/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com