Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renv::init() terra installation fails #1954

Open
luisesanmartin opened this issue Jul 30, 2024 · 4 comments
Open

renv::init() terra installation fails #1954

luisesanmartin opened this issue Jul 30, 2024 · 4 comments

Comments

@luisesanmartin
Copy link

I have encountered an error when trying to reproduce an environment from a colleague using renv::init() and an R installation in a conda environment. This is the prompt generated after my attempt:

- Installing terra ...                          FAILED
Error: Error installing package 'terra':
=================================

* installing *source* package 'terra' ...
** package 'terra' successfully unpacked and MD5 sums checked
** using staged installation

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs
using C compiler: 'x86_64-w64-mingw32-gcc.exe (conda-forge gcc 14.1.0-0) 14.1.0'
using C++ compiler: 'x86_64-w64-mingw32-g++.exe (conda-forge gcc 14.1.0-0) 14.1.0'
rm -f terra.dll RcppExports.o RcppFunctions.o RcppModule.o arith.o crs.o distRaster.o distance.o extract.o file_utils.o focal.o gcp.o gdal_algs.o gdal_multidimensional.o gdalio.o geodesic.o geos_methods.o geosphere.o math_utils.o mediancut.o memory.o movingWindow.o ncdf.o ram.o raster_methods.o raster_stats.o rasterize.o read.o read_gdal.o read_ogr.o sample.o sort.o spatBase.o spatDataframe.o spatFactor.o spatRaster.o spatRasterMultiple.o spatSources.o spatTime.o spatVector.o spatVector2.o string_utils.o vecmath.o vecmathse.o vector_methods.o write.o write_gdal.o write_ogr.o
cp -r "C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/share/gdal" ../inst/
cp: cannot stat 'C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/share/gdal': No such file or directory
make: *** [Makevars.ucrt:13: winlibs] Error 1
ERROR: compilation failed for package 'terra'
* removing 'C:/WBG/Rep-checks/RR_WLD_2024_153/renv/library/R-4.3/x86_64-w64-mingw32/.renv/1/terra'
install of package 'terra' failed [error code 1]

The relevant information from the lockfile is this:

