2

To answer this question, i tried to look at the source code of function extract from package 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.

Since it is a S4 function, i followed the guideline from 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"

But then fell on this error:

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

I'm currently on R 2.14.2, on a Mac and the version of package raster is 1.9-92. Although, i didn't see anything in the changelogs suggesting it's a version issue.

I also tried the following without success:

> getMethod("extract",signature="SpatialPolygons")
Error in getMethod("extract", signature = "SpatialPolygons") : 
  No method found for function "extract" and signature SpatialPolygons
Community
  • 1
  • 1
plannapus
  • 18,529
  • 4
  • 72
  • 94

1 Answers1

4

You haven't supplied the whole signature....

A signature is a named or unnamed vector of character strings. If named, the names must be formal argument names for the generic function. Signatures are matched to the arguments specified in the signature slot of the generic function

getMethod("extract" , signature = c( x = "Raster" , y = "SpatialPolygons") )
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
  • Indeed I just found it out. Still the r-faq question i linked to needs to be corrected since the function has to be provided as a character string. – plannapus Oct 11 '13 at 08:06
  • @plannapus sorry I don't see a link to r-faq? Just SO questions? – Simon O'Hanlon Oct 11 '13 at 08:10
  • Yeah sorry i meant the SO question tagged r-faq: http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function (I did correct it a minute ago). – plannapus Oct 11 '13 at 08:11
  • Slightly on the side, how easy would it be to change the content of 'getMethod("extract" , signature = c( x = "Raster" , y = "SpatialPolygons") )'? I would e.g. have liked to change the weighting functionality of 1/100 to 1/10.. – ego_ Nov 19 '13 at 18:13