Skip to content

scoping issue with xyValues?

2 messages · Roman Luštrik, Robert J. Hijmans

#
Hi Roman,
There is a signature(object="Raster", xy="vector"), and RasterLayer
inherits from Raster. However, that function does not have a 'buffer'
argument (an oversight, perhaps). I believe that is what causes your
grief (I need to look into this more carefully). You can probably fix
this by using the "..." argument in your function declaration; as
these will be passed on. At least in the example below test1, using
the dots, works, while test2 does not.

library(raster)
test1 = function(r, xy, ...) {  return( xyValues(r, xy, ...) ) }
test2 = function(r, xy, buffer, fun) { return( xyValues(r, xy,
buffer=buffer, fun=fun) )}

r = raster()
r[] = 1:ncell(r)
xy = c(0,0)

xyValues(r, c(0,0), buffer=100000, fun=mean)
test1(r, c(0,0), buffer=100000, fun=mean)
test2(r, c(0,0), buffer=100000, fun=mean)

Best, Robert
On Thu, Aug 26, 2010 at 6:03 AM, Roman Lu?trik <roman.lustrik at gmail.com> wrote: