gpt4 book ai didi

r - 创建安装 rstan 的 docker 镜像时出现问题

转载 作者:行者123 更新时间:2023-12-04 18:38:53 32 4
gpt4 key购买 nike

我有以下图像:

FROM rocker/r-ver:4.1.2

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
ed \
libnlopt-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/


RUN apt-get update
RUN apt install software-properties-common -y

# https://github.com/stan-dev/rstan/wiki/Configuring-C-Toolchain-for-Linux
RUN add-apt-repository -y ppa:marutter/rrutter4.0
RUN add-apt-repository -y ppa:c2d4u.team/c2d4u4.0+
RUN apt-get update
RUN apt install -y r-cran-rstan


# https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#installation-of-rstan
RUN Rscript -e 'Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1); install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)'
使用 docker build -f Dockerfile -t docker_r_stan_test . 构建镜像后(没有错误输出),然后运行: example(stan_model, package = "rstan", run.dontrun = TRUE)我期待看到类似于以下内容的内容: https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#verify-installation
相反,我得到了输出:
Error in find.package(package, lib.loc, verbose = verbose) :
there is no package called ‘rstan’
我在尝试使用 library(rstan) 时遇到了类似的错误:
> library("rstan")
Error in library("rstan") : there is no package called ‘rstan’
我不明白为什么 rstan未在此图像中正确安装,因为我似乎已密切遵循这些步骤

最佳答案

使用 Rocker 图像安装 rstan 确实是一个好主意,我通过(基本上)在我的博客上的 this older post 中的单个命令演示了它。
实际上,您最好的选择是依赖已经为 c2d4u.team 存储库设置的 Rocker 容器。而且,正如@Oliver 在对您的问题的评论中指出的那样,这些不是 r-ver 图像,它们(出于自身的正当原因)遵循不同的内部模型(这使得它们对于我们在此处使用的二进制文件不太理想)。
第一个例子:rocker/r-ubuntu:20.04
这个“简单”依赖于 rstan 作为二进制包 r-cran-rstan 存在于此处的事实——因此我们在更新 apt 索引后将其安装在一个命令中。

