Skip to content

GISRC environment variable using initGRASS

3 messages · Roger Bivand, Roger Bär

#
I am currently using the R package "rgrass7" (Version: 0.1-6)?in order to command GRASS GIS (Windows7, OSGEO4W installation). ?

I use R in order to start a GRASS environment and to script my geoprocessing. Both is working fine. However, I have problems with storing and calling the GRASS gisenv variables.?
Every time when I call "initGRASS" a file called "junk" is created containing GRASS gisenv variables.


Looking at the source of the initGRASS function the section below puzzeled me somehow:

?59 ? Sys.setenv(GISRC = paste(Sys.getenv("HOME"), "\\.grassrc7",?
?60 ? ? sep = ""))
?61 ? if (file.exists(Sys.getenv("GISRC")) && !override)?
?62 ? ? stop("A GISRC file already exists; to override, set override=TRUE")
?63 ?Sys.setenv(GISRC = "junk")
?64 ?cat("GISDBASE:", getwd(), "\n", file = Sys.getenv("GISRC"))
?65 ?cat("LOCATION_NAME: <UNKNOWN>", "\n", file = Sys.getenv("GISRC"),?
?66 ? ? append = TRUE)
?67 ?cat("MAPSET: <UNKNOWN>", "\n", file = Sys.getenv("GISRC"),?
?68 ? ? append = TRUE)
?69 ?gisrc <- ifelse(use_g.dirseps.exe, system(paste("g.dirseps.exe -g",?
?70 ? ? shQuote(Sys.getenv("GISRC"))), intern = TRUE), Sys.getenv("GISRC"))
?71 ? assign("addEXE", .addexe(), envir = .GRASS_CACHE)
? 72 ?Sys.setenv(GISRC = gisrc)

First, why is initGRASS using ".grassrc7" for storing the GISRC file??
InitGRASS is looking for the GISRC file under ".grassrc7" (line 59). However, in the?package documentation [1], the GISRC file is called ".gisrc". Moreover, the?GRASS documentation?says that the GISRC file is stored under "/.grass7/rc"

Second, what is the purpose of assigning "junk" to the GISRC environment variable??
GISRC is set to "junk" (line 63) and then the GISRC value ("junk") is assigned again back to system variable GISRC. Unless I misinterpreded the code, it does not make much sense to me. Shouldn't the enviroment varibales not be written (line 64 - 68) to ".grassrc7" rather than to "junk"?



I would appreciate any support or hints!

Regards,
Roger

[1] http://https//cran.r-project.org/web/packages/rgrass7/rgrass7.pdf
[2]?http://grass.osgeo.org/grass70/manuals/variables.html
#
On Fri, 15 Apr 2016, Roger B?r wrote:

            
What the file is called is probably immaterial.
This is setting GISRC to a value
This is setting it again in the working directory - I don't recall why - 
probably frustration years ago with Windows.
And this sets it again. It is set, otherwise GRASS wouldn't work; 
programmatically you'd have to use Sys.getenv("GISRC") to get the value. 
Please provide a use case where this matters, and consider moving this 
thread to the statsgrass list.

Hope this helps (doesn't clarify, but that's legacy Windows),

Roger

  
    
#
Thanks for the support!Please see below my comments.
Yes. The absolute path to the file (containing settings for GISDBASE, LOCATION_NAME and MAPSET)
I really do not understand the "junk" (line 63). Because GISRC is set to "junk" the subsequent lines of code will write the GISRC environment variables to a newly created file called "junk" in the home folder. 
Shouldn't this line not rather be omitted? 
(The GRASS environment variables would then be written to ".grassrc7", which in my opinion would be correct)
Sorry, I do not understand what you mean with "provide a use case where this matters". What do you mean with "this"?
I added the thread to the grass-stat list (and will remove r-sig from the cc the next time).
Roger