[R-sig-Geo] raster package feature suggestion: give more detailed error output in stack()

Kenny Bell kmb56 at berkeley.edu
Thu Mar 24 21:40:29 CET 2016


I am running ``stack()`` on a large number of ``.bil`` files, of which many
are corrupted in the download process. I'd like to be able to extract which
file fails from the error output and automatically redownload it.

I run:

    stack(many_bil_files)

    Error in .local(.Object, ...) :
      '<file name here>' not recognised as a supported file format.


    Error in .rasterObjectFromFile(x, band = band, objecttype =
"RasterLayer",  :
      Cannot create a RasterLayer object from this file.

The first error is thrown by ``raster:::.rasterFromGDAL()`` and contains
the file name, but a ``tryCatch`` call retrieves the second error message,
which doesn't contain the file name.

So, an easy solution is to change the error message in
``.rasterObjectFromFile`` to:

    stop(paste("Cannot create a RasterLayer object from file: ", x))

Which would then give the file name as part of the error message that users
can retrieve.

A more complicated, but user friendly, solution would output a vector of
failed files from the stack() call itself.

Hope this helps,
Kenny

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list