edd@rob:~$ docker run --rm -ti rocker/r-ubuntu:20.04 bash
root@11e89aea64f6:/# apt update -qq
85 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@11e89aea64f6:/# apt install r-cran-rstan
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpng-tools libtbb2 pandoc pandoc-data r-cran-backports r-cran-bh r-cran-brio r-cran-callr
r-cran-checkmate r-cran-cli r-cran-colorspace r-cran-cpp11 r-cran-crayon r-cran-data.table
r-cran-desc r-cran-diffobj r-cran-digest r-cran-ellipsis r-cran-evaluate r-cran-fansi r-cran-farver
r-cran-fastmatch r-cran-ggplot2 r-cran-glue r-cran-gridextra r-cran-gtable r-cran-inline
r-cran-isoband r-cran-jsonlite r-cran-labeling r-cran-lifecycle r-cran-loo r-cran-magrittr
r-cran-matrixstats r-cran-munsell r-cran-pillar r-cran-pkgbuild r-cran-pkgconfig r-cran-pkgload
r-cran-praise r-cran-prettyunits r-cran-processx r-cran-ps r-cran-r6 r-cran-rcolorbrewer r-cran-rcpp
r-cran-rcppeigen r-cran-rcppparallel r-cran-rematch2 r-cran-rlang r-cran-rprojroot r-cran-rstudioapi
r-cran-scales r-cran-stanheaders r-cran-svglite r-cran-systemfonts r-cran-testthat r-cran-tibble
r-cran-utf8 r-cran-vctrs r-cran-viridislite r-cran-waldo r-cran-withr
Suggested packages:
texlive-latex-recommended texlive-xetex texlive-luatex pandoc-citeproc texlive-latex-extra context
wkhtmltopdf librsvg2-bin groff ghc nodejs php python ruby libjs-mathjax node-katex r-cran-devtools
r-cran-knitr r-cran-rmarkdown r-cran-tinytest r-cran-covr
The following NEW packages will be installed:
libpng-tools libtbb2 pandoc pandoc-data r-cran-backports r-cran-bh r-cran-brio r-cran-callr
r-cran-checkmate r-cran-cli r-cran-colorspace r-cran-cpp11 r-cran-crayon r-cran-data.table
r-cran-desc r-cran-diffobj r-cran-digest r-cran-ellipsis r-cran-evaluate r-cran-fansi r-cran-farver
r-cran-fastmatch r-cran-ggplot2 r-cran-glue r-cran-gridextra r-cran-gtable r-cran-inline
r-cran-isoband r-cran-jsonlite r-cran-labeling r-cran-lifecycle r-cran-loo r-cran-magrittr
r-cran-matrixstats r-cran-munsell r-cran-pillar r-cran-pkgbuild r-cran-pkgconfig r-cran-pkgload
r-cran-praise r-cran-prettyunits r-cran-processx r-cran-ps r-cran-r6 r-cran-rcolorbrewer r-cran-rcpp
r-cran-rcppeigen r-cran-rcppparallel r-cran-rematch2 r-cran-rlang r-cran-rprojroot r-cran-rstan
r-cran-rstudioapi r-cran-scales r-cran-stanheaders r-cran-svglite r-cran-systemfonts r-cran-testthat
r-cran-tibble r-cran-utf8 r-cran-vctrs r-cran-viridislite r-cran-waldo r-cran-withr
0 upgraded, 64 newly installed, 0 to remove and 85 not upgraded.
Need to get 60.7 MB of archives.
After this operation, 345 MB of additional disk space will be used.
Do you want to continue? [Y/n]
第二个例子:rocker/r-bspm:20.04
由于 bspm 及其集成(以及 Inaki 和我有一个 arXiv paper on this ),它变得更好,因为我们可以_使用 install.packages() (通过脚本)为我们获取 r-cran-rstan:
edd@rob:~$ docker run --rm -ti rocker/r-bspm:20.04 bash                                                  
root@ef07add5e9e7:/# apt update -qq
28 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@ef07add5e9e7:/# install.r rstan
(loaded the methods namespace)
Loading required package: utils Tracing function "install.packages" in package "utils"
Install system packages as root...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Hit http://archive.ubuntu.com/ubuntu focal InRelease
Hit http://security.ubuntu.com/ubuntu focal-security InRelease
Hit http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu focal InRelease
Hit http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit http://archive.ubuntu.com/ubuntu focal-backports InRelease
Hit http://ppa.launchpad.net/edd/r-4.0/ubuntu focal InRelease
Hit http://ppa.launchpad.net/marutter/rrutter4.0/ubuntu focal InRelease
Fetched 0 B in 0s (0 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Get:1 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu focal/main amd64 r-cran-backports amd64 1.4.1-
1cran1.2004.0 [94.9 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libpng-tools amd64 1.6.37-2 [26.1 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/universe amd64 pandoc-data all 2.5-3build2 [76.0 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/universe amd64 pandoc amd64 2.5-3build2 [15.4 MB]
[... stuff omitted here for brevity ...]
Setting up r-cran-stanheaders (2.21.0-7-1cran1.2004.0) ...
Setting up r-cran-callr (3.7.0-1cran1.2004.0) ...
Setting up r-cran-tibble (3.1.6-1cran1.2004.0) ...
Setting up r-cran-pkgbuild (1.3.1-1cran1.2004.0) ...
Setting up r-cran-ggplot2 (3.3.5-1cran1.2004.0) ...
Setting up r-cran-rstan (2.21.3-1cran1.2004.0) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
root@d3045995c945:/# R

R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Loading required package: utils
Tracing function "install.packages" in package "utils"
> library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
>
请注意,我们在这里使用 install.r - 来自 littlerinstall.packages() 的包装器 - 指向 R 包,但我们得到了二进制文件。这一切都取决于。在一个命令中。我想我什至发布了一个动画 gif,只显示了一次......
然而,关键的见解是,这一切都不仅仅限于 Docker。我在一台不想从源代码编译的小型笔记本电脑上使用 bspm 方法。它完美无缺,并且已经使用了几个月。
如果您有任何问题,请在此处或 r-sig-debian 列表中告诉我们。
编辑:我刚刚创建的动画 gif 太大,无法在此处发布(限制为 2mb),但适合 Twitter,所以这里是: https://twitter.com/eddelbuettel/status/1485318710818754567

关于r - 创建安装 rstan 的 docker 镜像时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70824760/

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