2

I am trying to make a Docker image that has R and the library "DECIPHER" installed.

According to the website, the package is supposed to be installed with the following commands inside R:

if (!requireNamespace("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install("DECIPHER")

However, I would like to install it in my docker image. To do this, I made the following Dockerfile:

# syntax=docker/dockerfile:1

FROM r-base:latest

RUN R -e "install.packages('BiocManager')"
RUN R -e "BiocManager::install('DECIPHER')"

When I did the following, it doesn't seem like DECIPHER was installed:

% docker build -t test .
% docker run -it --name asdf test bash
/# R

R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DECIPHER)
Error in library(DECIPHER) : there is no package called ‘DECIPHER’
> 

I am unsure how to resolve this. I am new to docker and normally install my R packages within the R environment and not via the command line. I appreciate any help you can offer so that I install this package in my docker image.

Edit:

Something was going wrong during the installation. Basically, BiocManager failed to install RCurl, which caused the installation of other dependencies to fail as well. I did not resolve this issue. Instead, I simply copied the one function I needed from the DECIPHER package into my code. This resolved the issue for my purposes, but does not solve the problem I identified here.

Special thanks to @r2evans for helping me to diagnose the problem.

  • 1
    To help troubleshoot, in your `Dockerfile` add `.libPaths()` before installing, add a check after installing that looks at that first directory and confirms the presence/location of the `.../DECIPHER` directory. (I don't use bioconductor, does its installation go anywhere non-standard?) – r2evans Feb 04 '22 at 19:36
  • @r2evans Thanks for helping! I can try this. Do you mean to add `RUN R -e ".libPaths()` as a line in my `DockerFile`? Also, how do I add a check? – BillyBologna Feb 04 '22 at 19:48
  • Yes for adding `.libPaths()`. For checking ... how would you check normally? Do you know where your packages are being installed on your normal console? If not, read `?.libPaths` about the vector of directories that that references. It might be as simple as `dir.exists(file.path(.libPaths()[1], "DECIPHER"))` (which returns a simple true/false), or much more verbosely `lapply(.libPaths(), list.dirs, recursive = FALSE)` and look to see where it's being installed. – r2evans Feb 04 '22 at 19:53
  • Thanks for your help, @r2evans. The installation for dependencies (specifically `RCurl`) was failing, so `DECIPHER` never got installed. I really only needed one function from the package, and this function did not have any dependencies. So I just copied the one function I needed and gave up trying to install the package. – BillyBologna Feb 04 '22 at 20:44
  • If `RCurl` was failing, a common issue is that the underlying OS-level `libcurl` package (or other package) was not found during compilation. See https://stackoverflow.com/q/31035845/3358272, https://stackoverflow.com/q/25006739/3358272, https://stackoverflow.com/a/64173168/3358272, to name a few. – r2evans Feb 04 '22 at 20:50

1 Answers1

0

I figured this out. As @r2evans pointed out, it was an issue with curl and libcurl. Installing those into the docker image was required before the DECIPHER package could be installed.

This new dockerfile will successfully install the DECIPHER package:

# syntax=docker/dockerfile:1

FROM r-base:latest

# install curl and libcurl
RUN apt update
RUN apt-get install -y curl
RUN apt-get -y install libcurl4-openssl-dev

# install required R libraries
RUN R -e "install.packages('BiocManager')"
RUN R -e "BiocManager::install('DECIPHER')"
  • A little late to the party, but it's a little better the specify the version of r-base you're using. i.e. `FROM r-base:4.1.2` or `FROM r-base:4.1.0` vs `FROM r-base:latest`. If i recall correctly `latest` implies the most recently built version of the container, not the highest version number. – Nick Mar 28 '22 at 15:13
  • Thanks @Nick this is good advice. I don't know what constitutes 'latest', but I probably don't want to risk that the version will change and break something. I changed my dockerbuild file so that it will always install the same version of R. – BillyBologna Mar 31 '22 at 22:56