[GRASS-user] spgrass6 in GRASS script

Martin Wegmann wegmann at biozentrum.uni-wuerzburg.de
Thu Feb 22 08:44:28 EST 2007


I am trying to insert R commands in a GRASS script.

The indirect way works:

...GRASS script ...
echo "
x <- read.table('$points.xy', sep=\"|\")
" > R_temp
echo 'source("R_temp")' | R --vanilla --slave
rm R_temp
... GRASS script ... end

but I would like to skip the export/import routines in the script and do it 
instead with spgrass6 like:

... GRASS script ...
mydata <- readFLOAT6sp(c("myraster","myraster2"))
... R analysis ...
... GRASS script ...

but this approach fails with: 
mean_extract_R: line 293: syntax error near unexpected token `spgrass6'
mean_extract_R: line 293: `require(spgrass6)'

echo "
mydata <- readFLOAT6sp(c("myraster"))
" > R_temp
echo 'source("R_temp")' | R --vanilla --slave

fails with:
Loading required package: spgrass6
Loading required package: sp
Loading required package: maptools
Loading required package: foreign
Loading required package: rgdal
Geospatial Data Abstraction Library extensions to R successfully loaded
Error in seq(along = vname) : object "myraster" not found
Execution halted

So far I did not find a threat concerning R/spgrass6-GRASS communication in 
I appreciate any help/links/documents where R spgrass6 commands are included 
in a GRASS script.

thanks in advance, Martin

More information about the grass-user mailing list