I am trying to reproduce the example posted on

Extracting intersection areas in R

Although, when I try to create the SpatialPolygon "p2", R returns the error: "Error in as.vector(x) : no method for coercing this S4 class to a vector".

Any suggestions why is it happening? How can I fix it?

  • The exampled worked perfectly for me. I suggest checking that all the needed libraries in the example were loaded without any problem!
    – Guz
    Commented Feb 23, 2017 at 18:08

1 Answer 1


The intersect function is masked. Try raster::intersect() instead of intersect().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.