title: Clipping raster using shapefile in R, but keeping the geometry of the shapefile
body: <p>I am using {raster} to clip (or crop) a raster based on an irregular shapefile (the Amazon biome) but the output always has a rectangular extent. However, I need the output in the exact same geometry of the shapefile. Any tips? Cheers.</p>
  
  <pre><code>library(raster)
  library(rgdal)
  
  myshp &lt;- readOGR("Amazon.shp", layer="Amazon")
  e &lt;- extent(myshp)
  myraster &lt;- raster("Temperature.tif")
  myraster.crop &lt;- crop(myraster, e, snap="out", filename="myoutput.tif")
  </code></pre>