Skip to content
Prev 27001 / 29559 Next

How to test for a layer in GRASS GIS mapset using rgrass7

On Tue, 4 Dec 2018, Christian Willmes wrote:

            
You need to wrap the test in try() if it may not succeed (in nc):

oo <- try(execGRASS("g.findfile", element="cell", file="slope",
       mapset="'.'", intern=TRUE), silent=TRUE)
ifelse(class(oo) == "try-error", FALSE, TRUE)

and use intern to capture the output if the file exists. However, you can, 
as Rich says, simply overwrite existing files if you wish.
Note that your R script does not stop, simply g.findfile has returned 1 
rather than 0 on exit.

Hope this clarifies,

Roger