[GRASS-user] passing output from GRASS to R.

Markus Neteler neteler at osgeo.org
Mon May 4 17:33:11 EDT 2009


On Mon, May 4, 2009 at 8:57 PM, Milton Cezar Ribeiro
<miltinho.astronauta at gmail.com> wrote:
> Dear all,
>
> I am running R inside GRASS 6.4 and I can see a list
> of all my raster files when I type (from the R session)
>
> system("g.list rast")
>
> But I would like to pass the list of rasters to a vector object in R.
>
> I tryed innocently this, but not worked:
>
> my.rast.list<-system("g.list rast")

Try this:

> rasterfiles <- read.table(textConnection(system("g.mlist rast",intern = TRUE)))
> str(rasterfiles)
'data.frame':   42 obs. of  1 variable:
 $ V1: Factor w/ 42 levels "aspect","basin_50K",..: 31 1 2 3 4 5 6 7 8 9 ...
> rasterfiles
                     V1
1            myfacility
2                aspect
3             basin_50K
4  boundary_county_500m
...

> I also would like to define a pattern of raster names to the g.list command,
> like only return that raster names that have "_output_" on the name.

So:
> rasterfiles <- read.table(textConnection(system("g.mlist rast pattern="*_output_*",intern = TRUE)))
> str(rasterfiles)



> By the way, I am running GRASS inside MSYS, under windows.

Please report if above works (as it does on Linux).

Markus


More information about the grass-user mailing list