R can't find icc to compile packages - r

I've compiled R-mkl package in Arch Linux using the Intel OneAPI compilers. But I cannot install packages from inside R, since it cannot find icc. The path in order to bash find the executables is defined in /etc/bash.bashrc:
export PATH="$PATH:/opt/intel/oneapi/compiler/latest/linux/bin/intel64/"
When I try to compile a package, it says it cannot find icc:
> install.packages("lazyeval")
Installing package into ‘/home/juliano/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)
tentando a URL 'https://cran.rstudio.com/src/contrib/lazyeval_0.2.2.tar.gz'
Content type 'application/x-gzip' length 83482 bytes (81 KB)
==================================================
downloaded 81 KB
* installing *source* package ‘lazyeval’ ...
** package ‘lazyeval’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
icc -std=gnu11 -I"/usr/include/R/" -DNDEBUG -I/usr/local/include -fpic -O3 -fPIC -m64 -march=native -fp-model precise -fp-model source -I/opt/intel/mkl/include -c expr.c -o expr.o
/bin/sh: linha 1: icc: command not found
make: *** [/usr/lib64/R/etc/Makeconf:169: expr.o] Erro 127
ERROR: compilation failed for package ‘lazyeval’
* removing ‘/home/juliano/R/x86_64-pc-linux-gnu-library/4.2/lazyeval’
Warning in install.packages :
installation of package ‘lazyeval’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpPvcR2C/downloaded_packages’
How I do instruct R to read /etc/bash.bashrc or define the path to the compilers manually?
I have also tried to define the path in a file in /etc/profile.d, without success.

You can try sourcing setvars.sh script to initiate the OneAPI environment.
source /opt/intel/oneapi/setvars.sh
As you said, it will work if you create a symlink to the /bin.
Refer to the below link to get more details on usage of R with Intel OneAPI
https://www.intel.com/content/www/us/en/developer/articles/technical/using-onemkl-with-r.html

Related

Installing package "quantreg" in R fails with "had non-zero exit status"

My aim is to install the R package "quantreg". In R Studio, I therefore type
install.packages("quantreg")
R Studio then prints:
binary source needs_compilation
quantreg 5.85 5.88 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel)
I consequently write "Yes" and hit enter. The installation then fails with the following output:
installing the source package ‘quantreg’
trying URL 'https://cran.rstudio.com/src/contrib/quantreg_5.88.tar.gz'
Content type 'application/x-gzip' length 1016964 bytes (993 KB)
==================================================
downloaded 993 KB
* installing *source* package ‘quantreg’ ...
** package ‘quantreg’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gfortran -fPIC -Wall -g -O2 -c akj.f -o akj.o
make: gfortran: No such file or directory
make: *** [akj.o] Error 1
ERROR: compilation failed for package ‘quantreg’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/quantreg’
Warning in install.packages :
installation of package ‘quantreg’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/bl/yxw71y6n3ksbktr_vmp65h1m0000gn/T/Rtmpc1SB0G/downloaded_packages’
I am on Mac OS 12.3.1 Monterey and use R version 3.6.3. I use this old version of R (instead of an up-to-date one) because it is required in combination with another program that I use. Therefore, I cannot use newer versions of R.
What could be a possible fix for my problem, so that R installs quantreg without failing?

How to download Sf package on MacOS

