Unable to install the package "png" on R, possible conflict with Anaconda? - r

I'm trying to install the package "png" on RStudio but I get the following error, I run on Ubuntu 16.04:
Error: package or namespace load failed for ‘png’ in dyn.load(file,
DLLpath = DLLpath, ...):
unable to load shared object '/home/doma/R/x86_64-pc-linux-gnu
library/3.4/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
I have installed Anaconda so I was wondering if it could be the problem, since the file libpng16.so.16 is actually installed in anaconda's libraries.
Thank you!

You must install this ubuntu package before installing png in R.
Try the following:
Installing directly using apt-get.
sudo apt-get install libpng16-16
If this doesn't work, please install manually.
wget https://cfhcable.dl.sourceforge.net/project/libpng/libpng16/1.6.34/libpng-1.6.34.tar.xz
tar xf libpng-1.6.34.tar.xz
cd libpng-1.6.34/
./configure
sudo make check
sudo make install
Finally, install R package in R terminal.
> install.packages('png')

On CentOS7, system-wide libpng is 15, while anaconda has 16. During install.packages('png'), gcc with flag "-L//anaconda/lib" is called. I temporarily removed anaconda path from PATH variable, then the gcc command of install.packages('png') is without the flag, and install.packages('png') installed successfully.

Related

How to install Rmpfr on Ubuntu 18.04?

After install.packages("Rmpfr") I'm getting this error
configure: error: Header file mpfr.h not found; maybe use
--with-mpfr-include=INCLUDE_PATH
ERROR: configuration failed for package ‘Rmpfr’
I typed the suggestion --with-mpfr-include=INCLUDE_PATH into the terminal w/o success.
Look here: https://github.com/cran/Rmpfr
You first have to install the dependend libraries.
sudo apt-get install libmpfr-dev
sudo su - -c "R -e \"install.packages('Rmpfr', repos='http://cran.rstudio.com/')\""
It is also a better solution to install the R-Packages from the console, not inside R, since every user on the machine will have access to the package then. Otherwise it will just be in your personal library.

Installing Rmpi on Ubuntu 16.04 VirtualBox

I created a new ubuntu-16.04.2-desktop-amd64 machine on VM VirtualBox and I want to be able to use the R environment with Rmpi.
Both of the below approaches gives a similar error.
Updated simplified pre-build binary approach:
When Ubuntu had installed I opened a terminal and executed the following commands:
~$ sudo apt-get update
~$ sudo apt-get install openmpi-bin
~$ sudo apt-get install r-base
~$ sudo apt-get install r-cran-rmpi
~$ R
This opened the R terminal and I invoking the follow function which resulted in an error:
> library(Rmpi)
libmpi.so: cannot open shared object file: No such file or directory
Error : .onLoad failed in loadNamespace() for 'Rmpi', details:
call: fun(libname, pkgname)
error: Cannot start MPI_Init(). Exit
Error: package or namespace load failed for ‘Rmpi’
Alternative approaches that I have attempted include using a local OpenMPI installation and using the R function install.packages to install the Rmpi package (see below). These all resulted in the same error.
I have also tried using MPICH by substituting ~$ sudo apt-get install mpich as the second command in the above procedure (including using the R function for installing the package) which results in an even more onerous runtime error.
Does anyone know what I have done wrong or what I can do to resolve this installation error?
Or alternatively, have anyone been able to successfully install a VirtualBox machine with Rmpi using any Linux distro or an image with pre-installed components?
Original local installation approach:
I have followed the instructions on this blog to download OpenMPI version 2.1.0, compile and install it. However when I try to install the package in R with:
> install.packages("Rmpi", configure.args =
c("--with-Rmpi-include=/home/jormunr/openmpi/include",
"--with-Rmpi-libpath=/home/jormunr/openmpi/lib",
"--with-Rmpi-type=OPENMPI",
"--with-mpi=/home/jormunr/openmpi/"))
it gives the following error
Error: .onLoad failed in loadNamespace() for 'Rmpi', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/jormunr/R/x86_64-pc-linux-gnu-library/3.2/Rmpi/libs/Rmpi.so':
libmpi.so.20: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
I can see that the 'libmpi.so.20' file is in the /home/jormunr/openmpi/lib that I provided as one of the parameter to the installation.
[Disclaimer: I am not a Linux expert and merely have user level skills. Any contributions or corrections from an expert will be greatly appreciated.]
Pre-build Binary Approach
Although trying various ways to install the prebuilt binaries I did not manage to get this option to work. This involved executing in the terminal the command 'sudo apt-get install r-cran-rmpi' to install the r-cran-rmpi prebuilt packages which also automatically installs the libopenmpi1.10 package that is a listed prerequisite. However, it appears that the file 'libmpi.so' is not included in the libopenmpi1.10 package but expected by the Rmpi library which causes an error in the R environment that it cannot find this file.
Local Installation Approach
The local installation did eventually succeed with a few amendments. I created a new ubuntu-16.04.2-desktop-amd64 VirtualBox image with default settings, except for 2048MB of memory and 32GB of hard drive space. When installed I opened a terminal and executed the commands from the Jovinge Lab website with the inclusion of the penultimate command which amends the run-time link editor's path and enables the install.package() function of R to find the 'libmpi.so' file. (also changed the version to 1.10.6 as this is the latest version release of version 1 – see below for version 2)
~$ cd /home/jormunr
~$ wget https://www.open-mpi.org/software/ompi/v1.10/downloads/openmpi-1.10.2.tar.gz
~$ tar -zxvf openmpi-1.10.6.tar.gz
~$ cd openmpi-1.10.2
~$ ./configure --prefix=/home/jormunr
~$ make
~$ make install
~$ sudo apt-get install r-base
~$ export LD_LIBRARY_PATH=/home/jormunr/lib:$LD_LIBRARY_PATH
~$ R
This opens an R terminal and I invoked the function:
> install.packages("Rmpi", configure.args =
+ c("--with-Rmpi-include=/home/jormunr/include/",
+ "--with-Rmpi-libpath=/home/jormunr/lib/",
+ "--with-Rmpi-type=OPENMPI",
+ "--with-mpi=/home/jormunr/"))
This now executed without errors and I could test it with the following R statements:
> library("Rmpi")
> mpi.spawn.Rslaves()
master (rank 0, comm. 1) of size 2 is running on: Valhalla
slave1 (rank 1, comm. 1) of size 2 is running on: Valhalla
> mpi.close.Rslaves()
[1] 1
> mpi.quit()
When I tried this process with the OpenMPI Version 2.1.0 the installation completed successfully but the above test had issues; the mpi.spawn.Rslaves() function completed but mpi.close.Rslaves() did not complete – it never returned and the terminal was left hanging.
I experienced similar challenges. I landed on this solution where libopenmpi-dev was the secret.
sudo apt-get install openmpi-common openmpi-bin libopenmpi-dev r-base
sudo apt-get install r-cran-rmpi
sudo su
R
install.packages("doMPI", dependencies=TRUE)

