如何在Docker中安装R Github包

g2ieeal7  于 12个月前  发布在  Docker
关注(0)|答案(1)|浏览(88)

我正在尝试为我的R脚本创建一个Docker镜像,以便在Google Cloud上调度R作业。我正在用一个小的R脚本测试它。docker build命令在我安装rga GitHub包的步骤中失败。下面是我的R脚本和DockerFile:
R脚本:

library(rga)
library(bigrquery)
bq_token()
rga.open(instance = "ga", where="~/ga.rga")

demoScheduleAPI <- function(){
  search_perf <- ga$getData(XXXX, batch = TRUE, walk = TRUE, 
                          start.date = "2020-01-15",
                          end.date = "2020-01-16",
                          metrics = "ga:searchUniques",
                          dimensions="ga:date,ga:hour,ga:searchKeyword, ga:searchCategory ,ga:dimension6,ga:dimension10")
  project <- "bidone-data"
  insert_upload_job(project, "GA_Export_Prod_DataSet", "Test_Table123", search_perf)
}

Dockerfile

FROM rocker/r-ver:3.6.1

RUN mkdir /home/bidone

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

RUN R -e "install.packages('devtools', repos='http://cloud.r-project.org')"

RUN R -e "devtools::install_github('skardhamar/rga')"

COPY .secrets /home/analysis/.secrets

COPY ga /home/analysis/ga

COPY DockerTest.R /home/analysis/DOckerTest.R

CMD R -e "source('/home/analysis/DockerTest.R')"

它确实安装了devtools包,但是当它试图从github安装rga包时,它给出了以下错误。

> devtools::install_github('skardhamar/rga')
Error in loadNamespace(name) : there is no package called ‘devtools’
Calls: :: ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
The command '/bin/sh -c R -e "devtools::install_github('skardhamar/rga')"' returned a non-zero code: 1

如何解决此问题?

nbysray5

nbysray51#

  • 在2023年9月编辑:* 这些天,有人 * 真的 * 想使用r2u作为容器的基础。我现在已经在StackOverflow上添加了一些其他的答案,描述了r2u的使用,所以人们可以搜索这些答案。

你最好的选择是GitHub搜索。下面是我的一个例子,用于支持class I teach的容器,构建在another Dockerfile from our Rocker Project上。该链接为您提供了完整的细节,但为了简洁起见,我们在这里省略了一些位

FROM rocker/r-ubuntu:18.04   

# Install required libraries -- using prebuild binaries where available
RUN apt-get update && apt-get install -y \
    git \
    r-cran-data.table \
    r-cran-devtools \
    r-cran-doparallel \
    r-cran-dygraphs \
    r-cran-foreach \
    r-cran-fs \
    r-cran-future.apply \
    r-cran-gh \
    r-cran-git2r \
    r-cran-igraph \
    r-cran-memoise \
    r-cran-microbenchmark \
    r-cran-png \
    r-cran-rcpparmadillo \
    r-cran-rex \
    r-cran-rsqlite \
    r-cran-runit \
    r-cran-shiny \
    r-cran-stringdist \
    r-cran-testthat \
    r-cran-tidyverse \
    r-cran-tinytest \
    r-cran-xts \
    sqlite3 \
    sudo

# Install additional R packages from CRAN (on top of the ones 
# pre-built as r-cran-*)
RUN install.r bench diffobj flexdashboard lintr ttdo unix

# Install plr -- for now (?) from GH; also install visualTest
RUN installGithub.r stat430dspm/plr MangoTheCat/visualTest

这基本上涵盖了我们

  • 使用MichaelRutter的PPA,通过prebuild.deb软件包获取尽可能多的Ubuntu LTS(目前仍是18.04)
  • 使用littler脚本install.r从CRAN安装一些软件包
  • 使用另一个littler脚本installGithub.r从GitHub安装另外两个仓库

这只是显示了我的首选排序:二进制文件超过CRAN超过GitHub。你的问题的关键点是,这些littler脚本也在R-ver堆栈上。但是对于r-ver,你必须 * 非常小心 * 混合,因为发布日期是通过设计 * 固定在MRAN上的。
(And如果有人想知道更多关于这个容器的原因,我们只放一个pre-print on arXiv--但这是我们使用的测试和分级基础设施的特定内容。

相关问题