I tried a couple of hours to install sf package (on MacOs) by using most of the solutions I encountered on the web but still, it did not work. Let me show, what I did and then what the problem is step by step.
First, I tried the normal thing install.packages("sf") which resulted in the following error.
URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz' deneniyor
Content type 'application/x-gzip' length 93022013 bytes (88.7 MB)
====================================
downloaded 65.3 MB
Warning in install.packages :
downloaded length 68510897 != reported length 93022013
Warning in install.packages :
URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz': Timeout of 60 seconds was reached
Error in download.file(url, destfile, method, mode = "wb", ...) :
download from 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz' failed
Warning in install.packages :
download of package ‘sf’ failed
Following that, I tried to comply with the instructions in this website https://github.com/r-spatial/sf. To this end, I first installed home brew and then rendered these two codes on the MacOS terminal.
brew install pkg-config
brew install gdal
And, finally, in line with the website's suggestion, I run this code to install rgdal package to get sf installed.
install.packages("rgdal", configure.args = c("--with-proj-lib=/usr/local/lib/", "--with-proj-include=/usr/local/include/"))
However, it came with the following error.
There is a binary version available but the source version is later:
binary source needs_compilation
rgdal 1.5-26 1.5-27 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘rgdal’
URL 'https://cran.rstudio.com/src/contrib/rgdal_1.5-27.tar.gz' deneniyor
Content type 'application/x-gzip' length 4391149 bytes (4.2 MB)
==================================================
downloaded 4.2 MB
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
** using staged installation
configure: R_HOME: /Library/Frameworks/R.framework/Resources
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++14
configure: CFLAGS: -Wall -g -O2
configure: CPPFLAGS: -I/usr/local/include
configure: CXXFLAGS: -Wall -g -O2
configure: LDFLAGS: -L/usr/local/lib
configure: LDFLAGS: -L/usr/local/lib
configure: CXX11 is: clang++ -mmacosx-version-min=10.13, CXX11STD is: -std=gnu++11
configure: CXX is: clang++ -mmacosx-version-min=10.13 -std=gnu++11
configure: C++11 support available
configure: rgdal: 1.5-27
checking for /usr/bin/svnversion... no
configure: svn revision: 1148
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal’
Warning in install.packages :
installation of package ‘rgdal’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/tc/g15hmz9s0hg1nxmh7_4mw9lm0000gn/T/RtmplfPV9h/downloaded_packages’
As suggested in this website https://github.com/r-spatial/sf, I alternatively tried the solutions in https://github.com/r-spatial/sf/issues/1536#issuecomment-727342736.
Yet, in the part 2, when I run this code chunk,
install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source")
install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source")
library(devtools)
install_github("r-spatial/sf", configure.args = "--with-proj-lib=/usr/local/lib/")
A similar problem emerged for all these codes. For instance, for the first one, the error was;
URL 'http://R-Forge.R-project.org/src/contrib/rgeos_0.5-8.tar.gz' deneniyor
Content type 'application/x-gzip' length 276303 bytes (269 KB)
==================================================
downloaded 269 KB
* installing *source* package ‘rgeos’ ...
** using staged installation
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++14
configure: rgeos: 0.5-7
checking for /usr/bin/svnversion... no
cat: inst/SVN_VERSION: No such file or directory
configure: svn revision:
checking for geos-config... no
no
configure: error: geos-config not found or not executable.
ERROR: configuration failed for package ‘rgeos’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgeos’
Warning in install.packages :
installation of package ‘rgeos’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/tc/g15hmz9s0hg1nxmh7_4mw9lm0000gn/T/RtmplfPV9h/downloaded_packages’
And lastly, I followed the instructions to solve this problem on this website; trouble installing "sf" due to "gdal"
First: gdalinfo --version code resulted in GDAL 3.3.2, released 2021/09/01
Second, I did brew unlink gdal, yet when I run brew link --force gdal2, it did not work. (I am a new user so I assumed it might be because of different versions but when I tried brew link --force gdal3.3.2, it gave me the error Error: No such keg: /opt/homebrew/Cellar/gdal3.3.2.
So, if you can help me how to install sf on MacOS, I will be very glad for that.
The error message lines "Warning in install.packages : downloaded length 68510897 != reported length 93022013" and "Timeout of 60 seconds was reached" suggests the package didn't download properly - this can occur when it takes longer than 60 seconds to download the package to your computer for installation i.e. the "timeout" of 60 seconds is reached.
One solution (the solution that worked in this case) is to increase the amount of time R will wait to download the package by running options(timeout = 1200) before running install.packages("sf")
If you need to build packages from source (with or without openMP) on an M1 mac, I believe the instructions posted here work: https://stackoverflow.com/a/68275558/12957340
Not sure if this is helpful, but I was having similar trouble getting this installed on a fresh Mac. I ended up installing XQuartz (which I didn't have), downloading homebrew to get PROJ, and then reinstalling R (50/50 as to whether I downloaded the right version for my M1 Mac) and got everything installed properly.

Why some R packages can't be installed

I've been using R for a while and everything was normal when installing packages. Recently, I upgraded R on my Ubuntu 16.04 from 3.4.4 to 4.0.2 and then I tried to install the package imputeTS as
> install.packages("imputeTS")
Installing package into ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘png’, ‘gridtext’, ‘ggtext’
trying URL 'https://cloud.r-project.org/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 KB)
==================================================
downloaded 24 KB
trying URL 'https://cloud.r-project.org/src/contrib/gridtext_0.1.1.tar.gz'
Content type 'application/x-gzip' length 441462 bytes (431 KB)
==================================================
downloaded 431 KB
trying URL 'https://cloud.r-project.org/src/contrib/ggtext_0.1.0.tar.gz'
Content type 'application/x-gzip' length 1849875 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
trying URL 'https://cloud.r-project.org/src/contrib/imputeTS_3.1.tar.gz'
Content type 'application/x-gzip' length 3015320 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
* installing *source* package ‘png’ ...
** package ‘png’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG `libpng-config --cflags` -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c read.c -o read.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG `libpng-config --cflags` -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c write.c -o write.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o png.so read.o write.o -L/home/.../anaconda/lib -lpng16 -lm -lz -lm -L/usr/lib/R/lib -lR
installing to /home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/png’
ERROR: dependency ‘png’ is not available for package ‘gridtext’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/gridtext’
ERROR: dependency ‘gridtext’ is not available for package ‘ggtext’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/ggtext’
ERROR: dependency ‘ggtext’ is not available for package ‘imputeTS’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/imputeTS’
The downloaded source packages are in
‘/tmp/RtmpZubgYt/downloaded_packages’
Warning messages:
1: In install.packages("imputeTS") :
installation of package ‘png’ had non-zero exit status
2: In install.packages("imputeTS") :
installation of package ‘gridtext’ had non-zero exit status
3: In install.packages("imputeTS") :
installation of package ‘ggtext’ had non-zero exit status
4: In install.packages("imputeTS") :
installation of package ‘imputeTS’ had non-zero exit status
Then
> library(imputeTS)
Error in library(imputeTS) : there is no package called ‘imputeTS’
I tried to install the same package as install.packages("imputeTS", dependencies = TRUE) but this gave me the same result installation of package ‘imputeTS’ had non-zero exit status
Following, I tried to install the packages Hmisc and mice. The same result was for the first package where as mice was installed successfully!
Two more comments, the first is this statement (as ‘lib’ is unspecified) started to appear just after upgrading R. The second, I am not sure if related, is that there is no space on my linux!
So how could I install the needed packages successfuly?
Just a wrap up that people can find the correct answer given in the comments better and understand the error messages
This is no problem related specifically to the imputeTS package.
This can be seen in this part of the error message
Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
The error actually occurs while trying to install the png package.
How is this related to the imputeTS package?
You can see this here:
ERROR: loading failed
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/png’
ERROR: dependency ‘png’ is not available for package ‘gridtext’
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/gridtext’
ERROR: dependency ‘gridtext’ is not available for package ‘ggtext’
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/ggtext’
ERROR: dependency ‘ggtext’ is not available for package ‘imputeTS’
removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/imputeTS’
R packages build on each other and import functions of other packages. In this case imputeTS imports ggtext, which imports gridtext, which imports png.
So quite a sequence of dependencies and if installation of png fails, this affects all the other packages.
Luckily this part of the error message also gives a hint, what could be wrong:
unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
libpng16.so.16: cannot open shared object file: No such file or directory
There is a library missing on which the png package itself depends on. Without this library the installation of png will fail and cause all these mentioned issues.
So just install the library like this:
sudo apt-get install libpng16-16

Trouble installing package rms for Rstudio

I have been having an issue installing package rms. I am trying to interpret ordinal models (using the package ordinal) and plot regressions using them. For rms, I don't even get an error, just that it updates other loaded packages, loads and attaches package 'lubridate' which had already been installed, and that 'date' is masked from the base package.
For reference I had originally tried to install hmisc, which I found out was a dependency for rms. This led to an issue installing dependency gfortran. When I attempt to install gfortran, I get
package ‘gfortran’ is not available (for R version 3.5.1)
But then, when I try to install Hmisc, I get
installing the source package ‘Hmisc’
trying URL 'https://cran.rstudio.com/src/contrib/Hmisc_4.4-0.tar.gz'
Content type 'application/x-gzip' length 744545 bytes (727 KB)
==================================================
downloaded 727 KB
* installing *source* package ‘Hmisc’ ...
** package ‘Hmisc’ successfully unpacked and MD5 sums checked
** libs
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fPIC -Wall -g -O2 -c Hmisc.c -o Hmisc.o
gfortran -fPIC -g -O2 -c cidxcn.f -o cidxcn.o
make: gfortran: No such file or directory
make: *** [cidxcn.o] Error 1
ERROR: compilation failed for package ‘Hmisc’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Hmisc’
Warning in install.packages :
installation of package ‘Hmisc’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/5l/r40ht3p511j0mbty0ptcc7zm0000gn/T/RtmpFAI0pw/downloaded_packages’
For reference, I run this on a Mac OS Catalina (10.15.4).
Alternatively, if you have any other ways to graph regressions using ordinal models please let me know! Thank you very much.
I got a similar error even though I had installed gfortran by running brew install gfortran. But I needed to add this to my ~/.Rprofile:
Sys.setenv(PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin")

R install `KFKSDS` on mac

I am trying to install tsoutliers library in R where only the source is available and it doesn't has a CRAN package available. Also, KFKSDS in one of the dependencies that have to be installed, again, it is source code version available only.
I used brew to have gsl installed but when I tried to install KFKSDS, it still errorred out. On the other side, I installed gsl, gsl-devel, KFKSDS and tsoutliers easily on the redhat server. Can anyone show me how can I installed it successfully on my Mac. I am using R 3.1.1 which is not cutting edge but should be good enough, I guess.
> install.packages("KFKSDS", type="source")
trying URL 'http://cran.rstudio.com/src/contrib/KFKSDS_1.5.tar.gz'
Content type 'application/x-gzip' length 30272 bytes (29 Kb)
opened URL
==================================================
downloaded 29 Kb
* installing *source* package ‘KFKSDS’ ...
** package ‘KFKSDS’ successfully unpacked and MD5 sums checked
** libs
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -fPIC -mtune=core2 -g -O2 -c KF-deriv.cpp -o KF-deriv.o
In file included from /usr/include/c++/4.2.1/bits/locale_facets.h:1539,
from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from /usr/include/c++/4.2.1/numeric:67,
from KFKSDS.h:12,
from KF-deriv.cpp:1:
/usr/include/c++/4.2.1/bits/codecvt.h:219:45: error: macro "length" passed 4 arguments, but takes just 1
In file included from /usr/include/c++/4.2.1/bits/locale_facets.h:1539,
from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from /usr/include/c++/4.2.1/numeric:67,
from KFKSDS.h:12,
from KF-deriv.cpp:1:
/usr/include/c++/4.2.1/bits/codecvt.h:218: error: expected ‘;’ before ���const’
/usr/include/c++/4.2.1/bits/codecvt.h:222: error: expected `;' before ‘int’
make: *** [KF-deriv.o] Error 1
ERROR: compilation failed for package ‘KFKSDS’
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/KFKSDS’
Warning in install.packages :
installation of package ‘KFKSDS’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/d2/ffftfj193ng339zrc3jbdv75m9ssv9/T/RtmpgJshhe/downloaded_packages’

Resources