[R-sig-Geo] scoping issue with xyValues?

Robert J. Hijmans r.hijmans at gmail.com
Thu Aug 26 19:04:06 CEST 2010


Hi Roman,

> I noticed that in xyValues.R there is no method for
> signature(object="RasterLayer",
> xy="vector"). Could this be a problem?

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:
> I have a function (that is within a function and everything wrapped in a
> wrapper function) that uses raster::xyValues. When I run the wrapper
> function and try to pass xy arguments as a vector (of 2, as mentioned in the
> documentation), I get an error that the buffer argument (I call it
> effect.distance) doesn't exist. At this point I should note that the object
> is a RasterLayer. After some debugging I found that argument for buffer was
> not being passed to xyValues local environment (unlike arguments for
> objectand xy that had no trouble traversing).
>
> How I made this work:
> Either I created an effect.distance variable in the global environment or
> coerced the vector of two to a matrix (with two columns).
>
> I noticed that in xyValues.R there is no method for
> signature(object="RasterLayer",
> xy="vector"). Could this be a problem?
>
>
> Cheers,
> Roman
>
>
>
>
> --
> In God we trust, all others bring data.
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list