title: lapply to convert rasters to polygons using gdal_polygonizeR
body: <p>I am using John Baumgrtner's <code>gdal_polygonizeR</code> (<a href="https://johnbaumgartner.wordpress.com/2012/07/26/getting-rasters-into-shape-from-r/" rel="nofollow noreferrer">https://johnbaumgartner.wordpress.com/2012/07/26/getting-rasters-into-shape-from-r/</a>) to covert rasters to polygons in R. Aside - I tried <code>raster</code> pkg <code>rasterToPolygons</code> function and it took forever; <code>gdal_polygonizeR</code> is way faster. Anyways, I have a list of 533 raster files (different extents) that I want to convert to polygons. The <code>gdal_polygonizeR</code> function works when a single list element is called, but I have tried to use it on all list elements using <code>lapply</code> and get an error message. See code below:</p>
  
  <pre><code>#path to folder containing all .tif raster files
  dir &lt;- "/path/to/raster/files"
  
  #create a list of the files in the folder
  files &lt;- list.files(path = dir, pattern = ".tif$")
  
  #use lapply to import/create list of all files in folder
  rasterl_50 &lt;- lapply(paste0(dir, files), raster)
  
  #test gdal_polygonizeR function on single list element
  gdal_polygonizeR(rasterl_50[[1]])     #works properly
  
  #loop thru all elements in list
  lapply(rasterl_50, gdal_polygonizeR)
  </code></pre>
  
  <p>Output = the first six (6) elements seem to run OK, but I get the following error msg at [[7]]: </p>
  
  <blockquote>
    <p>wfp1 &lt;- gdal_polygonizeR(rasterl_50[[1]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d4dc99d8d.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    wfp2 &lt;- gdal_polygonizeR(rasterl_50[[2]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d7698a853.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    wfp3 &lt;- gdal_polygonizeR(rasterl_50[[3]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d30d4d703.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    wfp4 &lt;- gdal_polygonizeR(rasterl_50[[4]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d24036d07.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    wfp5 &lt;- gdal_polygonizeR(rasterl_50[[5]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d4683ed87.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    wfp6 &lt;- gdal_polygonizeR(rasterl_50[[6]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d4e23b4d1.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    wfp7 &lt;- gdal_polygonizeR(rasterl_50[[7]])
    Creating output /var/folders/s9/pm92gdl94h18k4n6026cb8x00000gn/T//RtmpvRRvA4/file23d6791d108.shp of format ESRI Shapefile.
    0...10...20...30...40...50...60...70...80...90...100 - done.
    Error in readOGR(dirname(outshape), layer = basename(outshape), verbose = !quiet) : 
      no features found
    In addition: Warning message:
    In ogrFIDs(dsn = dsn, layer = layer) :
     Show Traceback</p>
  </blockquote>
  
  <p>Rerun with Debug
   Error in readOGR(dirname(outshape), layer = basename(outshape), verbose = !quiet) : 
    no features found </p>
  
  <h2>#</h2>
  
  <p>If anyone has ideas for a solution using <code>lapply</code> or a for loop etc., please reply. Thanks</p>