You can find the source code of function extract
for SpatialPolygons
here. The code starts with the following snippet:
setMethod('extract', signature(x='Raster', y='SpatialPolygons'),
function(x, y, fun=NULL, na.rm=FALSE, weights=FALSE, cellnumbers=FALSE, small=FALSE, df=FALSE, layer, nl, factors=FALSE, sp=FALSE, ...){
px <- projection(x, asText=FALSE)
comp <- .compareCRS(px, projection(y), unknown=TRUE)
if (!comp) {
.requireRgdal()
warning('Transforming SpatialPolygons to the CRS of the Raster')
y <- spTransform(y, px)
}
...
Which suggests that extract
does in fact perform the projection itself (changing the projection of the SpatialPolygon to the projection of the raster), despite the fact that it is not documented in the help page.