unable to install R packages in Docker container - r

** UPDATED QUESTION **
I am running an R Studio server docker container and when login cannot import libraries (e.g. rvest) I installed in R studio with all dependecies installed.
docker-compose.yml
version: '3.9'
services:
rstudio:
build: ./docker/rstudio
container_name: etl
environment:
- PASSWORD=yourpassword
ports:
- 8787:8787
Dockerfile
FROM rocker/rstudio
RUN apt-get clean all && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
python3-pip \
&& apt-get clean all && \
apt-get purge && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN /usr/local/lib/R/bin/R -e 'install.packages("ODBC", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")' && \
/usr/local/lib/R/bin/R -e 'install.packages("RODBC", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")' && \
/usr/local/lib/R/bin/R -e 'install.packages("DBI", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")' && \
/usr/local/lib/R/bin/R -e 'install.packages("rvest", repos="https://packagemanager.rstudio.com/cran/__linux__/focal/latest")'
Error
> library(rvest)
Error: package or namespace load failed for ‘rvest’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/xml2/libs/xml2.so':
libxml2.so.2: cannot open shared object file: No such file or directory
The file '/usr/local/lib/R/site-library/xml2/libs/xml2.so' actually exists, but #2 not : '/usr/local/lib/R/site-library/xml2/libs/xml2.so.2'

The first error message is key:
unable to load shared object '/usr/local/lib/R/site-library/xml2/libs/xml2.so
These RSPM packages do not install system dependencies (as they can't, they are simple tar.gz archives; the site offers some help). You could either just nstall the pre-made binaries from Ubuntu (r-cran-{odbc,rodbc,dbi,rvest}) or take care of the system-dependencies via eg
apt install libxml2 libodbc1
taking care of the XML and ODBC libraries.
Edit: In response to your edited question look at this search for file libxml2.so.2 at packages.ubuntu.com pointing you to Ubuntu package libxml2. Which is exactly what I wrote earlier: you need sudo apt install libxml2 because the CRAN (source) package does not do it for you (and cannot). See r2u for an alternative.

Related

Error Installing redux R package on centos7

Am getting an error trying to install redux r package on centos7, and have no idea how to fix it. Has anybody come across it before?
my Dockerfile is:
FROM centos:centos7
RUN yum -y install wget git tar
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN yum -y install epel-release openssh-server
ENV R_VERSION=4.0.5
RUN wget https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm \
&& yum -y install R-${R_VERSION}-1-1.x86_64.rpm \
&& rm R-${R_VERSION}-1-1.x86_64.rpm
ENV PATH="${PATH}:/opt/R/${R_VERSION}/bin/"
RUN yum -y install openssl-devel
RUN Rscript -e "install.packages(c('redux'), repos = 'https://packagemanager.rstudio.com/all/__linux__/centos7/latest')"
RUN Rscript -e "library(redux)"
CMD ["/bin/bash"]
Then i build the image:
docker build -t test-3:latest .
And the error i get is:
=> ERROR [8/8] RUN Rscript -e "library(redux)" 0.6s
------
> [8/8] RUN Rscript -e "library(redux)":
#12 0.528 Error: package or namespace load failed for 'redux' in dyn.load(file, DLLpath = DLLpath, ...):
#12 0.528 unable to load shared object '/opt/R/4.0.5/lib/R/library/redux/libs/redux.so':
#12 0.528 libhiredis.so.0.12: cannot open shared object file: No such file or directory
#12 0.528 Execution halted
------
executor failed running [/bin/sh -c Rscript -e "library(redux)"]: exit code: 1
ps. I am able to install any other package and reference it without problems
That file seems to come from the hiredis package: https://rhel.pkgs.org/7/okey-x86_64/hiredis-0.12.1-1.el7.centos.x86_64.rpm.html
Try adding the line RUN yum -y install hiredis or maybe adding that package to one of your existing yum install lines.
So turns out I had to also have hiredis installed for the package to load successfully
Updated dockerfile:
FROM centos:centos7
RUN yum -y install wget git tar
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN yum -y install epel-release openssh-server
ENV R_VERSION=4.0.5
RUN wget https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm \
&& yum -y install R-${R_VERSION}-1-1.x86_64.rpm \
&& rm R-${R_VERSION}-1-1.x86_64.rpm
ENV PATH="${PATH}:/opt/R/${R_VERSION}/bin/"
RUN yum -y install openssl-devel hiredis
RUN Rscript -e "install.packages(c('redux'), repos = 'https://packagemanager.rstudio.com/all/__linux__/centos7/latest')"
RUN Rscript -e "library(redux)"
CMD ["/bin/bash"]

Update SSL Certificates inside dockerfile

I have the following dockerfile:
FROM rocker/tidyverse:3.5.2
RUN apt-get update
# System dependices for R packages
RUN apt-get install -y \
git \
make \
curl \
libcurl4-openssl-dev \
libssl-dev \
pandoc \
libxml2-dev \
unixodbc \
libsodium-dev \
tzdata
# Clean up package installations
RUN apt-get clean
# ODBC system dependencies
RUN apt-get install -y gnupg apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install msodbcsql17 -y
# Install renv (package management)
ENV RENV_VERSION 0.11.0
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))"
RUN R -e "remotes::install_github('rstudio/renv#${RENV_VERSION}')"
# Specify USER for rstudio session
ENV USER rstudio
COPY ./renv.lock /renv/tmp/renv.lock
WORKDIR /renv/tmp
RUN R -e 'renv::consent(provided = TRUE)'
RUN R -e "renv::restore()"
WORKDIR /home/$USER
I use this image to recreate environments for R scripting purposes. This was working for a number of months up until the end of September when I started getting:
Error in curl::curl_fetch_memory(url, handle = handle) :
SSL certificate problem: certificate has expired
This occured when using GET request to query a website. How do I update my certificate now and in the future to avoid certificates expiring...I do not want to use the "config(ssl_verifypeer = FALSE)" workaround.
This happened to me too. Any chance you are working on MacOS or Linux based machine? It seems to be a bug:
https://security.stackexchange.com/questions/232445/https-connection-to-specific-sites-fail-with-curl-on-macos
ca-certificates Mac OS X
SSL Certificates - OS X Mavericks
Instead of adjusting the certificates as is suggested here, you can simply set R to not verify the peer. Just add the following line to the beginning of your code.
httr::set_config(config(ssl_verifypeer = FALSE, ssl_verifyhost = FALSE))

