title: How to get contour lines around the grids in R-raster?
body: <p>Having a raster in R, how can I draw a contour line <em>around</em> the grids (not joining the centers or anything else, really following the boundaries of the grids) having some value (or identified by some mask)?</p>
  
  <p>The following example shows how to get the contour lines around areas with value 0.6: how to do the same but with the lines following the borders of the grids? 
  The function should return an object to add to a plot (as a <code>SpatialLinesDataFrame</code> for <code>rasterToContour</code>), and adjacent grids should be included in one single contour line (i.e., only the outer boundaries of a polygon should be drawn). I couldn't find the solution with <code>rasterToPolygons</code> (see <a href="https://stackoverflow.com/questions/14379828/how-does-one-turn-contour-lines-into-filled-contours">here</a> for a visual aspect, but it didn't help me here).</p>
  
  <pre><code>set.seed(2)
  r &lt;- raster(nrow=10, ncol=10)
  r[] &lt;- runif(ncell(r))
  r[r&gt;0.6] &lt;- 0.6
  rc &lt;- rasterToContour(r, levels=c(0.6))
  plot(r)
  plot(rc, add=TRUE)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/4kK75.png" alt="enter image description here"></p>