[GRASS-dev] R script runs in loop when using execGRASS("r.random" ...)

Hi,

I have a shell script which writes a R script to file and then runs it. The R script includes some calls to GRASS functions using the execGRASS function from the spgrass6 package. This all works fine except when I make a call to the GRASS function r.random. It will run, but at the end of the script, the script will start from the beginning… and this will continue till using ctrl+c. This is in GRASS 7.0 on Ubuntu 12.10. In GRASS6.4 the same problem does not happen.

A simplified example of my script is below:

#!/bin/sh

LOGDIR=“$HOME”
LOGFILE=“$LOGDIR/r_model_eval.log”
echo “r.model.edm :” >> “$LOGFILE”
writeScript1(){
cat > $1 << “EOF”
options(echo = TRUE)
require(spgrass6)
execGRASS(“r.random”, flags=“overwrite”, input=“pnv_900m”, n=“100”, raster_output=“test”)
EOF
}
RGRASSSCRIPT1=“g.tempfile pid=$$
writeScript1 “$RGRASSSCRIPT1”
R --no-save --no-restore --no-site-file --no-init-file < $RGRASSSCRIPT1 > $LOGFILE 2>&1

A small part of the logfile looks like:

options(echo = TRUE)
require(spgrass6)
Loading required package: spgrass6
Loading required package: sp
Loading required package: XML
GRASS GIS interface loaded with GRASS version: GRASS 7.0.svn (2013)
and location: AEA
execGRASS(“r.random”, flags=“overwrite”, input=“pnv_900m”, n=“100”, raster_output=“test”)
Collecting Stats…
0% 3% 6% 9% 12% 15% 19% 22% 25% 28% 31% 34% 38% 41% 44% 47% 50% 53% 57% 60% 63% 66% 69% 73% 76% 79% 82% 85% 88% 92% 95% 98% 100%
Writing raster map …
0% 3% 6% 9% 12% 15% 18% 21% 24% 27% 30% 33% 36% 39% 42% 45% 48% 51% 54% 57% 60% 63% 66% 69% 72% 75% 78% 81% 84% 87% 90% 93% 96% 99% 100%
save.image(file=“testing.RData”)
options(echo = TRUE)
require(spgrass6)
execGRASS(“r.random”, flags=“overwrite”, input=“pnv_900m”, n=“100”, raster_output=“test”)
Collecting Stats…
0% 3% 6% 9% 12% 15% 19% 22% 25% 28% 31% 34% 38% 41% 44% 47% 50% 53% 57% 60% 63% 66% 69% 73% 76% 79% 82% 85% 88% 92% 95% 98% 100%
Writing raster map …
0% 3% 6% 9% 12% 15% 18% 21% 24% 27% 30% 33% 36% 39% 42% 45% 48% 51% 54% 57% 60% 63% 66% 69% 72% 75% 78% 81% 84% 87% 90% 93% 96% 99% 100%
save.image(file=“testing.RData”)
options(echo = TRUE)
.
.
etc…

As you can see, after creating the random layer, it starts the script again (line 14). It only happens, it seems, when using execGRASS to run the r.random function (or use a direct system call). Using execGRASS with any other function work fine it seems.

I am not sure this is a problem with GRASS GIS, R, or what, but let me first try the GRASS GIS email list. Any idea what could go wrong here?

Cheers,

Paulo