Unable to install R library of facebook prophet on CentOS7 - r

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.

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.

Related

Issue installing R package 'devtools' in Docker - getting error installing git2r

I am using a continuumio/miniconda3:latest base container and activating a Conda environment.
This all works fine.
When I run:
RUN R -e "install.packages('devtools',repos = 'http://cran.us.r-project.org')"
I get an error:
configure: Package dependency requirement 'libgit2 >= 0.26.0' could not be satisfied.
-----------------------------------------------------------------------
Unable to find the libgit2 library on this system. Building 'git2r'
using the bundled source of the libgit2 library.
To build git2r with a system installation of libgit2, please install:
libgit2-dev (package on e.g. Debian and Ubuntu)
libgit2-devel (package on e.g. Fedora, CentOS and RHEL)
libgit2 (Homebrew package on OS X)
and try again.
If the libgit2 library is installed on your system but the git2r
configuration is unable to find it, you can specify the include and
lib path to libgit2 with:
given you downloaded a tar-gz archive:
R CMD INSTALL git2r-.tar.gz --configure-vars='INCLUDE_DIR=/path/to/include LIB_DIR=/path/to/lib'
or cloned the GitHub git2r repository into a directory:
R CMD INSTALL git2r/ --configure-vars='INCLUDE_DIR=/path/to/include LIB_DIR=/path/to/lib'
or download and install git2r in R using
install.packages('git2r', type='source', configure.vars='LIB_DIR=-L/path/to/libs INCLUDE_DIR=-I/path/to/headers')
On macOS, another possibility is to let the configuration
automatically download the libgit2 library from the Homebrew
package manager with:
R CMD INSTALL git2r-.tar.gz --configure-vars='autobrew=yes'
or
R CMD INSTALL git2r/ --configure-vars='autobrew=yes'
or
install.packages('git2r', type='source', configure.vars='autobrew=yes')
-----------------------------------------------------------------------
configure: Attempting configuration of bundled libgit2
checking size of void*... 8
checking for library containing inflate... no
configure: error: in `/tmp/Rtmpbkmfhr/R.INSTALL8c407eb001/git2r':
configure: error:
---------------------------------------------
The zlib library that is required to build
git2r was not found.
Please install:
zlib1g-dev (package on e.g. Debian and Ubuntu)
zlib-devel (package on e.g. Fedora, CentOS and RHEL)
and try again.
If the zlib library is installed on your
system but the git2r configuration is
unable to find it, you can specify the
include and lib path to zlib with:
R CMD INSTALL git2r --configure-vars='LIBS=-L/path/to/libs CPPFLAGS=-I/path/to/headers'
---------------------------------------------
See `config.log' for more details
ERROR: configuration failed for package ‘git2r’
* removing ‘/opt/conda/envs/r-app/lib/R/library/git2r’
I have libgit2-dev installed at the start of my Dockerfile using apt-get install libgit2-dev and it installs libgit2 version 0.27.7.
Now the odd part about this is if I start the container and access it, I can run the "install.packages('devtools',repos = 'http://cran.us.r-project.org')" just fine and it works.
Dockerfile:
FROM continuumio/miniconda3:latest
RUN apt-get update -y; apt-get upgrade -y; \
apt-get install -y vim ssh libgit2-dev zlib1g-dev \
build-essential gcc gfortran g++
RUN conda update -n base -c defaults conda
COPY environment.yml environment.yml
RUN conda env create -f environment.yml
RUN echo "source activate r-env" >> ~/.bashrc
ENV PATH /opt/conda/envs/r-env/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN R -e "install.packages('devtools',repos = 'http://cran.us.r-project.org')"
environment.yml:
name: r-env
channels:
- conda-forge
- defaults
dependencies:
- python=3.7
- r-essentials
- r-base
Replace the last line of your Dockerfile with:
RUN Rscript -e "install.packages('devtools',repos = 'http://cran.us.r-project.org')"

launching R in AWS EC2

