isciences / exactextractr

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

Understanding error message regarding single data frame #87

Closed fabeit closed 1 year ago

fabeit commented 2 years ago

I am trying to use the following

myrast=rast(ymin=-90,ymax=90,xmin=-180,xmax=180,nrows=90,ncols=180) myshape=read_sf(myshape.shp) sf [287 × 34] (S3: sf/tbl_df/tbl/data.frame)

result=exact_extract(myrast,myshape,fun=sum)

Error in .local(x, y, ...) : exact_extract was called with a function that does not appear to be of the form function(values, coverage_fractions, ...). If the summary function should accept a single data frame argument, set summarize_df = TRUE

I am not sure what does this mean. Can you please help?

dbaston commented 2 years ago

It means that the summary function needs to accept the values as a first argument and the coverage fractions as a second argument, like the built-in function weighted.mean. The error is raised because the sum function does not accept the coverage fractions. Maybe calling with fun = 'sum' will provide the behavior you are looking for?