title: R raster functions, splitting multiple rasters from one
body: <p>I have a simple function splitting a raster object into three different classes. However my function doesn't return these rasters.  I also read this tutorial <a href="http://cran.r-project.org/web/packages/raster/vignettes/functions.pdf" rel="nofollow">http://cran.r-project.org/web/packages/raster/vignettes/functions.pdf</a>
  and according to it this is <em>"a really bad way of doing this"</em>. However the 'right way' seems overly complicated. Is it really that there is no simple way of doing this (i.e., considering functions should make things easier for you not the vice versa). </p>
  
  <p>I'm quite new to processing rasters with R so forgive me my stupid question..</p>
  
  <pre><code>rm(list=ls(all=T))
  
  r &lt;- raster(ncol=10, nrow=10)
  r[] &lt;- rnorm(100,100,5)
  
  # Create split function // three classes
  splitrast &lt;- function(rast, quantile) {
    print("Splitting raster...")
    (q &lt;- quantile(rast, probs=quantile))
    r1 &lt;- rast; r2 &lt;- rast; r3 &lt;- rast # copy raster three times
  
    r1[rast &gt; q[1]] &lt;- NA                    #raster value less than .25 quantile
    r2[rast &lt;= q[1] | rast &gt;= q[2]] &lt;- NA    #raster values is between quantiles
    r3[rast &lt; q[2]] &lt;- NA                    #raster values is over .75 quantile
    par(mfrow=c(1,3))
    plot(r1);plot(r2);plot(r3)
    rast &lt;-   brick(r1,r2,r3)
    return(rast)
  }
  
  splitrast(r,c(0.2,0.8))
  ls()
  </code></pre>
  
  <p>EDIT: reproducible example added</p>