When you see this error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for
function ‘crop’ for signature ‘"sf"’
it means you are trying to call
crop with an argument it was not built to understand. What does it understand? Check the
Cut out a part of a SpatRaster with a SpatExtent, or another
object from which an extent can be obtained.
But you don't have a
SpatRaster you have an
sf spatial data frame.
The functions to work with
sf data nearly all start with
st_ and live in the
help.search("crop") shows us:
sf::st_crop crop an sf object to a specific rectangle
Aliases: st_crop, st_crop.sfc, st_crop.sf
There's various ways to pass the coordinates of the crop including specifying each one as an argument, eg:
> xc = st_crop(x, xmin=500000, ymin=4140000, xmax=600000, ymax=4240000)
attribute variables are assumed to be spatially constant throughout all geometries
and I can plot that over the full data:
> plot(xc$geometry, add=TRUE, col="red")
and you can see how it has cut out the square (although you can't see the top and right edges of the square, it has cut the ring on the far right).
Note your coordinates are not in the range of the data, so maybe they are in the wrong coordinate system for this map. You need to supply the crop coordinates in the same coordinate system as the map data, so maybe you need to use
st_transform to get them correctly. But that's another question...