[R-sig-Geo] GISRC environment variable using initGRASS

Roger Bär baerroger at outlook.com
Fri Apr 15 20:35:11 CEST 2016


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
 		 	   		  


More information about the R-sig-Geo mailing list