[GRASS-user] spgrass6 in GRASS script

Roger Bivand Roger.Bivand at nhh.no
Thu Feb 22 09:59:58 EST 2007


On Thu, 22 Feb 2007, Martin Wegmann wrote:

> Hello,
> 
> I am trying to insert R commands in a GRASS script.
> 
> The indirect way works:

The next release of R (2.5.0) will include an Rscript #! scripting 
facility, see help(Rscript) in the development snapshots. I'm not sure 
that this will get round the argument passing problem, but it just might, 
provided the templates can be written as shell scripts for R first.

Roger

> 
> ...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 ...
> R
> require(spgrass6)
> 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)'
> 
> and:
> echo "
> require(spgrass6)
> 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 
> scripts.
> I appreciate any help/links/documents where R spgrass6 commands are included 
> in a GRASS script.
> 
> thanks in advance, Martin
> 
> _______________________________________________
> grassuser mailing list
> grassuser at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grassuser
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the grass-user mailing list