From aa1cc02ee617235bbd08fcc28b547ea22f88d59f Mon Sep 17 00:00:00 2001 From: Roger Bivand Date: Mon, 28 Feb 2022 14:08:04 +0100 Subject: [PATCH] add env. var GRASS_INSTALLATION to initGRASS man page for checking --- man/initGRASS.Rd | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/man/initGRASS.Rd b/man/initGRASS.Rd index 88fef5d..8ea9fcd 100644 --- a/man/initGRASS.Rd +++ b/man/initGRASS.Rd @@ -49,9 +49,28 @@ remove_GISRC() \seealso{\code{\link{gmeta}}} \examples{ -\dontrun{ -initGRASS("/usr/bin/grass-7.0.0", home=tempdir()) -initGRASS("C:/GRASS", home=tempdir()) +GRASS_INSTALLATION <- Sys.getenv("GRASS_INSTALLATION") +run <- FALSE +if (nzchar(GRASS_INSTALLATION)) run <- file.info(GRASS_INSTALLATION)$isdir +run <- require(terra, quietly=TRUE) +if (run) { +f <- system.file("ex/elev.tif", package="terra") +r <- rast(f) +plot(r, col=grDevices::terrain.colors(50)) +} +if (run) { +(loc <- initGRASS(GRASS_INSTALLATION, home=tempdir(), SG=r, override=TRUE)) +} +if (run) { +write_RAST(r, "elev", flags="overwrite") +execGRASS("r.info", map="elev") +} +if (run) { +execGRASS("r.slope.aspect", flags="overwrite", elevation="elev", slope="slope", aspect="aspect") +} +if (run) { +u1 <- read_RAST(c("elev", "slope", "aspect"), return_format="terra") +plot(u1[["elev"]], col=grDevices::terrain.colors(50)) } } % Add one or more standard keywords, see file 'KEYWORDS' in the