Unable to install r package inside docker container

I'm trying to install the docker package using binaries inside a docker container. inspired by this post:How to speed up R packages installation in docker
Now all the cran package to be installed is stored in file requirements-bin.txt
Error:
E: Unable to locate package r-cran-plumber
E: Unable to locate package r-cran-tolerance
Docker File:
FROM rocker/r-apt:bionic
WORKDIR /app
RUN apt-get update && \
apt-get install -y libxml2-dev
# Install binaries (see https://datawookie.netlify.com/blog/2019/01/docker-images-for-r-r-base-versus-r-apt/)
COPY ./requirements-bin.txt .
RUN cat requirements-bin.txt | xargs apt-get install -y -qq
# Clean up package registry
RUN rm -rf /var/lib/apt/lists/*
COPY ./src /app
EXPOSE 5000
CMD ["Rscript", "Server.R"]
requirements-bin.txt
r-cran-plumber
r-cran-tolerance

How to build Dockerfile with R & Java

I'm trying to build a Docker container that runs R with the package RJava. I have tried the following code:
# Install R version 3.6.3
FROM rocker/tidyverse:3.6.3
# Make ~/.R
RUN mkdir -p $HOME/.R
# Install Ubuntu packages && then R packages
RUN install2.r --error \
lubridate magrittr RPostgres DBI broom rlang rJava
However I get the following: installation of package ‘rJava’ had non-zero exit status.
Can anyone help me with this. I'm thinking that maybe it is because Java is not installed. Does anyone know how to install Java on this docker container?
I've tried adding the following to my dockerfile as per another post I found however I get the error saying 'The repository 'http://ppa.launchpad.net/webupd8team/java/ubuntu focal Release' does not have a Release file:
# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
software-properties-common
# Add the "JAVA" ppa
RUN add-apt-repository -y \
ppa:webupd8team/java
# Install OpenJDK-8
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
I'm new to docker and any help with this would be much appreciated.
The rocker images are based on debian, not ubuntu. Specifically it is Debian GNU/Linux 10 (buster). With that version, you can install java by installing the package openjdk-11-jdk via apt and you don't need to add any repositories for openjdk-8-jdk.
So a working dockerfile that installs rJava:
FROM rocker/tidyverse:3.6.3
RUN apt-get update && \
apt-get install -y openjdk-11-jdk && \
apt-get install -y liblzma-dev && \
apt-get install -y libbz2-dev
RUN Rscript -e "install.packages('rJava')"
Note: liblzma-dev and libbz2-dev are additional system dependencies for compiling rJava.

Installing "choroplethr" in Ubuntu

I am trying to install "choroplethr."
I have read the following related-looking errors:
https://askubuntu.com/questions/1057100/error-libudunits2-a-not-found-when-installing-ggraph-additional-error-objec
Install udunits2 package for R3.3
Their recommendation is to install something I have already installed. I have libudunits2 installed in a standard location, with:
$ sudo apt-get install libudunits2-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libudunits2-dev is already the newest version (2.2.26-1).
I can see headers:
$ ll /usr/include/ | grep unit
-rw-r--r-- 1 root root 39998 Jan 5 2018 udunits2.h
-rw-r--r-- 1 root root 5195 Jan 5 2018 udunits.h
However, on installation, I get this error:
$ R
R version 3.5.1 (2018-07-02) -- "Feather Spray"
> install.package("choroplethr", dep=T)
...
configure: error: in `/tmp/RtmpWC06JV/R.INSTALL7cbb4928db67/units':
configure: error:
--------------------------------------------------------------------------------
Configuration failed because libudunits2.so was not found. Try installing:
* deb: libudunits2-dev (Debian, Ubuntu, ...)
* rpm: udunits2-devel (Fedora, EPEL, ...)
* brew: udunits (OSX)
If udunits2 is already installed in a non-standard location, use:
--configure-args='--with-udunits2-lib=/usr/local/lib'
if the library was not found, and/or:
--configure-args='--with-udunits2-include=/usr/include/udunits2'
if the header was not found, replacing paths with appropriate values.
You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
--------------------------------------------------------------------------------
I've done these settings, but
install.packages("udunits2", configure.args = '--with-udunits2-include=/usr/include/udunits2')
-----Error: libudunits2.a not found-----
If the udunits2 library is installed in a non-standard location,
use --configure-args='--with-udunits2-lib=/usr/local/lib' for example,
or --configure-args='--with-udunits2-include=/usr/include/udunits2'
replacing paths with appropriate values for your installation.
You can alternatively use the UDUNITS2_INCLUDE and UDUNITS2_LIB
environment variables.
If udunits2 is not installed, please install it.
It is required for this package.
What am I missing? Is this package OSX only?
For Ubuntu with R 3.5 you can use the c2d4u3.5 PPA made available by the same persons that bring you R Ubuntu packages on CRAN, c.f. https://cran.r-project.org/bin/linux/ubuntu/README.html and http://dirk.eddelbuettel.com/blog/2017/12/22/:
sudo add-apt-repository ppa:marutter/c2d4u3.5
sudo apt-get update
After that you can install binary packages for most CRAN packages:
sudo apt-get install r-cran-choroplethr
This should work for all packages that are mentioned in CRAN task views.
Besides this, I tried to reproduce your installation problems using docker:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install --yes --no-install-recommends gnupg ca-certificates \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 \
&& echo "deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get install --yes --no-install-recommends r-base-dev libudunits2-dev \
&& Rscript -e 'install.packages(c("units", "udunits2"))'
However, the image was build without problems.

Resources