{
  "R": {
    "Version": "4.3.3",
    "Repositories": [
      {
        "Name": "CRAN",
        "URL": "https://cran.rstudio.com"
      }
    ]
  },
  "Packages": {

... (more packages here)

"terra": {
      "Package": "terra",
      "Version": "1.7-29",
      "Source": "Repository",
      "Repository": "CRAN",
      "Requirements": [
        "R",
        "Rcpp",
        "methods"
      ],
      "Hash": "89c24bf35c961e047df79dde2eb69224"
    }

I searched for possible solutions and found this issue which shows an error close to mine. However, I'm not receiving the same warning for unzip(...), which makes me think that the source of the issue is different. I'm also using RTools43 in Windows.
Any ideas will be appreciated. Thanks!

@luisesanmartin
Copy link
Author

Update:
I installed gdal in my conda environment with conda install -c conda-forge gdal and tried to initialize the renv environment again. Now the error message is different:

- Installing terra ...                          FAILED
Error: Error installing package 'terra':
=================================

* installing *source* package 'terra' ...
** package 'terra' successfully unpacked and MD5 sums checked
** using staged installation

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs
using C compiler: 'x86_64-w64-mingw32-gcc.exe (conda-forge gcc 14.1.0-0) 14.1.0'
using C++ compiler: 'x86_64-w64-mingw32-g++.exe (conda-forge gcc 14.1.0-0) 14.1.0'
rm -f terra.dll RcppExports.o RcppFunctions.o RcppModule.o arith.o crs.o distRaster.o distance.o extract.o file_utils.o focal.o gcp.o gdal_algs.o gdal_multidimensional.o gdalio.o geodesic.o geos_methods.o geosphere.o math_utils.o mediancut.o memory.o movingWindow.o ncdf.o ram.o raster_methods.o raster_stats.o rasterize.o read.o read_gdal.o read_ogr.o sample.o sort.o spatBase.o spatDataframe.o spatFactor.o spatRaster.o spatRasterMultiple.o spatSources.o spatTime.o spatVector.o spatVector2.o string_utils.o vecmath.o vecmathse.o vector_methods.o write.o write_gdal.o write_ogr.o
cp -r "C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/share/gdal" ../inst/
cp -r "C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/share/proj" ../inst/
x86_64-w64-mingw32-g++ -std=gnu++17  -I"C:/Users/wb532468/CONDA~1/envs/RR_WLD~1/lib/R/include" -DNDEBUG  -I'C:/WBG/Rep-checks/RR_WLD_2024_153/renv/library/R-4.3/x86_64-w64-mingw32/.renv/1/Rcpp/include'   -I"C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/include"     -O2 -Wall  -march=x86-64 -mtune=generic  -c RcppExports.cpp -o RcppExports.o
x86_64-w64-mingw32-g++ -std=gnu++17  -I"C:/Users/wb532468/CONDA~1/envs/RR_WLD~1/lib/R/include" -DNDEBUG  -I'C:/WBG/Rep-checks/RR_WLD_2024_153/renv/library/R-4.3/x86_64-w64-mingw32/.renv/1/Rcpp/include'   -I"C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/include"     -O2 -Wall  -march=x86-64 -mtune=generic  -c RcppFunctions.cpp -o RcppFunctions.o
x86_64-w64-mingw32-g++ -std=gnu++17  -I"C:/Users/wb532468/CONDA~1/envs/RR_WLD~1/lib/R/include" -DNDEBUG  -I'C:/WBG/Rep-checks/RR_WLD_2024_153/renv/library/R-4.3/x86_64-w64-mingw32/.renv/1/Rcpp/include'   -I"C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/include"     -O2 -Wall  -march=x86-64 -mtune=generic  -c RcppModule.cpp -o RcppModule.o
x86_64-w64-mingw32-g++ -std=gnu++17  -I"C:/Users/wb532468/CONDA~1/envs/RR_WLD~1/lib/R/include" -DNDEBUG  -I'C:/WBG/Rep-checks/RR_WLD_2024_153/renv/library/R-4.3/x86_64-w64-mingw32/.renv/1/Rcpp/include'   -I"C:/Users/wb532468/.conda/envs/RR_WLD_2024_153/Library/include"     -O2 -Wall  -march=x86-64 -mtune=generic  -c arith.cpp -o arith.o
In file included from spatVector.h:21,
                 from spatRaster.h:20,
                 from spatRasterMultiple.h:18,
                 from arith.cpp:19:
spatDataframe.h:51:41: error: 'int8_t' was not declared in this scope
   51 |                 std::vector<std::vector<int8_t>> bv;
      |                                         ^~~~~~
spatDataframe.h:28:1: note: 'int8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   27 | #include "spatFactor.h"
  +++ |+#include <cstdint>
   28 | #include <limits>
spatDataframe.h:51:41: error: template argument 1 is invalid
   51 |                 std::vector<std::vector<int8_t>> bv;
      |                                         ^~~~~~
spatDataframe.h:51:41: error: template argument 2 is invalid
spatDataframe.h:51:47: error: template argument 1 is invalid
   51 |                 std::vector<std::vector<int8_t>> bv;
      |                                               ^~
spatDataframe.h:51:47: error: template argument 2 is invalid
spatDataframe.h:68:29: error: 'int8_t' was not declared in this scope
   68 |                 std::vector<int8_t> getB(unsigned i);
      |                             ^~~~~~
spatDataframe.h:68:29: note: 'int8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
spatDataframe.h:68:35: error: template argument 1 is invalid
   68 |                 std::vector<int8_t> getB(unsigned i);
      |                                   ^
spatDataframe.h:68:35: error: template argument 2 is invalid
spatDataframe.h:79:17: error: 'int8_t' does not name a type
   79 |                 int8_t getBvalue(unsigned i, unsigned j);
      |                 ^~~~~~
spatDataframe.h:79:17: note: 'int8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
spatDataframe.h:95:45: error: 'int8_t' was not declared in this scope
   95 |                 bool add_column(std::vector<int8_t> x, std::string name);
      |                                             ^~~~~~
spatDataframe.h:95:45: note: 'int8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
spatDataframe.h:95:51: error: template argument 1 is invalid
   95 |                 bool add_column(std::vector<int8_t> x, std::string name);
      |                                                   ^
spatDataframe.h:95:51: error: template argument 2 is invalid
spatDataframe.h:103:48: error: 'int8_t' was not declared in this scope
  103 |                 void insert_column(std::vector<int8_t>, size_t i);
      |                                                ^~~~~~
spatDataframe.h:103:48: note: 'int8_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
spatDataframe.h:103:54: error: template argument 1 is invalid
  103 |                 void insert_column(std::vector<int8_t>, size_t i);
      |                                                      ^
spatDataframe.h:103:54: error: template argument 2 is invalid
make: *** [C:/Users/wb532468/CONDA~1/envs/RR_WLD~1/lib/R/etc/x64/Makeconf:272: arith.o] Error 1
ERROR: compilation failed for package 'terra'
* removing 'C:/WBG/Rep-checks/RR_WLD_2024_153/renv/library/R-4.3/x86_64-w64-mingw32/.renv/1/terra'
install of package 'terra' failed [error code 1]

I understand the output is pointing out to int_8t being the source of the error, but I'm still not able to get what's going on. I'll look for some more info tomorrow and will write any updates here. Thanks!

@kevinushey
Copy link
Collaborator

I'm also using RTools43 in Windows.

I don't think this is true; it looks like your Conda installation's gcc installation is being found and used instead. See from the output:

using C compiler: 'x86_64-w64-mingw32-gcc.exe (conda-forge gcc 14.1.0-0) 14.1.0'
using C++ compiler: 'x86_64-w64-mingw32-g++.exe (conda-forge gcc 14.1.0-0) 14.1.0'

And the compiler output does give the most probable fix:

spatDataframe.h:103:48: note: 'int8_t' is defined in header ''; this is probably fixable by adding '#include '

But unfortunately that fix would need to happen in the terra package.

@luisesanmartin
Copy link
Author

thanks, @kevinushey . In your experience and knowledge, can a solution be to indicate R to use Rtools43 instead of the GCC installation available from conda?

@kevinushey
Copy link
Collaborator

I think you can create a file at ~/.R/Makevars.ucrt, and do something like:

CC=C:/rtools43/usr/bin/gcc.exe
CXX=C:/rtools43/usr/bin/g++.exe

But I'm not positive that will still work with a Conda R installation. You might also need to modify variables like CXX11 and others -- you might need to peruse the R manuals (e.g. https://cran.r-project.org/doc/manuals/r-release/R-exts.html) for more information.

You might also want to examine the file located at:

file.path(R.home("etc"), "x64/Makeconf")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants