[R-sig-Geo] GRASS with R interface issues - running R within GRASS 6.4.2

Roger Bivand Roger.Bivand at nhh.no
Mon Apr 23 22:19:58 CEST 2012


On Mon, 23 Apr 2012, Laura S wrote:

> Dear Roger and others:
>
> My apologies if I am not piecing everything together. I think I am 
> almost there; I appreciate your patience.
>
>
> This is my current point of confusion, and what I am able to do so far:
>
> I. My main point of confusion is that when I type the path into GRASS 
> MSYS, the R console window pops up, and I am unable to type more into 
> the GRASS console. I cannot type GRASS commands in R, so I am unsure 
> where I type the GRASS commands if GRASS console does not let me type 
> more, and the R console does not recognize R commands.

Why should it? Simply minimise the R GUI to work in GRASS directly, using 
the GRASS GUI or from the prompt in MSYS. I doubt very much whether saying 
d.ask makes sense anyway, as the GRASS display GUI covers that.

It is possible to write GRASS commands using execGRASS() from the R 
console, but since you have had to ask, you will find it easier simply to 
minimise R and use GRASS directly. Because R is within GRASS, it "sees" 
the current status of the location.

Hope this clarifies - please change to one of the GRASS lists for further 
help.

Roger

>
>
> II. What I can do so far in more detail:
> 1. Within the GRASS 6.4.2RC2 with 
> MSYS, I typed using tab autocompletion: "C:/Program 
> Files/R/R-2.14/bin/i386/Rgui.exe" which causes the RGui to pop up as a 
> second R window. Thus, I am not in GRASS directly anymore I assume, but 
> rather in the RGui. In this GUI, it says the following when I type 
> library(spgrass6): 
> "GRASS GIS Interface loaded with GRASS version GRASS 6.4.2RC2exported (2011) and location: demolocation" 
> gmeta6() 
> gisdbase C:/Documents etc. 
>
> If I try a GRASS command such as "d.ask" in the RGUI after loading spgrass:
>
> d.ask
> Error: object 'd.ask' not found
>
>
> 2. I can also get this to work in R directly: 
> loc <- initGRASS("C:/Program Files/Grass 6.4",home=tempdir()) 
> gmeta6() 
> **prints gisdbase, etc.** 
>
> d.ask
> Error: object 'd.ask' not found
>
>
> Thank you for your help,
> Laura 
>
>
>
>
> ________________________________
> From: Roger Bivand <Roger.Bivand at nhh.no>
> To: Laura S <les_ecol at yahoo.com> 
> Cc: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org> 
> Sent: Monday, April 23, 2012 2:21:16 AM
> Subject: Re: [R-sig-Geo] GRASS with R interface issues - running R within GRASS 6.4.2
> 
> On Mon, 23 Apr 2012, Laura S wrote:
>
>> Dear all:
>>
>>
>> Should I reinstall GRASS and set up some sort of path, so that R is 
>> recognized? Would anyone be able to send me key words to find more 
>> basic, newbie, information on "PATH" and "R_LIBS"? I would like to find 
>> the paths, and set the proper variables, but I am unsure where to start. 
>> I have fiddled in GRASS now without R, but I would like to use R within 
>> GRASS.?
>>
>
> Please do try to search more effectively. The standard way of running R 
> inside GRASS on Windows is to start GRASS first in the location you are 
> using, then enter the complete path to R at the MSYS prompt. The complete 
> path is the same as the string shown as Target: under Properties if you 
> right-click on the R icon on your Windows desktop. For example:
>
> "C:/Program Files/R/R-2.15.0/bin/i386/Rgui.exe"
>
> or the equivalent for your installation. You may also need to set the 
> environment variable R_LIBS if R cannot "find" the correct library 
> containing the packages you need.
>
> If you are not using a GRASS location, you may use the initGRASS() 
> function in spgrass6 to start a temporary GRASS session, often in a 
> throw-away location, because you only need to move objects from R to 
> GRASS, use GRASS on them, and move the output objects back to R. Then you 
> need the complete path to the GRASS install directory, for example:
>
> "C:/Program Files/GRASS 6.4.2"
>
> or the equivalent for your installation.
>
> It is also possible to use initGRASS() with existing locations in a 
> scripting context, but this is not your case.
>
> The grass-stats mailing list is often used for questions like this.
>
> Hope this clarifies,
>
> Roger
>
>
>> Which location should I do all this
>> in? There are more than option for GRASS, e.g., command line, GUI (with
>> MSYS, without, etc.), MSYS UNIX console; I am not sure which one to use
>> for loading R within GRASS.
>>
>>
>> Any suggestions are much appreciated.
>>
>> Thank you,
>> Laura
>>
>>
>>> Dear all:
>>>
>>> I am trying to get
>> R to run with grass, but I am running into trouble.
>>>
>>>
>>> This is what I have done so far:
>>>
>>> Installed GRASS 6.4.2 for Windows XP
>>> Installed spgrass6 with dependencies.
>>>
>>> When I do:
>>> library(spgrass6)
>>> gmeta6()
>>>
>>> I get the following:
>>> Error in system(cmd0,intern=TRUE); "g.region.exe' not found
>>> Error in parseGRASS(cmd) : g.region not found.
>>>
>>>
>> Any suggestions are much appreciated. I am new to using GRASS with R,
>> but I am looking forward to using them together to analyze data.
>>>
>>>
>> I am unsure which terminal to run R in GRASS because I keep getting
>> errors in the command console in GRASS: I type into either "Command
>> console in GRASS GIS Layer Manager" OR "GRASS Command Line":
>>>
>>> R
>>> ...Then I get
>>>
>>> 'R' is not recognized as an internal or external command, operable program or batch file.
>>
>> This
>> suggests that you need to give the complete path to R from within your
>> GRASS session. It may be "C:/Program Files/R/R-2.14.1/bin/Rgui.exe" or
>> something like that, depending on where you installed it. You may also
>> need to add R_LIBS="<whatever>" to this, to show where any local
>> libraries may be.
>>
>> Alternatively, you may try to add R's binary
>> location to your PATH environment variable, and declare R_LIBS globally;
>> these used to be under advanced system properties.
>>
>> Finally, as
>> Rainer suggests, you may start GRASS from within R, using the same logic
>> in reverse, giving the full path to the GRASS install location to the
>> initGRASS() function. The key in both cases is to find out where in your
>> file system the software components live, and note changes when you
>> upgrade.
>>
>> Hope this helps,
>>
>> Roger
>>     [[alternative HTML version deleted]]
>>
>>
>
> -- 
> Roger Bivand
> Department of Economics, NHH Norwegian School of Economics,
> 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
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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