Unable to install packages via renv::restore() ("R was unable to find one or more FORTRAN libraries during compilation.") - r

I've downloaded an old repo on a new laptop (running on MacOS Catalina) and attempted to run a R script.
The repo has a renv lock file - meaning, I should be able to restore all dependencies as they were.
But as I run the renv::restore() command, this error message appears:
Installing pbapply [1.4-3] ...
OK [linked cache]
Installing mvtnorm [1.1-2] ...
FAILED
Error installing package 'mvtnorm':
===================================
* installing to library ‘~/renv/staging/2’
* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ 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 C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fPIC -Wall -g -O2 -c miwa.c -o miwa.o
gfortran -fPIC -g -O2 -c mvt.f -o mvt.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fPIC -Wall -g -O2 -c mvtnorm-init.c -o mvtnorm-init.o
gfortran -fPIC -g -O2 -c tvpack.f -o tvpack.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o mvtnorm.so C_FORTRAN_interface.o miwa.o mvt.o mvtnorm-init.o tvpack.o -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mvtnorm.so] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘~/renv/staging/2/mvtnorm’
------------------------------------------------------------------------------
R was unable to find one or more FORTRAN libraries during compilation.
This often implies that the FORTRAN compiler has not been properly configured.
Please see https://stackoverflow.com/q/35999874 for more information.
Reason(s):
- 'ld: library not found for -lgfortran'
Error: install of package 'mvtnorm' failed [error code 1]
Traceback (most recent calls last):
13: renv::restore()
12: renv_restore_run_actions(project, diff, current, lockfile, rebuild)
11: renv_install(records)
10: renv_install_staged(records)
9: renv_install_default(records)
8: handler(package, renv_install_impl(record))
7: renv_install_impl(record)
6: withCallingHandlers(renv_install_package_local(record), error = function(e) {
vwritef("\tFAILED")
writef(e$output)
})
5: renv_install_package_local(record)
4: renv_install_package_local_impl(package, path)
3: r_cmd_install(package, path)
2: r_exec_error(package, output, "install", status)
1: stop(error)
I can't make sense of the link in the error message (copied here: Mac OS X R error "ld: warning: directory not found for option").
From my problem search, I've come across some possible solutions that are above my R knowledge level, e.g.:
"[...] creating the file ~/.R/Makevars within my home directory." (Unable to install fortran based packages in R - "gfortran -m32:not found")
"[...] installed gcc & gcc-fortran and that solved it" (Unable to install a package on R)
Similar ideas here: OS X package installation depends on gfortran-4.8
Some guidance here would be deeply appreciated. Please let me know if there's any other info you need (first time posting here).
Thanks in advance!
Solution
Download and install "gfortran-6.1.pkg (OS X 10.11+, signed, 64-bit)" from this page: https://cran.r-project.org/bin/macosx/tools/

Related

irlba not installing on Mac OS

I cannot seem to get the irlba R package to install on my mac system.
After running install.packages("irlba", force = TRUE, type = "source"), I get the following error
Content type 'application/x-gzip' length 233555 bytes (228 KB)
==================================================
downloaded 228 KB
* installing *source* package ‘irlba’ ...
** package ‘irlba’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Matrix/include' -I/usr/local/include -fPIC -Wall -g -O2 -c irlb.c -o irlb.o
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Matrix/include' -I/usr/local/include -fPIC -Wall -g -O2 -c utility.c -o utility.o
clang -mmacosx-version-min=10.13 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o irlba.so irlb.o utility.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [irlba.so] Error 1
ERROR: compilation failed for package ‘irlba’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/irlba’
Warning in install.packages :
installation of package ‘irlba’ had non-zero exit status
What does the ...had a non-zero exit status warning tag mean? and how can I resolve that?
I would appreciate any help with this!
You are missing a FORTRAN compiler on macOS which is common and well-known. CRAN maintains a dedicated section on how to work around that, see and carefully read:
https://mac.r-project.org/tools/

tm package installation errors in R version 3.6.1 (2019-07-05) -- "Action of the Toes"

