[R-sig-Geo] read GRASS6 from outside

Roger Bivand Roger.Bivand at nhh.no
Thu Nov 13 15:40:05 CET 2008


On Thu, 13 Nov 2008, Patrick Giraudoux wrote:

> Roger Bivand a écrit :
>> On Thu, 13 Nov 2008, Patrick Giraudoux wrote:
>> 
>>> Dear listers,
>>> 
>>> I am using GRASS6 embedded within QGIS under Windows for teaching purpose. 
>>> This prevents reading GRASS objects from R within GRASS (R cannot be 
>>> launched within GRASS in this configuration).
>> 
>> Patrick,
>> 
>> Could you explain why not? I can launch it, and I know others can, at least 
>> by:
>> 
>> Plugins -> GRASS -> Open GRASS Tools -> shell
>> 
>> and typing the full path to Rgui.exe at the shell prompt, for me:
>> 
>> $ "C:/Program Files/R/R-2.8.0/bin/Rgui.exe"
>> 
>> You may need to set the path to R_LIBS in user environment variables, or to 
>> add it to the command line in the GRASS shell prompt, or use .libPaths() 
>> within R, but beyond that, things should work, including file transfer etc.
>> 
>> The startup message in the current release does say "GRASS not running" 
>> because QGIS does not set the GRASS_VERSION or LOCATION_NAME environment 
>> variables, but does set GISRC - I'll try to fix that.

This should be fixed in the version of the package just submitted to CRAN. 
It is worth noting, however, that it hasn't been tested on GRASS < 6.3, 
but works - giving the correct GRASS version and LOCATION - on Linux (of 
course!), Windows Cygwin, Windows native GRASS, and QGIS 0.11 GRASS 
plugin.

The Windows native GRASS also needs the full path to Rgui.exe entered into 
the lower panel of the Output - GIS.m window, followed by -> Run. If there 
are any GRASS or QGIS developers online - might it be possible to put R on 
a button with the full path string somewhere in an editable option?

Roger

>> 
>> Doing getwd() in R will show that R is in the QGIS MSYS home directory for 
>> the user. This of course places R "on top" in standard spgrass6 fashion, 
>> but QGIS can be used at the same time. Work is progressing to embed R 
>> within QGIS, see:
>> 
>> http://www.ftools.ca/manageR.html
>> 
>> but until this is up and easily installable, going through the GRASS shell 
>> seems to work. Note that when you do system() from R, QGIS expects all 
>> executables to have the .exe extension added:
>> 
>> system("g.list rast") # fails
>> system("g.list.exe rast") # succeeds
>> 
>> Hope this helps,
>> 
>> Roger
>> 
>> PS. Note that the QGIS MSYS GRASS shell does history, so it logs the 
>> command to start R, which you retrieve with the up arrow in the usual way - 
>> the only editing needed is when you upgrade R.
>> 
>>> 
>>> I was wondering if it would be possible to read GRASS objects (vector, 
>>> raster layers, region values, etc.) in R (eg to sp objects) from outside 
>>> GRASS, with functions analogous to those  provided with spgrass6.
>> 
>> PPS. In desperation, use v.(in/out).ogr and r.(in/out).gdal matched with 
>> read(GDAL/OGR) and write(GDAL/OGR) in rgdal, but watch which directory they 
>> land in.
>> 
>>> 
>>> Any idea welcome.
>>> 
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>> 
>> 
> Roger,
>
> Ashes on my head ! I was convinced (means perfectly stuborn here)  that GRASS 
> within QGIS was closed to any call to external programmes. Which is obviously 
> wrong ! So I did not even try... Real apologize to have lost your time for 
> writing a response.
>
> Cheers,
>
> Patrick
>
>
>

-- 
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 R-sig-Geo mailing list