If I have to crop a raster for a irregular shapefile (for e.g. a country), I would do a crop
followed by mask
as follows:
library(raster)
r <- crop(my_raster, extent(polygon))
r <- mask(r, polygon)
Is there any equivalent of doing the same for polygons. I tried the below to clip world river basin shapefile for a given country but it only returned me the basins that were included in the extent and not the basin following the boundary of the shapefile
library(sf)
cropped <- st_crop(river_basins, country_shapefile)