I'm trying to access GRASS functionality via spgrass6 and a plr script.

The following works (when executed directly from within R)...

library(spgrass6)
initGRASS(gisBase = "/usr/local/grass-6.4.3svn/", home = tempdir(), gisDbase = "/usr/local/share/grassdata/", location = "aust_dem_1sec_wgs84", mapset = "ubuntu", SG="aust_dem_1sec", override = TRUE)
execGRASS("g.region", parameters = list(n="-34.9759927736275", s="-34.9985728860995", e="138.641896696527", w="138.619947232807", align="aust_dem_1sec"))
execGRASS("r.viewshed", parameters = list(input = "aust_dem_1sec", output = "viewshed_raster", coordinate = "138.630922,-34.987283", obs_elev = 25, max_dist = 1000), flags = c("b", "overwrite")) 
execGRASS("r.to.vect", parameters = list(input = "viewshed_raster", output = "viewshed_vector", feature = "area"), flags = c("overwrite")) 
execGRASS("v.out.ogr", parameters = list(input = "viewshed_vector", dsn = "PG:host=localhost dbname=test user=postgres password=password", olayer = "viewshed_vector", format = "PostgreSQL", type = "area"), flags = c("c")) 

But not so when called by a plr function...

CREATE OR REPLACE FUNCTION generate_viewshed() RETURNS text as $$
library(spgrass6)
initGRASS(gisBase = "/usr/local/grass-6.4.3svn/", home = tempdir(), gisDbase = "/usr/local/share/grassdata/", location = "aust_dem_1sec_wgs84", mapset = "ubuntu", SG="aust_dem_1sec", override = TRUE)
execGRASS("g.region", parameters = list(n="-34.9759927736275", s="-34.9985728860995", e="138.641896696527", w="138.619947232807", align="aust_dem_1sec"))
execGRASS("r.viewshed", parameters = list(input = "aust_dem_1sec", output = "viewshed_raster", coordinate = "138.630922,-34.987283", obs_elev = 25, max_dist = 1000), flags = c("b", "overwrite")) 
execGRASS("r.to.vect", parameters = list(input = "viewshed_raster", output = "viewshed_vector", feature = "area"), flags = c("overwrite")) 
execGRASS("v.out.ogr", parameters = list(input = "viewshed_vector", dsn = "PG:host=localhost dbname=test user=postgres password=password", olayer = "viewshed_vector", format = "PostgreSQL", type = "area"), flags = c("c")) 
$$ LANGUAGE 'plr';

I get the following error.... which through a process of elimination the error occurs at the initGRASS() line...

ERROR:  R interpreter expression evaluation error
DETAIL:  Error in parseGRASS(cmd) : g.region not parsed
CONTEXT:  In PL/R function generate_viewshed

Is there a compatibility issue between plr and spgrass6, or is it due to something on my part?   Any suggestions?

BTW, I've also posted this on the plr mailing list.

Thanks

Mark
	[[alternative HTML version deleted]]

