Cannot install nloptr (R 4.0.3, Ubuntu 20.04) - r

I tried to install nloptr on R 4.0.3, however I get this error:
/usr/bin/ld: /usr/local/lib/libnlopt.a(general.o): relocation R_X86_64_TPOFF32 against `nlopt_srand_called' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libnlopt.a(mt19937ar.o): relocation R_X86_64_TPOFF32 against `mti' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libnlopt.a(timer.o): relocation R_X86_64_TPOFF32 against `start_inited.4301' can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:10: nloptr.so] Error 1
ERROR: compilation failed for package ‘nloptr’
* removing ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/4.0/nloptr’
Warning in install.packages :
installation of package ‘nloptr’ had non-zero exit status
Can someone point me to a solution?
Thanks in advance.

The latest (2.6.2) package of libnlopt-dev is broken in Ubuntu 20, for some reason it is compiled into a static library (.so shared object is missing)
I faced the similar problem a couple of days ago. The quick fix is to download NLOPT fron Github and compile it yourself
https://nlopt.readthedocs.io/en/latest/NLopt_Installation/
At least, it worked for me.

I had a slightly related issue with this package, apt install cmake which was suggested by cli itself fixed the issue.

I also failed to install the nloptr but had another error.
g++: error: nlopt/lib/libnlopt.a: No such file or directory
I followed others suggestion to install the nlopt first as described in nlopt website. The installation process was
mkdir build
cd build
cmake ..
make
sudo make install
But I found the cmake version which nlopt needed should be higher than 3. The default cmake in my computer was version 2.8.12.2 which was /usr/bin/cmake. So I installed cmake version 3.24.2 in my home directory and compiled the nlopt using absolute path of cmake as ~/software/install/cmake-3.24.2-linux-x86_64/bin/cmake ... And I used sudo to install the nlopt in the computer. I could see the libnlopt.so libnlopt.so.0 libnlopt.so.0.11.1 files in /usr/local/lib64
When I went back to install the nloptr in R. It still failed. I found the cmake failure in the output information of installation. So I add the cmake(version 3.24.2) to my PATH in .bashrc file and then I installed the nloptr successfully.

Related

Installing systemfonts package from CRAN and GitHub fails

I recently upgraded my intel MacBook from Catalina to Monterey (Darwin release 21.1.0) I also upgraded R from 4.0.1 to 4.1.1 via home-brew. I have reinstalled the majority of packages necessary for my work, however, ran into issues with mapview. It failed to install due to an issue with a dependency - systemfonts. I attempted to install systemfonts directly from CRAN and after that failed from GitHub which also failed with these messages:
/bin/sh: I/usr/local/Cellar/r/4.1.1_1/lib/R/include: No such file or directory
make: [mac/FontManagerMac.o] Error 127 (ignored)
and
clang: error: no such file or directory: 'mac/FontManagerMac.o'
make: *** [systemfonts.so] Error 1
ERROR: compilation failed for package ‘systemfonts’
* removing ‘/usr/local/lib/R/4.1/site-library/systemfonts’
Warning message:
In i.p(...) :
installation of package ‘/var/folders/85/56q39hqj2_gf31m9mbln7hhw0000gn/T//RtmpJGiNgA/file324134b404c/systemfonts_1.0.3.9000.tar.gz’ had non-zero exit status
I'd appreciate any thoughts on this issue. I may open an issue on GitHub r-lib/systemfonts as this may be related to some sort of incompatibility between the package and the updated OS however, thought I should start here.
Thanks
The solution listed in the issue from #Kevin_Cazelles linked to worked on my computer. Seems like it has something to do with gcc and R's call for the compiler.
This worked for me:
brew reinstall gcc
brew link --overwrite gcc
and then this in R-studio terminal
withr::with_makevars(c(OBJCXX = "gcc"), install.packages('systemfonts'))
In the bash shell:
sudo apt install libfontconfig1-dev
in RStidio
install.packages("systemfonts", dependencies = TRUE)

R package build failing on Windows machines (AppVeyor) due to missing GSL - GNU Scientific Library