I am trying to launch an R instance in AWS EC2. I have opted for the free tier and use the Amazon Linux AMI. In user data I have specified in the following manner to install R and Rstudio:
#!/bin/bash
# install R
yum install -y R
# install RStudio-Server
wget https://download2.rstudio.org/server/centos6/x86_64/rstudio-server-rhel-1.2.5033-
x86_64.rpm
yum install -y --nogpgcheck rstudio-server-rhel-1.2.5033-x86_64.rpm
yum install -y curl-devel
yum install -y openssl openssl-devel
# add user
useradd forecasting
echo forecasting:testing | chpasswd
However, the R version is not the latest one - how do I modify this code to download the latest version of R?
Using the instructions in this installing R for RStudio link, I think the following might work for Centos 6. Unfortunately I can't check it, but it might give you something to work from.
#!/bin/bash
# install R runtime dependencies
yum install epel-release
# set R version
R_VERSION=3.6.2
# download and install R
wget https://cdn.rstudio.com/r/centos-6/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
yum install -y R-${R_VERSION}-1-1.x86_64.rpm
# install RStudio-Server
wget https://download2.rstudio.org/server/centos6/x86_64/rstudio-server-rhel-1.2.5033-
x86_64.rpm
yum install -y --nogpgcheck rstudio-server-rhel-1.2.5033-x86_64.rpm
yum install -y curl-devel
yum install -y openssl openssl-devel
# add user
useradd forecasting
echo forecasting:testing | chpasswd

error installing "rgl" package, version 0.100.19 in anaconda/jupyter-notebook. Ubuntu 18.04

I like to install "rgl" package version 0.100.19 (since the other package depends on this version) in anaconda/jupyter notebook environment and received error.
configure: error: X11 not found but required, configure aborted
I tried
sudo apt-get install xorg
sudo apt-get install libx11-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install r-cran-rgl
conda install -c conda-forge xorg-libx11
conda install -c anaconda mesa
but, they did not help yet.
install.packages("rgl")
configure: error: X11 not found but required, configure aborted
I came across this problem, my solution was to:
$ conda install r-rgl
It seems like the conda install goes to the conda R (see this with which R), and the way I found to get rgl installed on conda's R version was via conda install.

Not able to install tm package in R Studio in Fedora-25

I am getting this error and i have tried every other solution related to this given on stackoverflow but still not able to install the package.Please suggest a solution.And how can i install any R package using source on linux?
You can try the following:
In shell:
sudo yum install -y epel-release
sudo yum install glibc-common
sudo yum install -y rpm-build make wget tar libxml2-devel
In R:
install.packages('xml2')
Instructions are adapted from https://github.com/opencpu/opencpu-server/tree/master/rpm#readme
Please let me know if it works.

how can i install the packages in r properly and correctly using Rstudio app?

I tried to install "xlsx" package using Rstudio, and i couldn't install it.
I am trying to install my packages using install.packages("xlsxjars"). I already tried doing that from Tools window in Rstudio app, and I tried using the console.
I am using Linux (Gnome 17.04). I get this error:
input
install.packages("xlsxjars")
output
Installing package into ‘/home/aim/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/xlsxjars_0.6.1.tar.gz'
Error in install.packages : error reading from connection
if you get some Errors while installing r packages kind of somthing.so is miising or some packages are missing depending on the version of R, you should try this commands because, i had this kind of errors with R 3.0.x in Ubuntu 14.04
so i upgrade my R version to fix it with the following commands :
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" »
gpg —keyserver keyserver.ubuntu.com —recv-key E084DAB9
gpg -a —export E084DAB9 | sudo apt-key add -
sudo apt-get —purge remove r-base-core
sudo apt-get update
sudo apt-get -y install r-base
sudo apt-get update
now i can install all packages without errors
I totally agree with the answer of #kissi salim yahia
Just want to add . When you tape in R
install.packages("your_package")
you got some dependencies below.
these one may have troubles sometimes. So just need to install them manually from the SHELL like:
sudo apt-get install r-cran-your_dependencie
I spent a while struggling with that too. Eventually I just gave up as the java in that package was out of date and I would have needed to load older Java up to get it to run. I would suggest readxl instead.
A simple intro to the package can be found here: https://www.datacamp.com/community/tutorials/r-tutorial-read-excel-into-r#readxl

Resources