Installing R package from source using docker file

I am trying to install an r package from source using the dockerfile. Like seen here (using ggplot2 for simplicity)

FROM rocker/r-ver

COPY . /usr/local/src/myscripts
WORKDIR /usr/local/src/myscripts

RUN R -e 'install.packages("ggplot2_3.0.0.tar.gz", repos = NULL, type = "source")'

CMD ["Rscript", "run.R"]

Once I build the image I get this error

> install.packages("ggplot2_3.0.0.tar.gz", repos = NULL, type = "source")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
ERROR: dependencies ‘digest’, ‘gtable’, ‘lazyeval’, ‘plyr’, ‘reshape2’, 
‘rlang’, ‘scales’, ‘tibble’, ‘viridisLite’, ‘withr’ are not available for 
package ‘ggplot2’
* removing ‘/usr/local/lib/R/site-library/ggplot2’
Warning message:
In install.packages("ggplot2_3.0.0.tar.gz", repos = NULL, type = "source") 
:>
> installation of package ‘ggplot2_3.0.0.tar.gz’ had non-zero exit status

The files included in the docker folder can be seen here

Does anyone know what I need to add to the dockerfile to solve (if possible) this error?

Upvotes: 0

Views: 2233

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 546153

Since you set repos = NULL, you will need to install all of the mentioned dependencies first — and their dependencies before that. You can do this manually but figuring out all dependencies is going to be a hassle, and is subject to change with every update.

It’s therefore probably better to use a local package manager. I have no personal experience with any of them but you can give {miniCRAN} a try.

Upvotes: 2

Related Questions