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

Milton Cezar Ribeiro miltinho.astronauta at gmail.com
Tue May 5 08:31:47 EDT 2009


Thanks for both, Markus and Roger Bivand.

Cheers

milton

2009/5/5 Roger Bivand <Roger.Bivand at nhh.no>

>
> >From spgrass6 0.6-*, and after installing the R XML package (off CRAN but
> installs automatically from Prof. Ripley's extra Windows repository if you
> are on Windows), you can use:
>
> rasterfiles <- execGRASS("g.mlist", parameters=list(type="rast",
> pattern="*ele*"), intern=TRUE)
>
> (here from spearfish, which has *ele* rasters in PERMANENT). Do:
>
> parseGRASS("g.mlist")
>
> to see the flags and parameters. As Markus pointed out, intern=TRUE is the
> key argument, to get the output of the GRASS command back into the R
> workspace. There are issues with regard to quoting between platforms for a
> few GRASS commands, but most things now work. I tried this on MSYS Windows
> native 6.4.0 RC4.
>
> Roger
>
>
>
> Milton Cezar Ribeiro wrote:
> >
> > Hi Markus,
> >
> > Under windows I needed only small changes
> >
> > rasterfiles <- read.table(textConnection(system("g.mlist.exe rast
> > pattern=*output*", intern = TRUE)))
> > Thanks a lot,
> >
> > milton
> >
> > 2009/5/4 Markus Neteler <neteler at osgeo.org>
> >
> >> 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
> >>
> >
> > _______________________________________________
> > grass-user mailing list
> > grass-user at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/grass-user
> >
> >
>
>
> -----
> Roger Bivand
> Economic Geography Section
> Department of Economics
> Norwegian School of Economics and Business Administration
> Helleveien 30
> N-5045 Bergen, Norway
>
> --
> View this message in context:
> http://n2.nabble.com/passing-output-from-GRASS-to-R.-tp2788835p2791576.html
> Sent from the Grass - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20090505/5466050b/attachment.html


More information about the grass-user mailing list