r - How to build a Docker image with the right R and package versions and open Rstudio with them afterwards?
问题描述
I just finished writing a manuscript for publication in a scientific journal. I want my research to be reproducible, so besides sharing my original and compiled R markdown notebooks on Github, I would like to save the environment in which I was analysing my data (including the data, notebooks and specific R and package versions) in a Docker container. Moreover, I would like anyone trying to reproduce my work to be able to execute this code in an interactive Rstudio session.
I was able to create a Dockerfile with the correct environment. Here is a toy example:
FROM rocker/r-ver:3.5.1
RUN mkdir /home/working_directory
RUN mkdir /home/working_directory/bin
RUN R -e 'options(repos = \
list(CRAN = "http://mran.revolutionanalytics.com/snapshot/2019-01-01")); \
install.packages("ggplot2")'
COPY current/0[1-8]-*.Rmd /home/working_directory/
COPY current/bin/utils.R /home/working_directory/bin/
RUN R
However, this doesn't allow the users to read the Rmd notebooks and execute the code line by line. A workaround is to run the image rocker/rstudio, and install the packages from there, but I would like to be able to do so from a single docker build call. Unfortunately, I wasn't able to do so.
Cheers!
解决方案
Rocker RStudio图像应该有你需要的东西 - RStudio 位于 R 之上。如果你特别想要 R 3.5.1,你可以在这里找到源代码:
有关如何使用它的更多详细信息,请阅读https://hub.docker.com/r/rocker/rstudio。
仅使用具有特定 R 版本的预构建图像
# with R version 3.5.1:
docker pull rocker/rstudio:3.5.1
以交互方式研究图像:
docker run --rm -it rocker/rstudio:3.5.1 bash
现在我们可以运行例如:
# Check R version
Rscript -e "sessionInfo()[['R.version']][['version.string']]"
# [1] "R version 3.5.1 (2018-07-02)"
# Check RStudio Server version
rstudio-server version
# 1.1.463
# Exit when done
exit
推荐阅读
- python - 使用布尔输出对 df 进行更短的过滤
- object-detection - 如何在 Tensorflow 2.x 中打印准确度和其他指标?
- mysql - 如何在 SQL 的日期字段中插入日期
- php - 将变量从一个函数传递到同一控制器中的另一个函数
- java - Eclipse 在 Windows10 中安装时返回错误消息
- android - 在 react-native 应用程序的发布版本中获取错误
- visual-studio-code - VS Code - 一个文件夹中的多个源文件
- python - 如何进行流畅的图像运动?| 基维
- python - Python获取div标签下的href
- jquery - 具有延迟和页面调整大小的 J-query 动画