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

Roger Bivand Roger.Bivand at nhh.no
Fri Apr 15 20:58:15 CEST 2016


On Fri, 15 Apr 2016, Roger Bär wrote:

> 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.
>

What the file is called is probably immaterial.

>
> 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 = ""))

This is setting GISRC to a value

>  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")

This is setting it again in the working directory - I don't recall why - 
probably frustration years ago with Windows.

>  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)
>

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

> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412


More information about the R-sig-Geo mailing list