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

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')"

Related

Unable to install R library of facebook prophet on CentOS7

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.

Installing R `sf` and `RPostgres` packages on Unbuntu 18.04.4

Desire is to installed R {sf} and {RPostgres} packages on Ubuntu 18.04.4.
Trying:
R$> install.packages("sf")
configure: error: gdal-config not found or not executable.
Some SO searching (eg https://stackoverflow.com/a/49181048/2802810) suggests this:
sh$> sudo apt-get install libgdal-dev
The following packagess have unmet dependencies: libpq-dev :
Depends: libpq5 (= 10.12-0Ubuntu0.18.04.1) but 12.3-1.pgdg18.04+1 is
to be installed E: Unable to correct problems, you have broken
packages.
I also need libpq-dev for R {RPostgres}.
You may want to add PPA, depending on your R version.
https://launchpad.net/~marutter/+archive/ubuntu/c2d4u
https://launchpad.net/~marutter/+archive/ubuntu/c2d4u3.5
https://launchpad.net/~c2d4u.team/+archive/ubuntu/c2d4u4.0+
After adding PPA, you can install using sudo apt install r-cran-sf and sudo apt install r-cran-rpostgres
OKaaaay. The box I'm working in didn't have a Postgres repo installed (https://www.postgresql.org/download/linux/ubuntu/). Never libpq libs and that was all it needed.

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.

Correct fftw installation enabling Rcartogram

I would like to instal FFTW to enable the Rcartogram package.
Attempts
homebrew
After installing fftw libraries via homebrew:
brew install fftw --with-fortran --with-mpi --with-openmp --enable-float
The attempt to install the Rcartogram fails with the following error:
>> devtools::install_github("omegahat/Rcartogram")
Downloading GitHub repo omegahat/Rcartogram#master
from URL https://api.github.com/repos/omegahat/Rcartogram/zipball/master
Installing Rcartogram
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ \
--no-save --no-restore --quiet CMD INSTALL \
'/private/var/folders/7x/kwc1y_l96t55_rwlv35mg8xh0000gn/T/Rtmp7nMfM9/devtoolsa9f2458e68c3/omegahat-Rcartogram-715cb93' \
--library='/Users/whereIkeepMyStuff' --install-tests
* installing *source* package ‘Rcartogram’ ...
(...)
Can compile with fftw3.h
checking for fftw_malloc in -lfftw3... no
configure: error: "cannot link to libfftw3"
ERROR: configuration failed for package ‘Rcartogram’
* removing (...)
Error: Command failed (1)
make install
As a second approach I tried the guidelines available here and install FFTW using the following syntax:
wget http://www.fftw.org/fftw-3.3.6-pl1.tar.gz
tar -xvzf fftw-3.3.6-pl1.tar.gz
cd fftw-3.3.6-pl1
./configure --prefix=/usr/local/fftw-3.6.6 --enable-threads \
--enable-float --enable-shared \
CC="gcc -arch i386 -arch x86_64" CXX="g++ -arch i386 -arch x86_64" \
CPP="gcc -E" CXXCPP="g++ -E" F77=gfortran
make
sudo make install
sudo ln -s /usr/local/fftw-3.6.6 /usr/local/fftw
This fails as follows:
>> devtools::install_github("omegahat/Rcartogram")
(...)
* installing *source* package ‘Rcartogram’ ...
checking for pkg-config... /usr/local/bin/pkg-config
Package fftw3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `fftw3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fftw3' found
Package fftw3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `fftw3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fftw3' found
Looking for fftw3 files in /usr/local
Cannot find fftw.h
ERROR: configuration failed for package ‘Rcartogram’
Configuration
OS
sw_vers -productVersion
10.12.2
R
R --version
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
How can install FFTW so I could use the Rcartogram package?
Cleaning
After failed attempts I would clean:
homebrew
brew uninstall fftw
shell
sudo make uninstall
sudo rm -rv /usr/local/fftw*

Install shiny on remote Debian machine with R version 3.1.1

I am trying to host an shiny app on an remote Debian machine. Yet, i have encountered an R version issue when installing shiny package. I will basically walk through the steps that I took in the process:
After SSH into the VM, I install and update the r-base:
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev
The latest version I can get for R is 3.1.1. Then, I was trying to install "shiny" package as root by the following command:
sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""
Then, I was getting the error message like:
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository http://cran.rstudio.com/src/contrib
Warning message:
package ‘shiny’ is not available (for R version 3.1.1)
Is there any work-around on this issue? Such as starch the apt-get to install the latest R version rather than 3.1.1? Or possibly install shiny from a Github repo? Please help! Thanks!
You should be able to get the R package yourself, rather than using apt-get. This way you can choose which release to install. For example:
wget http://cran.rstudio.com/src/base/R-3/R-3.2.2.tar.gz
tar zxvf R-3.2.2.tar.gz; cd R-3.2.2/
./configure; make;
sudo make install
Then you can get shiny through the terminal as well, rather than within R:
wget https://cran.r-project.org/src/contrib/shiny_0.13.2.tar.gz
sudo R CMD INSTALL shiny_0.13.2.tar.gz
credit to Huiong Tian, from whom I learned this a while back:
http://withr.me/install-shiny-server-on-raspberry-pi/

Resources