值未复制到下一个(本地)环境?

考虑来自位于calcDistance内部的browser()的以下输出:

Called from: calcDistance(object = rst, xy = xy[[i]][j, ], effect.distance = effect.distance)
Browse[1]> ls.str()
effect.distance :  num 236
object : Formal class 'RasterLayer' [package "raster"] with 12 slots
xy :  Named num [1:2] -101.8 35.5

Browse[1]> 
debugging in: xyValues(object = object, xy = xy, buffer = effect.distance)
debug: standardGeneric("xyValues")

Browse[2]> ls.str()
object : Formal class 'RasterLayer' [package "raster"] with 12 slots
xy :  Named num [1:2] -101.8 35.5

功能如下:SimulationRun> createDistRaster> calcDistance>光栅:: xyValues.在上面的输出中,您仅看到最后两个. xyValues来自栅格数据包.

代码的第一段显示存在三个对象:effect.distance,object,xy.
在第二段中,我们通过调用debug(xyValues)进入xyValues.
在第三段中,我们可以看到effect.distance丢失了.

我的问题是:尽管对象和xy似乎可以复制到xyValues环境中,但effect.distance却不是.如何解释呢?

我的sessionInfo()

R version 2.11.1 (2010-05-31) 
i386-pc-mingw32 

locale:
[1] LC_COLLATE=Slovenian_Slovenia.1250  LC_CTYPE=Slovenian_Slovenia.1250   
[3] LC_MONETARY=Slovenian_Slovenia.1250 LC_NUMERIC=C                       
[5] LC_TIME=Slovenian_Slovenia.1250    

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] raster_1.3-11   foreach_1.3.0   codetools_0.2-2 iterators_1.0.3
 [5] Hmisc_3.8-2     survival_2.35-8 spam_0.22-0     splancs_2.01-27
 [9] sp_0.9-66       spatstat_1.20-2 deldir_0.0-12   mgcv_1.6-2     

loaded via a namespace (and not attached):
[1] cluster_1.12.3     grid_2.11.1        lattice_0.18-8     Matrix_0.999375-39
[5] nlme_3.1-96        tools_2.11.1 
最佳答案
更新:
在R邮件列表中也讨论了此问题,在特定情况下,事实证明这是解析传递的参数时的错误/不一致.这是报告给R的.可以在以下位置找到讨论:
Nabble

相当有趣的问题.当您检查

showMethods("xyValues",incl=T)

有两个重要的代码块.一个带有签名向量的xy,一个带有xy的矩阵.由于您的对象是“ RasterLayer”对象,因此需要确保origin.point是矩阵.如果我们看一下代码,这实际上是违反直觉的

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.")
    }
}

因此,这实际上仅将xy参数转换为矩阵,并将所有其他参数传递给下一个泛型.下一个必须是这个,然后:

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, ...)
}

这个采用参数“ buffer”.为什么在解析树中找不到参数的值,我不知道,但是您可以尝试通过提供矩阵(而不是向量)作为输入来避免方法级联.

转载注明原文:值未复制到下一个(本地)环境? - 代码日志