Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install R packages using Dockerfile

I am trying to install R packages using Dockerfile.

I installed the image Rocker/Rstudio.

The content of the Dockerfile is:

# 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')"

I then build my image doing: docker build -t my_r_image . The image builds but the packages are not installed as I get this warning:

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'

I tried by replacing http://cran.us.r-project.org by = 'http://cran.rstudio.com/')" but I get a similar error saying that it is unable to access index for repository.

Anyone has an idea of what I am doing wrong?

edit1: See below output I get when I do:

.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)
like image 499
ML_Enthousiast Avatar asked Oct 17 '19 14:10

ML_Enthousiast


1 Answers

strangely enough, with exactly the same Dockerfile, I had no problem installing the packages using the rocker/tidyverse repository instead of the rocker/rstudio. Anyone knows why is that?

like image 79
ML_Enthousiast Avatar answered Nov 03 '22 05:11

ML_Enthousiast