getMethod导致“as.vector中的错误(...”

时间:2013-10-11 07:48:39

标签: r s4

要回答this question,我尝试从包extract查看函数raster的源代码。

> library(raster)
> extract
standardGeneric for "extract" defined from package "raster"

function (x, y, ...) 
standardGeneric("extract")
<environment: 0x859c3e4>
Methods may be defined for arguments: x, y
Use  showMethods("extract")  for currently available ones.

由于它是S4功能,我遵循this answer的指南:

> showMethods(extract)
Function: extract (package raster)
x="Raster", y="data.frame"
x="Raster", y="Extent"
x="Raster", y="matrix"
x="Raster", y="SpatialLines"
x="Raster", y="SpatialPoints"
x="Raster", y="SpatialPolygons"
x="Raster", y="vector"

但后来却出现了这个错误:

> getMethod(extract,signature="SpatialPolygons")
Error in as.vector(x, "character") : 
  cannot coerce type 'closure' to vector of type 'character'

我目前使用的是R 2.14.2,在Mac上,包raster的版本是1.9-92。虽然,我在更改日志中没有看到任何暗示它是版本问题的内容。

我也尝试了以下但没有成功:

> getMethod("extract",signature="SpatialPolygons")
Error in getMethod("extract", signature = "SpatialPolygons") : 
  No method found for function "extract" and signature SpatialPolygons

1 个答案:

答案 0 :(得分:4)

您尚未提供整个签名....

  

签名是字符串的命名或未命名向量。如果已命名,则名称必须是泛型函数的正式参数名称。签名与通用函数

的签名槽中指定的参数匹配
getMethod("extract" , signature = c( x = "Raster" , y = "SpatialPolygons") )