values not being copied to the next (local) environment?

拈花ヽ惹草 提交于 2019-12-02 03:29:17

UPDATE : This problem is also discussed on the R mailing list, and it turned out to be a bug/inconsistency in the resolving of passed arguments in specific cases. This is reported to R. The discussion can be found at : Nabble


Quite an interesting problem. When you check

showMethods("xyValues",incl=T)

There are two important chunks of code. The one with signature vector for xy, and one for xy as a matrix. As your object is a "RasterLayer" object, you need to make sure origin.point is a matrix. This is pretty counterintuitive actually if we look at the code

object="Raster", xy="vector"
function (object, xy, ...) 
{
    if (length(xy) == 2) {
        callGeneric(object, matrix(xy, ncol = 2), ...)
    }
    else {
        stop("xy coordinates should be a two-column matrix or data.frame, or a vector of two numbers.")
    }
}

So this actually only transforms the xy argument to a matrix, and passes all other arguments to the next generic. The next one has to be this one then :

object="RasterLayer", xy="matrix"
function (object, xy, ...) 
{
    .local <- function (object, xy, method = "simple", buffer = NULL, 
        fun = NULL, na.rm = TRUE) 
    {
        if (dim(xy)[2] != 2) {
            stop("xy has wrong dimensions; it should have 2 columns")
        }
        if (!is.null(buffer)) {
            return(.xyvBuf(object, xy, buffer, fun, na.rm = na.rm))
        }
        if (method == "bilinear") {
            return(.bilinearValue(object, xy))
        }
        else if (method == "simple") {
            cells <- cellFromXY(object, xy)
            return(.readCells(object, cells))
        }
        else {
            stop("invalid method argument. Should be simple or bilinear.")
        }
    }
    .local(object, xy, ...)
}

This one takes the argument "buffer". Why the value for the argument can't be found in the parse tree, I have no clue, but you could try to avoid the method cascade by giving a matrix as input instead of a vector.

buffer argument is passed through ... argument. Type str(list(...)) under debug mode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!