Unable to install R library of facebook prophet on CentOS7

487 views Asked by At

I am trying to install R library for Facebook's prophet on centOS 7. For easy reproducibility, I am providing a dockerfile and commands.

FROM centos:7

RUN yum -y install epel-release
RUN yum -y groupinstall "Development Tools"
RUN yum -y install proj

RUN yum -y install udunits2-devel
RUN yum -y install openssl-devel
RUN yum -y install libjpeg-turbo-devel
RUN yum -y install libcurl-devel

RUN yum -y install v8-devel

RUN yum -y install R

To build the dockerfile, use following command.

docker build -t test_prophet_installation .

Once it is built, I run the container using this next command.

docker run -it --entrypoint=/bin/bash test_prophet_installation

Now, I am inside my container. I tried to install prophet using below command.

su - -c "R -e \"install.packages('prophet', repos='http://cran.rstudio.com/')\""

The above command said, one of the dependencies of prophet i.e rstan failed to install. So I tried to install 'rstan' using the following command.

su - -c "R -e \"install.packages('rstan', repos='http://cran.rstudio.com/')\"" 

After running the above command, I got the following error.

Error in .shlib_internal(args) :
  C++14 standard requested but CXX14 is not defined
* removing '/usr/lib64/R/library/rstan'

The downloaded source packages are in
        '/tmp/RtmpsPDQ9G/downloaded_packages'
Updating HTML index of packages in '.Library'
Warning messages:
1: In install.packages("rstan", repos = "http://cran.rstudio.com/") :
  installation of package 'rstan' had non-zero exit status
2: In file.create(f.tg) :
  cannot create file '/usr/share/doc/R-3.6.0/html/packages.html', reason 'No such file or directory'
3: In make.packages.html(.Library) : cannot update HTML package index

I tried almost all the troubleshooting from Google to solve above error still no luck. I think, I am not setting some environment variable correctly.

1

There are 1 answers

0
Stefano On BEST ANSWER

The problem here is that when using the yum groupinstall "Development Tools", the installed gcc is 4.8.5 and therefore does not support C++14 (as you can see here).

In order to solve this you need to add the following:

RUN yum -y install centos-release-scl
RUN yum -y install devtoolset-8-gcc*

RUN scl enable devtoolset-8 sh

on top of this, you have to define the Makevars for rstan. You can find an explanation here: https://github.com/stan-dev/rstan/issues/569

I created this Makevars:

CXX14 = g++ -std=c++1y -Wno-unused-variable -Wno-unused-function -fPIC

and added a COPY in my Dockerfile:

COPY Makevars /root/.R/Makevars

I'm using the following command to download the packages:

install.packages('rstan', repos='http://cran.rstudio.com/', dependencies = TRUE)

Some things are still not working as expected but it's a step forward.

EDIT: this approach does not work since the system keeps using the old g++. I ended up using the docker image centos/devtoolset-7-toolchain-centos7:latest.