I would like to crop the no-data part of some rasters (example of the image in 1 where no-data is in black) without defining the extent manually.
Any idea?
You can use trim
for that:
library(raster)
r <- raster(ncol=18,nrow=18)
r[39:49] <- 1
r[205] <- 6
s <- trim(r)