I am trying to work with tm package in R on my Macbook Pro (late 2011) running under macOS High Sierra Version 10.13.6. The tm package has been installed but when I load it, I receive the following error message
Error: package or namespace load failed for ‘tm’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘slam’
Then I tried to install slam and got this:
There is a binary version available but the source
version is later:
binary source needs_compilation
slam 0.1-45 0.1-46 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
installing the source package ‘slam’
trying URL 'https://cran.rstudio.com/src/contrib/slam_0.1-46.tar.gz'
Content type 'application/x-gzip' length 53515 bytes (52 KB)
==================================================
downloaded 52 KB
* installing *source* package ‘slam’ ...
** package ‘slam’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c apply.c -o apply.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c dll.c -o dll.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c grouped.c -o grouped.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c sparse.c -o sparse.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c util.c -o util.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o slam.so apply.o dll.o grouped.o sparse.o util.o -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [slam.so] Error 1
ERROR: compilation failed for package ‘slam’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/slam’
Warning in install.packages :
installation of package ‘slam’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/zq/lzsw_rp15sj3wtfvb3r0kksc0000gn/T/RtmpX95gez/downloaded_packages’```
Can anyone please help me fix this?
Thanks!
I have come across exactly the same issue today. I'm running R 3.6.1 (as you are) on a Mac Book Pro using macOS Mojave (10.14.6), and I have the same error messages.
I tried some of the answers from here:
dependency ‘slam’ is not available when installing TM package
by trying:
install.packages("NLP", dependencies = TRUE)
install.packages("tm", dependencies = TRUE)
.....but no joy.
So I went to here:
https://cran.r-project.org/web/packages/slam/index.html
And downloaded slam_0.1-45.tgz to my Downloads folder
And then installed it directly from there, using:
install.packages("~/Downloads/slam_0.1-45.tgz", repos = NULL, type = .Platform$pkgType)
And it seems to now install the tm package fine.

Trouble installing rcpp package on R server- Suse 12 SP3 - R-3.3.2

I am very new to R language. Being an admin I am setting up an rserver and installing the required packages for my use of this R server with SAP HANA 1.0.
The fundamental problem here is when i am installing the rcpp.0.12.16 and getting the below error. g++ is 4.8-6.189.
Are there an incompatibilities witht the OS version R version and rccp package i am using? Please help resolving this issue.
> setwd("/Media/R/R_indep_pack")
> install.packages("Rcpp_0.12.16.tar.gz",repos = NULL, type="source")
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -
I/usr/local/include -fPIC -c Date.cpp -o Date.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -
I/usr/local/include -fPIC -c Module.cpp -o Module.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -
I/usr/local/include -fPIC -c Rcpp_init.cpp -o Rcpp_init.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -
I/usr/local/include -fPIC -c api.cpp -o api.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -
I/usr/local/include -fPIC -c attributes.cpp -o attributes.o
g++ -I/usr/local/lib64/R/include -DNDEBUG -I../inst/include/ -
I/usr/local/include -fPIC -c barrier.cpp -o barrier.o
g++ -L/usr/local/lib64/R/lib -L/usr/local/lib64 -o Rcpp.so Date.o Module.o
Rcpp_init.o api.o attributes.o barrier.o -L/usr/local/lib64/R/lib -lR
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crt1.o: In function
`_start':
/home/abuild/rpmbuild/BUILD/glibc-2.22/csu/../sysdeps/x86_64/start.S:114:
undefined reference to `main'
collect2: error: ld returned 1 exit status
/usr/local/lib64/R/share/make/shlib.mk:6: recipe for target 'Rcpp.so' failed
make: *** [Rcpp.so] Error 1
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/usr/local/lib64/R/library/Rcpp’
Warning message:
In install.packages("Rcpp_0.12.16.tar.gz", repos = NULL, type = "source") :
installation of package ‘Rcpp_0.12.16.tar.gz’ had non-zero exit status
>
Your linker is looking for a main function since it is not told to build a shared library:
g++ -L/usr/local/lib64/R/lib -L/usr/local/lib64 -o Rcpp.so Date.o Module.o
Rcpp_init.o api.o attributes.o barrier.o -L/usr/local/lib64/R/lib -lR
Here a -shared is missing from the command line. The command line flags used here are defined via the Makevars file:
$ grep SHLIB.*LDFLAGS $(R RHOME)/etc/Makeconf
SHLIB_CXXLDFLAGS = -shared
SHLIB_CXX98LDFLAGS = -shared
SHLIB_CXX11LDFLAGS = -shared
SHLIB_CXX14LDFLAGS = -shared
SHLIB_CXX17LDFLAGS = -shared
SHLIB_FCLDFLAGS = -shared
SHLIB_LDFLAGS = -shared# $(CFLAGS) $(CPICFLAGS)
SHLIB_LINK = $(SHLIB_LD) $(SHLIB_LDFLAGS) $(LIBR0) $(LDFLAGS)
SHLIB_CXX1XLDFLAGS = -shared
Either these are incorrectly set on your system or you are overriding them via ~/.R/Makevars.
In ubuntu, in such situation, I would search for
apt search rcpp # search in central repository for \
# packages for R packages
In this case, this leads to 'r-cran-rcpp' package which I then install with
sudo apt install r-cran-rcpp
(such packages from 'r-cran-' help, because they install for you the further dependencies in the system - which are often dependencies outside of R - automatically for you. E.g. some packages require java or some other system libraries.).
Similarly, you have to search in rpm or yast2 repos for rcpp packages.
I found googling http://rpmfind.net/linux/rpm2html/search.php?query=R-Rcpp
or http://rpm.pbone.net/index.php3/stat/4/idpl/33595438/dir/opensuse/com/R-RcppArmadillo-0.4.450.1.0-2.38.i586.rpm.html
Or: if you are using conda:
conda install -c r r-rcpp
would definitely help ...
If you don't know conda: This tutorial is super!
https://www.youtube.com/watch?v=YJC6ldI3hWk
Just spend 11 minutes and you will be able to use conda!
(With conda, you can install several R versions with all their packages in parallel in your system - sometimes you need that because some versions are not compativle with some R packages - conda creates for you different local environments within which you can install programs with all their specific dependencies. And you can switch between the environments.)
I definitely recommend you to use conda. Because this solves many package dependency problems.

Installing R package BASiCS on macOS High Sierra

I'm trying to install BASiCS in R 3.4.2 on macOS High Sierra. I've installed R via homebrew. I've also installed gfortran as part of gcc via brew install gcc.
Still, I get the error below. Does anyone have a clue how to resolve this?
Thanks,
ERROR MESSAGE IN R
Downloading GitHub repo catavallejos/BASiCS#master
from URL https://api.github.com/repos/catavallejos/BASiCS/zipball/master
Installing BASiCS
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ \
--no-save --no-restore --quiet CMD INSTALL \
'/private/var/folders/xk/dfj20kgd56xg8796xh874tjr0000gn/T/RtmpW243tu/devtools3375bbc3c81/catavallejos-BASiCS-407caff' \
--library='/Library/Frameworks/R.framework/Versions/3.4/Resources/library' \
--install-tests
* installing *source* package ‘BASiCS’ ...
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppArmadillo/include" -I/usr/local/include -fPIC -Wall -g -O2 -c BASiCS_CPPcode.cpp -o BASiCS_CPPcode.o
In file included from BASiCS_CPPcode.cpp:12:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/RcppCommon.h:122:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/exceptions.h:103:53: warning: all paths through this function will call itself
[-Winfinite-recursion]
inline void warning(const std::string& message) { // #nocov start
^
1 warning generated.
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppArmadillo/include" -I/usr/local/include -fPIC -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o BASiCS.so BASiCS_CPPcode.o RcppExports.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [BASiCS.so] Error 1
ERROR: compilation failed for package ‘BASiCS’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BASiCS’
Installation failed: Command failed (1)
It seems you need to install gfortran from CRAN, rather than via homebrew.
I had the same problem and solved it with this github recommendation.

loop_apply.o: file not recognized: File format not recognized

I am trying to install R’s plyr package. Here is the error message:
* installing *source* package ‘plyr’ ...
** package ‘plyr’ successfully unpacked and MD5 sums checked
** libs
clang++ -I/opt/R-3.4.1/include -DNDEBUG -I"/home/isomorphismes/R/i686-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -I/opt/boost_1_61_0/boost -c RcppExports.cpp -o RcppExports.o
clang -I/opt/R-3.4.1/include -DNDEBUG -I"/home/cd/R/i686-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -g -O2 -flto -c loop_apply.c -o loop_apply.o
clang++ -I/opt/R-3.4.1/include -DNDEBUG -I"/home/isomorphismes/R/i686-pc-linux-gnu-library/3.4/Rcpp/include" -I/usr/local/include -fpic -I/opt/boost_1_61_0/boost -c split-numeric.cpp -o split-numeric.o
clang++ -shared -L/usr/local/lib -o plyr.so RcppExports.o loop_apply.o split-numeric.o
loop_apply.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/opt/R-3.4.1/share/make/shlib.mk:6: recipe for target 'plyr.so' failed
make: *** [plyr.so] Error 1
ERROR: compilation failed for package ‘plyr’
* removing ‘/home/cd/R/i686-pc-linux-gnu-library/3.4/plyr’
The *.o files are in /opt/plyr/src, from github.com/hadley/plyr. They look like this on my system:
i#scheherezade:/opt/plyr/src$ file *o
loop_apply.o: LLVM IR bitcode
RcppExports.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
split-numeric.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
In case you didn't know, -flto specifies link time optimization, and has been added by R. How did you manage to end up with such a mis-configured R install?
Adding -flto to the link command may work? Or remove it from the loop_apply compilation line. If either of those works, you need to fix your R install.
Compiling with -flto using clang requires (on Ubuntu) installing the llvm-dev package. Otherwise, the linker is unable to handle -flto object files.
apt-get install clang-10 llvm-10-dev
Now the linking should succeed.

Resources