值没有被复制到下一个(本地)环境?
考虑位于 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 >创建DistRaster >计算距离>栅格::xy值。在上面的输出中,您只能看到最后两个。 xyValues
来自栅格包。
第一段代码显示存在三个对象:effect.distance
、object
、xy
。 在第二段中,我们通过调用 debug(xyValues) 深入到 xyValues。 在第三段中,我们可以看到缺少 effect.distance
。
我的问题是:尽管 object
和 xy
似乎复制到 xyValues
环境就好,effect.distance
> 不是。这怎么解释呢?
我的会话信息()
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
Consider this output from browser()
that is located inside calcDistance
:
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
Functions are as follows: simulationRun > createDistRaster > calcDistance > raster::xyValues. In the above output, you only see the last two. xyValues
is from raster package.
First paragraph of code shows that three objects are present: effect.distance
, object
, xy
.
In second paragraph, we descend into xyValues by calling debug(xyValues).
In third paragraph we can see that effect.distance
is missing.
My question is: Even though object
and xy
seem to be copied to the xyValues
environment just fine, effect.distance
is not. How could this be explained?
My 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:
R 邮件列表上也讨论了这个问题,结果证明这是在特定情况下解决传递参数时的错误/不一致。这将报告给 R。讨论可以在以下位置找到:
Nabble
相当有趣的问题。当你检查
There 有两个重要的代码块时。一种具有 xy 的签名向量,另一种将 xy 作为矩阵。由于您的对象是“RasterLayer”对象,因此您需要确保 origin.point 是矩阵。如果我们查看代码,这实际上是非常违反直觉的
,所以这实际上只是将 xy 参数转换为矩阵,并将所有其他参数传递给下一个泛型。那么下一个必须是这个:
这个采用参数“buffer”。为什么在解析树中找不到参数的值,我不知道,但是您可以尝试通过提供矩阵而不是向量作为输入来避免方法级联。
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
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
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 :
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
参数通过...
参数传递。在调试模式下输入str(list(...))
。buffer
argument is passed through...
argument. Typestr(list(...))
under debug mode.