[GRASS-stats] [R-sig-Geo] GISRC environment variable using initGRASS
Roger Bär
baerroger at outlook.com
Mon Apr 18 02:52:26 PDT 2016
----------------------------------------
> Date: Mon, 18 Apr 2016 10:40:02 +0200
> From: Roger.Bivand at nhh.no
> To: baerroger at outlook.com
> CC: grass-stats at lists.osgeo.org
> Subject: RE: [R-sig-Geo] GISRC environment variable using initGRASS
>
> On Mon, 18 Apr 2016, Roger Bär wrote:
>
>>
>>
>> ----------------------------------------
>>> Date: Sun, 17 Apr 2016 20:11:06 +0200
>>> From: Roger.Bivand at nhh.no
>>> To: baerroger at outlook.com
>>> CC: grass-stats at lists.osgeo.org
>>> Subject: RE: [R-sig-Geo] GISRC environment variable using initGRASS
>>>
>>> On Sat, 16 Apr 2016, Roger Bär wrote:
>>>
>>>> Thanks for the support!Please see below my comments.
>>>>
>>>>> Date: Fri, 15 Apr 2016 20:58:15 +0200
>>>>> From: Roger.Bivand at nhh.no
>>>>> To: baerroger at outlook.com
>>>>> CC: r-sig-geo at r-project.org
>>>>> Subject: Re: [R-sig-Geo] GISRC environment variable using initGRASS
>>>>>
>>>>> 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
>>>>
>>>> Yes. The absolute path to the file (containing settings for GISDBASE,
>>>> LOCATION_NAME and MAPSET)
>>>>
>>>>>> 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.
>>>>
>>>> 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)
>>>
>>> The name of the file is immaterial, but from an R script should only be
>>> accessed from the value of the environment variable.
>>>
>>
>> Ok.
>>
>>>>
>>>>>
>>>>>> 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.
>>>>
>>>> Sorry, I do not understand what you mean with "provide a use case where
>>>> this matters". What do you mean with "this"?
>>>
>>> The use of an arbitrary name in a throw-away location is of no
>>> significance, and could in the future be a short random name. My guess is
>>> that the use of "junk" may have come from different file permissions on
>>> unix and windows systems - if override is TRUE, R might end up trying to
>>> write to a file that some other process is still blocking.
>>>
>>
>> Ok.
>>
>>> Unless you can provide an R script that I can run in WinNat (not OSGeo4W -
>>> I do not have the time or patience to install multiple Windows versions of
>>> GRASS that I never use), and which demonstrates that something more is
>>> involved than the name of a temporary file, I can't help, because I do not
>>> see any real problem - the name if the file is arbitrary, and in the R
>>> session is accesses by Sys.getenv().
>>
>> Ok, I get that. The main issue was to keept the directory clean since
>> access my grass data from different operating system. But thinks it's
>> not worth to spend more time on this issue. (I'll survive the junk file
>> in my workspace)
>
> Would it help to try to add an argument to initGRASS() to try to delete
> the file pointed at by GISRC on exit from the R session?
>
> In many cases, the file is in R's temporary directory (home=tempdir()), so
> gets removed automatically, but if you are using a non-temporary home=,
> the file stays there.
>
> Roger (Bi)
Yes, that would solve my issue indeed.
Because I am using initGRASS mostly in a permanent home with all my project data.
Roger (Bä)
>> Thanks you anyway!
>>
>>
>> Regards,
>> Roger (Bä)
>>
>>
>>
>>
>>>> I added the thread to the grass-stat list (and will remove r-sig from
>>>> the cc the next time).
>>>
>>> OK,
>>>
>>> Roger (Bi)
>>>
>>>> Roger
>>>>
>>>>>
>>>>> 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
>>>>
>>>
>>> --
>>> 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
>
> --
> 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 grass-stats
mailing list