rmacosgfortranrenv

renv::restore() failing to restore library installing Matrix: compilation failed


I use renv to snapshot the package library I need for a data set I created: https://github.com/mtwente/nordatlantisk-ft. However, I cloned the repository on another computer and wanted to restore the project library using renv::restore() which lead to a large chunk of error messages.

The computer on which renv throws the error has the folloing sessionInfo():

R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.3.2 tools_4.3.2    renv_1.0.3    

I opened the project in R Studio and ran renv::restore(). renv downloaded the packages as recorded the lockfile:

> renv::restore()
The following package(s) will be updated:

# CRAN -----------------------------------------------------------------------

# Since the post is too long, I put the list of installed packages here: [https://pastebin.com/QyjF9311](https://pastebin.com/QyjF9311)

Do you want to proceed? [Y/n]: y

Yes, I do.

# Downloading packages -------------------------------------------------------
- Downloading Matrix from CRAN ...              OK [file is up to date]
- Downloading mgcv from CRAN ...                OK [file is up to date]

# R telling me that it successfully downloaded the other packages mentioned above...

Successfully downloaded 111 packages in 240 seconds.

This seems to have worked just fine, but then...

# Installing packages --------------------------------------------------------
- Installing lattice ...                        OK [linked from cache]
- Installing Matrix ...

I get this wall of red lines. I cannot even scroll back to the very top in R Studio, because it is such a long output.

                              ^
../Core/t_cholmod_transpose.c:44:21: warning: variable 'nrow' set but not used [-Wunused-but-set-variable]
    Int j, p, pend, nrow, ncol, Apacked, use_fset, fp, Fpacked, jj, permute ;
                    ^
../Core/t_cholmod_transpose.c:44:56: warning: variable 'Fpacked' set but not used [-Wunused-but-set-variable]
    Int j, p, pend, nrow, ncol, Apacked, use_fset, fp, Fpacked, jj, permute ;

# Since the post is too long, I put the most part of the error messages here: [https://pastebin.com/EEVzNRf5](https://pastebin.com/EEVzNRf5)

ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' not found
ld: warning: search path '/opt/gfortran/lib' not found
ld: library 'gfortran' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Matrix.so] Error 1
ERROR: compilation failed for package ‘Matrix’
* removing ‘/Users/[username]/github/nordatlantisk-ft/renv/staging/1/Matrix’
install of package 'Matrix' failed [error code 1]

I don't even understand the error mesage in the first place, but this is very confusing to me due to the fact that renv worked just fine on the computer on which I set up the project.

There, I just get:

> renv::status()
No issues found -- the project is in a consistent state.

What was I expecting? I expected renv::restore() to install the packages recorded in my lockfile so I could use the scripts regardless of what computer I am using at the moment.

Any help to understand this errors is appreciated and also any help on how to resolve this so I can use renv as it is supposed to work!

Best regards


Solution

  • I see the system of your new computer is running OSX. On new OSX systems you need a Fortran compiler for the Matrix library (Fortran is one of the compiled programming languages R utilises for package development etc.). Have a look here and here. Quoting the first link: "In short, you need at the very least Xcode and a Fortran compiler. R 4.3.0 and higher use universal GNU Fortran 12.2 compiler."

    You will find the download links for on the pages that I shared.