Closed fab4ap closed 6 years ago
What the error is saying is that mean
(the function, i.e. a closure) is not an allowed value for "fun" - it must be a
?fasterize
#character. The name of a function by which to combine overlapping polygons.
# Currently takes "sum", "first", "last", "min", "max", "count", or "any".
You cannot apply a mean at all currently, but there's a workaround for using raster for this described in the help. Something like (untested ...)
x <- fasterize(riv129mprdsf, canus1kgrd, by = "riv129_20k", background=0)
act <- calc(x, mean)
Beware that if you have a lot of distinct values in that field you'll get a huge-number layered raster, which might be a pain so first try this, if it's more than "a few" you'll get a very large raster given your x/y dimensions here, so iterating over individual features and accumulating a sum with raster addition might be better than a big-calc in one go.
length(unique(riv129mprdsf$riv129_20k))
(Calling a function a closure shows a fun part of R's history as descendant from Lisp, and lexical scoping - it's explained here: http://adv-r.had.co.nz/Functional-programming.html#closures You also get a fun error like this from mean[1]
)
I'm closing this as it is expected behavior, but opened #18, #19, and #20 in response.
OK. Thanks much! Prasad
On Fri, Mar 23, 2018 at 10:01 AM, Noam Ross notifications@github.com wrote:
I'm closing this as it is expected behavior, but opened #18 https://github.com/ecohealthalliance/fasterize/issues/18, #19 https://github.com/ecohealthalliance/fasterize/issues/19, and #20 https://github.com/ecohealthalliance/fasterize/issues/20 in response.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ecohealthalliance/fasterize/issues/13#issuecomment-375674203, or mute the thread https://github.com/notifications/unsubscribe-auth/AjQIhyDO9VRoUOrJQ8AnHPUpJ44ZpElfks5thQApgaJpZM4SjGdq .
Hello: Wanted to report this error. Hope the foll. is self-explanatory. Works with rasterize() but not in fasterize().