title: Make raster stack with different extent
body: <p>I am in trouble making raster stack which have slightly different extent. The answer (1st one) given <a href="https://stackoverflow.com/questions/31114542/bring-rasters-to-same-extent-by-filling-with-na-in-r">here</a> is useful but did not help in my case. For example, I want to make a raster stack using <a href="https://data.biogeo.ucdavis.edu/data/worldclim/v2.0/tif/base/wc2.0_30s_bio.zip" rel="nofollow noreferrer">bio2 raster</a> for Australia and <a href="ftp://203.101.225.64/tern-soils/Products/National_digital_soil_property_maps/AWC/AWC_000_005_05_N_P_AU_NAT_C_20140801.tif" rel="nofollow noreferrer">this Australian raster</a>. The second raster comes for Australia only and the first one is global. So I cropped the global bio2 raster to the same extent of Australian raster using <code>crop()</code> function, but the resultant raster extent (i.e., <code>bio2.au</code>) is slightly different (therefore, I cannot make raster using the cropped raster and the Australian raster, <code>awc</code>). Sample code is below:</p>
  <pre><code>library(raster)
  awc &lt;- raster(&quot;path to Australian raster&quot;)
  bio2.g &lt;- raster(&quot;path to Bio2 global raster&quot;)
  # crop bio2.g to the same extent of awc
  bio2.au &lt;- crop(bio2.g, extent(awc))
  
  # make a raster stack
  st &lt;- stack(awc, bio2.au)
  Error in compareRaster(x) : different extent
  </code></pre>
  <p>I have also tried using <code>quick=TRUE</code> within the <code>stack()</code> function. But in this case the cell values in <code>awc</code> is lost. Note: the size of <code>awc</code> raster is 4gb.</p>
  <pre><code># first make a list of rasters saved in the computer
  li &lt;- list.files(&quot;path to file&quot;, pattern = &quot;.tif$&quot;, full.names = TRUE)
  st &lt;- stack(li, quick=TRUE)
  st[[1]] # no cell values for awc
  </code></pre>
  <p>Your suggestions will be highly appreciated. My ultimate goal is to crop several <a href="https://data.biogeo.ucdavis.edu/data/worldclim/v2.0/tif/base/wc2.0_30s_bio.zip" rel="nofollow noreferrer">bioclim rasters</a> to the same extent of <a href="ftp://203.101.225.64/tern-soils/Products/National_digital_soil_property_maps/AWC/AWC_000_005_05_N_P_AU_NAT_C_20140801.tif" rel="nofollow noreferrer">Australian raster</a> <code>awc</code> and stack them together so that raster cell values are not lost.</p>
  <h1>Edit (after comment of @Cobin):</h1>
  <p>Below is the attribute of each raster</p>
  <pre><code># global raster (bigger raster)
  &gt; r
  class       : RasterLayer 
  dimensions  : 21600, 43200, 933120000  (nrow, ncol, ncell)
  resolution  : 0.008333333, 0.008333333  (x, y)
  extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
  data source : D:\Worldclim2_Bioclim\wc2.0_bio_30s_02.tif 
  names       : wc2.0_bio_30s_02 
  values      : 0, 37.06667  (min, max)
  
  
  # Australian raster (smaller raster)
  &gt; r1
  class       : RasterLayer 
  dimensions  : 43201, 49359, 2132358159  (nrow, ncol, ncell)
  resolution  : 0.0008333333, 0.0008333333  (x, y)
  extent      : 112.8921, 154.0246, -44.00042, -7.999583  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
  data source : D:\SoilAWC5cm.EV1.tif 
  names       : SoilAWC5cm.EV1 
  values      : 2.997789, 27.86114  (min, max)
  
  # new raster, after crop() function is applied
  &gt; r2 &lt;- crop(r,extent(r1))
  &gt; r2
  class       : RasterLayer 
  dimensions  : 4320, 4936, 21323520  (nrow, ncol, ncell)
  resolution  : 0.008333333, 0.008333333  (x, y)
  extent      : 112.8917, 154.025, -44, -8  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
  data source : C:\Users\Anwar\AppData\Local\Temp\Rtmpmg9fyF\raster\r_tmp_2018-11-23_164300_11308_65747.grd 
  names       : wc2.0_bio_30s_02 
  values      : 1.933333, 18.15833  (min, max)
  
  # rebuild r2 to match r1
  &gt; r22 &lt;- raster(vals=values(r2),ext=extent(r1), nrows=dim(r1)[1],ncols=dim(r1)[2])
  
  Error in setValues(r, vals) : 
    length(values) is not equal to ncell(x), or to 1
  </code></pre>