I am developing an R package called DescObs (https://github.com/MaaniBeigy/DescObs). It imports conf.limits.nct function from MBESS, which itself depends on another package called gsl. It shows no problems at all for R CMD check and the installation of DescObs on Linux machines assessed by Travis continuous integration platform (https://travis-ci.org/MaaniBeigy/DescObs). However, AppVeyor fails:
** libs
*** arch - i386
C:/Rtools/mingw_32/bin/gcc -I"c:/R/include" -DNDEBUG -I/include -O3 -Wall -std=gnu99 -mtune=generic -c airy.c -o airy.o
airy.c:1:29: fatal error: gsl/gsl_sf_airy.h: No such file or directory
#include <gsl/gsl_sf_airy.h>
^
compilation terminated.
make: *** [c:/R/etc/i386/Makeconf:208: airy.o] Error 1
ERROR: compilation failed for package 'gsl'
* removing 'c:/RLibrary/gsl'
Error in i.p(...) :
(converted from warning) installation of package 'gsl' had non-zero exit status
Calls: <Anonymous> ... with_rprofile_user -> with_envvar -> force -> force -> i.p
Execution halted
Command exited with code 1
I also tried the solution recommended in Building an R package that uses the GSL on Windows but it did not help. I also compiled it using mingw-w64 and gcc-4.6.3, which both showed the same error.
Moreover, I tried to install by - cmd: vcpkg install gsl:x64-windows, but did show the same error. Here, you can see my appveyor.yml.
Do you have any ideas?
Fortunately, my previous appveyor.yml could finally build it:
install:
- ps: Bootstrap
- cmd: git submodule update --init --recursive
- cmd: git clone https://github.com/CxxTest/cxxtest
- cmd: cd c:\tools\vcpkg
- cmd: vcpkg integrate install
- cmd: vcpkg install gsl:x64-windows
- cmd: vcpkg install fftw3:x64-windows
- cmd: cd "%APPVEYOR_BUILD_FOLDER%"
environment:
global:
USE_RTOOLS: true
NOT_CRAN: true
_R_CHECK_FORCE_SUGGESTS: true
_R_CHECK_CRAN_INCOMING_: true
#R_CHECK_ARGS: "--run-dontrun"
matrix:
- R_VERSION: devel
R_ARCH: x64
GCC_PATH: gcc-4.6.3
I do not know the exact reason, but I am glad it works.
edit: I faced the problem again in another package. This line by Owen McDonnell image: previous visual studio 2015 could solve the problem. Refer to cvcqv package for the full appveyor.yml.
I came to this thread because I faced what I think is a very similar situation when I tried to update the package gsl:
installing source package 'gsl' ...
** package 'gsl' successfully unpacked and MD5 sums checked
** using staged installation
********************************************** WARNING: this
package has a configure script
It probably needs manual configuration **********************************************
** libs "C:/rtools40/mingw64/bin/"gcc -I"C:/PROGRA~1/R/R-4.1.1/include" -DNDEBUG -I/include -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c airy.c -o airy.o airy.c:1:10: fatal error: gsl/gsl_sf_airy.h: No such file or
directory #include <gsl/gsl_sf_airy.h>
^~~~~~~~~~~~~~~~~~~ compilation terminated. make: *** [C:/PROGRA~1/R/R-4.1.1/etc/x64/Makeconf:238: airy.o] Error 1 ERROR:
compilation failed for package 'gsl'
removing 'C:/Users/shima/OneDrive/Documents/R/win-library/4.1/gsl'
restoring previous 'C:/Users/shima/OneDrive/Documents/R/win-library/4.1/gsl' Warning in
install.packages : installation of package ‘gsl’ had non-zero exit
status
This thread helped me find the solution, a warm thank you, along with this discussion and this one
For those of you on Windows, using Rtools, here are my steps to solve this issue, i.e. not being able to update gsl package in R under windows:
start Rtools Bash (found in apps, Rtools 4.0 in the Windows menu)
Run pacman -S mingw-w64-x86_64-gsl and confirm with yes (y)
I don't think it's relevant, but i ran pacman -Syu just before to update my Rtools and throwing the command pacman -Sl gave me the correct name of the package for the pacman command in 2.
Updating gsl in Rstudio now leads to a clean
DONE (gsl)

Where should I search for the installed R packages by conda?

I am installing r packages using conda. It works fine when I use this example format
"conda install -c r r-scales --name condaenv"
But when I want to define installtion directory using --prefix
conda install -c r r-scales --prefix=/opt/local
the package "scale" is installed but I cannot find it in the directory I expect to be
"/opt/local/lib/R/library"
. It is weird because when I try to reinstall this package it says
All requested packages already installed.
that means this package is already installed in defined path. BUT WHERE?
I also try using
conda list
But I cannot find "scales" among installed packages.
UPDATE:
I also tried to use install.packages("scales), but I ran into this error
/opt/anaconda/bin/x86_64-conda_cos6-linux-gnu-ld: cannot find -lm
collect2: error: ld returned 1 exit status make: ***
[/raid60/raid2/opt/local/lib/R/share/make/shlib.mk:6: scales.so] Error
1 ERROR: compilation failed for package ?scales?
* removing ?/raid60/raid2/opt/local/lib/R/library/scales?

gcc error when installing Statnet package

Installing statnet on mac 10.10.3 with R 3.2.x (RStudio 0.99.441).
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [latentnet.so] Error 1
ERROR: compilation failed for package ‘latentnet’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/latentnet’
Warning in install.packages :
installation of package ‘latentnet’ had non-zero exit status
ERROR: dependency ‘latentnet’ is not available for package ‘statnet’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/statnet’
Warning in install.packages :
installation of package ‘statnet’ had non-zero exit status
I tried updating XCode/Command Line Tools. Also tried not installing dependencies. I have been able to install other packages, such as ergm and sna.
It looks like the install is looking for the GCC folder and not finding it.
whereis gcc
reveals that my gcc is in /usr/bin/gcc
It looks like the install is looking for it in /usr/local/lib/gcc/
Is there a way to fix this?
This is a compilation error that you only get if you are trying to install packages from source, or when a package requires a library to be compiled from source. Normally, if you don’t use the latest version of R, you can install statnet from binary and thus R won’t have to compile the source package.
The version you are mentioning at the beginning of your message (0.99.441) is the version of your R-Studio, and not R. The version of your R is 3.2.x (Hence its address in the Library folder: /Library/Frameworks/R.framework/Versions/3.2/Resources…). Before trying to fix the compilation error you may want to try to roll back your R to a version like 3.1.2 or 3.1.3 on which you can probably download and install statnet in binary format.
For the compiler, my guess is that even if you fix the address of your gcc with a symlink, you will still get an error about gfortran or the version of gcc. Once I solved this issue by installing R and the right version of gcc through Homebrew, but right now I don’t have the possibility to try the solution and tell you exactly how.
My experience (on Yosemite) is that if you use 3.1.2 or 3.1.3, even if there is need for compilation, the error with gcc won’t occur.
sudo mkdir /usr/bin/lib && sudo ln -s /usr/bin/gcc /usr/bin/lib/gcc
Creates a new directory in /usr/bin called `lib' and creates a symbolic link to gcc in that new directory.
If that doesn't fix the error, you can undo it with:
sudo rm -i /usr/bin/lib/gcc && sudo rm -id /usr/bin/lib

"Unable to compile a JNI program" when installing rJava [duplicate]

I am not able to call rJava package in R 3.0. I got the following message
Error: package ‘rJava’ was built before R 3.0.0: please re-install it
I am getting error when I tried to re-install rJava package. I have provided the output of R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.7.0_21
Java home path : /usr/lib/jvm/java-7-openjdk-i386/jre
Java compiler : /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javac
Java headers gen.: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/javah
Java archive tool: /usr/lib/jvm/java-7-openjdk-i386/jre/../bin/jar
trying to compile and link a JNI progam
detected JNI cpp flags :
detected JNI linker flags :
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -O2 -pipe -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program
Java library path:
JNI cpp flags :
JNI linker flags :
Updating Java configuration in /usr/lib/R
Done.
I am using Ubuntu 13.04. I also tried apt-get install r-cran-rjava which is not helping to solve the issue. Regarding jni.h there were some solution here. But, not sure how can I use the solution here.
I ran into the exact same issue. My solution was to install the openjdk-7-* via
sudo apt-get install openjdk-7-*
Followed that with
sudo R CMD javareconf
and I was then able to install rJava in R via install.packages("rJava").
While perhaps not the most elegant solution it appears to have solved my problems with getting rJava to work.
For those getting the error:
error: unable to load shared object '/some/dir/rJava/libs/rJava.so': libjvm.so:
cannot open shared object file: No such file or directory
I solved the error locating the library in the system and linking them to /usr/lib:
$sudo updatedb
$locate libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/debug/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/jamvm/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/zero/libjvm.so
$sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server/libjvm.so /usr/lib/
Installing rJava from the distribution packages as proposed in this askUbuntu answer also works:
sudo apt-get install r-cran-rjava
NOTE: tried from a Debian system.
I was also facing same error which was on RHEL8.1 & i resolved it as follows:
yum --enablerepo=* install java-1.8*
later i ran same command which was giving me error logs of R server.
R CMD javareconf
which turns into following output.

Resources