在 Deepnote 的 Dockerfile 中安装 R 包

Install an R package in Dockerfile in Deepnote

我已经在 Deepnote 中设置了一个 custom environment 和 R 内核,我想使用 Dockerfile 安装 mosaic 包(否则我必须每天手动安装它,这需要一段时间)。当我添加

RUN R -e 'install.packages("mosaic")'

在 Dockerfile 中的 IRkernel::installspec 行之后,我得到了这个输出:

Step #1: > install.packages("mosaic")
Step #1: Installing package into ‘/usr/local/lib/R/site-library’
Step #1: (as ‘lib’ is unspecified)
Step #1: Warning in install.packages("mosaic") :
Step #1:   'lib = "/usr/local/lib/R/site-library"' is not writable
Step #1: Error in install.packages("mosaic") : unable to install packages
Step #1: Execution halted
Step #1: The command '/bin/sh -c R -e 'install.packages("mosaic")'' returned a non-zero code: 1
Finished Step #1
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
Step #1: 

我做错了什么?

您 link 的示例有 sudo:

RUN sudo apt-get update && \
    sudo apt-get install -y r-base

RUN sudo R -e "install.packages('IRkernel', repos='http://cran.rstudio.com/')"
    ^^^^

您可能也需要它,因为您会收到一条 is not writable 消息。