[英]Error in as.vector(data) : no method for coercing this S4 class to a vector
[英]getMethod resulting in “Error in as.vector(…”
為了回答這個問題 ,我試圖看一下從包raster
extract
函數的源代碼。
> 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函數,因此我遵循以下答案的指導原則:
> 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'
我目前在Mac上使用R 2.14.2,軟件包raster
的版本是1.9-92。 雖然,我在變更日志中沒有看到任何暗示它是版本問題的信息。
我還嘗試了以下操作,但未成功:
> getMethod("extract",signature="SpatialPolygons")
Error in getMethod("extract", signature = "SpatialPolygons") :
No method found for function "extract" and signature SpatialPolygons
您尚未提供完整的簽名...。
簽名是字符串的命名或未命名向量。 如果已命名,則名稱必須是通用函數的形式參數名稱。 簽名與通用函數的簽名槽中指定的參數匹配
getMethod("extract" , signature = c( x = "Raster" , y = "SpatialPolygons") )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.