using exact_extract from exactextractr in R

Viewed 316

I am trying to run the example code from the exactextractr package in R

library(raster)
library(sf)
library(exactextractr)


    brazil <- st_as_sf(getData('GADM', country='BRA', level=2))
    
    
    prec <- getData('worldclim', var='prec', res=10)
    
    brazil$mean_dec_prec <- exact_extract(prec[[12]], brazil, 'mean')
    
    
    brazil <- cbind(brazil, exact_extract(prec, brazil, c('min', 'max')))

When I get to the third line I keep getting the following error

    in CPP_stats(x, weights, wkb, default_value, default_weight, coverage_area,  : 
  Cannot convert object to a function: [type=NULL; target=CLOSXP, SPECIALSXP, or BUILTINSXP].

I've searched around but I can't find anyone else having this error, I've had other people run the code, we are using the same package versions and it works fine for them.

Does anyone have any ideas on the problem or how to fix it?

Thanks, Dave

2 Answers

It seems this was a package version issue, resolved by updating.

I was able to reproduce the bug with version 0.5.2, but it worked fine with version 0.7.2

So it's maybe not the best fix but the only thing that worked was deleting all the packages involved and reinstalling them. For some reason even just updating them wouldn't work, had to completely get rid of them first

Related