isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
272 stars 26 forks source link

error with argument include_cell=TRUE in exact_extract #65

Closed jldupouey closed 2 years ago

jldupouey commented 2 years ago

A simple exact_extract fails when asking for the cell index:

> library(exactextractr)
> library(raster)
Loading required package: sp
Warning message:
package ‘sp’ was built under R version 4.1.2 
> library(sf)
Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1
Warning message:
package ‘sf’ was built under R version 4.1.2 
> 
> rast <- raster::raster(matrix(1:100, ncol=10), xmn=0, ymn=0, xmx=10, ymx=10)
> poly <- sf::st_as_sfc('POLYGON ((2 2, 7 6, 4 9, 2 2))')
> 
> exact_extract(rast,poly)
[[1]]
   value coverage_fraction
1     32        0.14285715
2     42        0.50000000
3     33        0.42857143
...
> exact_extract(rast,poly,include_cell=TRUE)
Error in CPP_exact_extract(x, weights, wkb, default_value, default_weight,  : 
  Cannot convert object to a function: [type=NULL; target=CLOSXP, SPECIALSXP, or BUILTINSXP].
dbaston commented 2 years ago

This example works for me with both the master and CRAN (v0.7.2) versions of exactextractr. Can you please paste your sessionInfo() ?

jldupouey commented 2 years ago

Here it is:

> sessionInfo()

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252   
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

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

other attached packages:
[1] sf_1.0-4            raster_3.5-2        sp_1.4-6           
[4] exactextractr_0.7.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7         magrittr_2.0.1     units_0.7-2        tidyselect_1.1.1  
 [5] lattice_0.20-44    R6_2.5.1           rlang_0.4.11       fansi_0.5.0       
 [9] dplyr_1.0.7        tools_4.1.1        grid_4.1.1         utf8_1.2.2        
[13] KernSmooth_2.23-20 terra_1.4-22       e1071_1.7-8        DBI_1.1.1         
[17] ellipsis_0.3.2     class_7.3-19       assertthat_0.2.1   tibble_3.1.4      
[21] lifecycle_1.0.0    crayon_1.4.1       purrr_0.3.4        vctrs_0.3.8       
[25] codetools_0.2-18   glue_1.4.2         proxy_0.4-26       compiler_4.1.1    
[29] pillar_1.6.2       generics_0.1.0     classInt_0.4-3     pkgconfig_2.0.3   
dbaston commented 2 years ago

Can you update to the latest version of the package and try again?

jldupouey commented 2 years ago

Thank you, it now works very well with the latest version (0.7.2). Sorry for my post, I should have installed this new version first. Anyway, exactextractr is a very useful package.

Jean-Luc