Unable to install rJava on R platform

I have Ubuntu 10.x OS and I have installed R on it. I want to install rJava on R. For that when I am running installed.packages("rJava) command which is giving error
checking whether Java run-time works... Error: Could not find or load main class getsp
no
configure: error: Java interpreter '/usr/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/hduser/R/i486-pc-linux-gnu-library/2.10/rJava’
The downloaded packages are in
‘/tmp/Rtmp0tlBXn/downloaded_packages’
Warning message:
In install.packages("rJava") :
installation of package 'rJava' had non-zero exit status
If I run system("java -version")
Then it showing same Java version which is given when I run Java -version command from base OS prompt. So it means no problem with Java which I can see reason in output of install package command? As suggested when I use
sudo apt-get install r-cran-rjava
Here also didnt get any luck
Please suggest
I just saw that you wrote installed.packages instead of install.packages, you have to use install.packages("rJava") to install it.
The description of the method you used (installed.packages) says: Find (or retrieve) details of all packages installed in the specified libraries.
Can you please try
install.packages("rJava")
library(rJava)
and tell me the output? (I'm pretty sure it will already work then).
in the terminal run sudo apt-get install default-jdk
then run sudo R CMD javareconf
after that you can continue in R or Rstudio install.packages("rJava")

GLPK: No such file or directory error when trying to install R package

I am trying to install sparkTable in R 3.1.0 which depends on Rglpk. I manually installed GPLK on the system and added the libs folder to LD_LIBRARY_PATH before going into R for the install.packages("sparkTable") procedure. I get this error during the installation process. Any ideas?
* installing *source* package ‘Rglpk’ ...
** package ‘Rglpk’ successfully unpacked and MD5 sums checked
** libs
/bin/sh: line 0: cd: GLPK: No such file or directory
make: *** [GLPK.ts] Error 1
ERROR: compilation failed for package ‘Rglpk’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/Rglpk’
ERROR: dependency ‘Rglpk’ is not available for package ‘sparkTable’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/sparkTable’
sudo apt-get install libglpk-dev
did the trick for me.
I had this problem and took a good bit of digging in the package to understand what was happening. If Rgplk can't compile its test program when installing, it does something weird, including this bizarre cd to nowhere. Assuming glpk-devel is installed, the reason it can't compile the test program is that it can't find the gplk header as it is in a non-standard directory.
Just set the environment variable CPATH=/usr/include/glpk
and the test program will compile, allowing the package install to proceed normally.
I had this problem too. The following steps solved this issue for me. My current setup:
OS: Scientifc Linux version 6.5 (on a High Performance Cluster Server)
local user, no root access.
GLPK was not installed
Install GLPK in a local directory:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=/home/<username>/GLPK
make
make install
Install Rglpk (0.6-3):
cd ~
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-3.tar.gz
export LIBRARY_PATH=/home/<username>/GLPK/lib
R CMD INSTALL Rglpk_0.6-3.tar.gz
I landed on this page, because I could not update igraph under Windows 10/11, since igraph also requires glpk as per OP. Specifically:
igraph_glpk_support.h:36:10: fatal error: glpk.h: No such file or
directory #include <glpk.h>
^~~~~~~~ compilation terminated. make: *** [C:/PROGRA~1/R/R-4.1.1/etc/x64/Makeconf:238: feedback_arc_set.o] Error
1 ERROR: compilation failed for package 'igraph'
removing 'C:/Users/xxx/Documents/R/win-library/4.1/igraph'
restoring previous 'C:/Users/xxx/Documents/R/win-library/4.1/igraph' Warning
in install.packages : installation of package ‘igraph’ had non-zero
exit status
I am under Windows 11 (but would be same for Windows 10).
Simple resolution is suggested here:
start Rtools Bash (found in all apps, Rtools 4.0 in the Windows menu)
Run pacman -S mingw-w64-x86_64-glpk and confirm with yes (y)
Run pacman -S mingw-w64-x86_64-libxml2 and confirm with yes (y)
Updating igraph in Rstudio now leads to a clean
DONE (igraph)
(there is no need to install anything, add any path, etc... just the above 4 steps)
In ubuntu 14.04, all above doesn't work. the following however works, without the need of installing libglpk-dev using apt-get.
download the glpk package from gnu and extract it:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.55.tar.gz
tar xvf glpk-4.55.tar.gz
make a GLPK directory in your local path:
mkdir ~/GLPK
configure within glpk:
cd glpk-4.55
./configure --prefix=$HOME/GLPK
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
download the Rglpk package from cran and extract it:
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-0.tar.gz
tar xvf Rglpk_0.6_0.tar.gz
move the glpk directory into Rglpk/src and rename it to GLPK:
mv glpk-4.55 Rglpk/src/GLPK
now you can install:
R CMD INSTALL Rglpk
now a bit of explanation of what's going on. The "src/Makevars.in" file in the Rglpk package contains a line of code to enter a non-existing directory 'GLPK' within the src/ folder:
(line 11 of Makevars.in)
GLPK.ts:
#(cd GLPK && make)
touch $#
this is where the problem arises. obviously the code is trying to build glpk within that directory for some unknown reasons. and the solution above is achieved simply by moving the downloaded (and configured) glpk directory there...
If you're on a Debian-based Linux distribution, run this to install GLTK:
sudo apt install libglpk-dev
If you're on MacOS, run this to install GLTK:
brew install gltk
Finally, install the R library:
install.packages("Rglpk")
On Centos, have sudo rights. None of the above worked, but had to install GLPK in /usr/local as suggested in this SO answer. Been trying to install it for about 3 hours fml
You must install glpk dependency first.
On macOS (via homebrew):
brew install glpk
or in RStudio (via homebrew):
system("brew install glpk")
It worked for me when I combined the answers from Simón Ramírez Amaya and shadowleaves:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=$HOME/GLPK
make
make install
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
wget https://cran.r-project.org/src/contrib/Rglpk_0.6-4.tar.gz
R CMD INSTALL Rglpk_0.6-4.tar.gz
To load the library
dyn.load(file.path(Sys.getenv("HOME"), "GLPK", "lib", "libglpk.so"))
library(Rglpk)
The answer of Zhiying Cui is right, however, if your script has some special codes, such as foreach for parallel computing, it may raise an error.
A better way is as fellow
If your os is Centos, try
yum install glpk-devel
then just go to R or Rstudio server and
install.packages("Rglpk")

how to install R packages "RNetCDF" and "ncdf" on Ubuntu?

I would like to use the R packages RNetCDF and ncdf in Ubuntu.
When I try install.packages('RNetCDF') or install.packages('ncdf'), I get similar errors:
...
ncdf.c:3:20: fatal error: netcdf.h: No such file or directory
compilation terminated.
make: *** [ncdf.o] Error 1
ERROR: compilation failed for package ‘ncdf’
...
Warning message:
In install.packages("ncdf") :
installation of package ‘ncdf’ had non-zero exit status
The packages libnetcdf6 and netcdf-bin from the Ubuntu repository are installed. Do I need to do something else?
You need to install the -dev of those packages to get the headers that are required to compile the package. In this case, you need libnetcdf-dev, udunits-bin and libudunits2-dev
In my case, libudunits2-dev package was needed.
sudo apt-get install libudunits2-dev
Since I installed NetCDF from source, I had to manually specify the locations of lib and include folders
install.packages("/home/user/Downloads/RNetCDF_1.6.1-2.tar.gz",
repos = NULL,
type="source",
dependencies=FALSE,
configure.args="--with-netcdf-include=/usr/local/netcdf-4.2.1-build/include --with-netcdf-lib=/usr/local/netcdf-4.2.1-build/lib")
Just to clarify, since your initial issue is in R, and the fix is applied outside of R. I initially was trying to do
install.packages("libnetcdf-dev"), which didn't work.
instead, from outside of R: sudo apt-get install libnetcdf-dev
That fixed it for me.
In Ubuntu 20.04 LTS one can install the ncdf4 package (which supersedes ncdf), including all dependencies, with the bash command sudo apt install r-cran-ncdf4. Similarly for RNetCDF you can use sudo apt install r-cran-rnetcdf.

Resources