Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initGRASS() PYTHON handling is not as current GRASS 7.8 #21

Closed
rsbivand opened this issue Jan 5, 2021 · 15 comments
Closed

initGRASS() PYTHON handling is not as current GRASS 7.8 #21

rsbivand opened this issue Jan 5, 2021 · 15 comments

Comments

@rsbivand
Copy link
Owner

rsbivand commented Jan 5, 2021

initGRASS() makes outdated assumptions about PYTHON handling. It sets GRASS_PYTHON and PYTHONPATH in an outdated way. (Continued from #20).

rsbivand added a commit that referenced this issue Jan 5, 2021
@rsbivand
Copy link
Owner Author

rsbivand commented Jan 5, 2021

@florisvdh Here is a Windows binary built locally, and tested on Windows 10 for an almost current WinGRASS and a bit older OSGeo4W. On Linux and both Windows variants, the python handling seems improved. I'm unsure what will happen for GRASS < 7.8, which used python2 not python3. If your collaborators have access, please try, also with execGRASS("g.gui").

rgrass7_0.2-4.zip

@florisvdh
Copy link
Collaborator

Thanks for the work @rsbivand. Starting to test in Linux, a bug appears in initGRASS():

library(rgrass7)
#> Loading required package: XML
#> GRASS GIS interface loaded with GRASS version: (GRASS not running)
gisbase_grass <- 
    if (.Platform$OS.type == "windows") link2GI::paramGRASSw()$gisbase_GRASS[1] else {
      link2GI::paramGRASSx()$gisbase_GRASS[1]
    }
gisbase_grass
#> [1] "/usr/lib/grass78"
list.files(gisbase_grass)
#>  [1] "AUTHORS"                "bin"                    "CITING"                
#>  [4] "contributors_extra.csv" "contributors.csv"       "COPYING"               
#>  [7] "demolocation"           "docs"                   "driver"                
#> [10] "etc"                    "fonts"                  "GPL.TXT"               
#> [13] "gui"                    "lib"                    "locale"                
#> [16] "scripts"                "translators.csv.gz"
initGRASS(gisBase = gisbase_grass, 
          home = tempdir())
#> Error in nchar(OSGEO4W_ROOT): object 'OSGEO4W_ROOT' not found

Created on 2021-01-06 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Linux Mint 20               
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language nl_BE:nl                    
#>  collate  nl_BE.UTF-8                 
#>  ctype    nl_BE.UTF-8                 
#>  tz       Europe/Brussels             
#>  date     2021-01-06                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version  date       lib source                            
#>  assertthat    0.2.1    2019-03-21 [1] CRAN (R 4.0.2)                    
#>  callr         3.5.1    2020-10-13 [1] CRAN (R 4.0.3)                    
#>  class         7.3-17   2020-04-26 [4] CRAN (R 4.0.0)                    
#>  classInt      0.4-3    2020-04-07 [1] CRAN (R 4.0.2)                    
#>  cli           2.2.0    2020-11-20 [1] CRAN (R 4.0.3)                    
#>  crayon        1.3.4    2017-09-16 [1] CRAN (R 4.0.2)                    
#>  DBI           1.1.0    2019-12-15 [1] CRAN (R 4.0.2)                    
#>  desc          1.2.0    2018-05-01 [1] CRAN (R 4.0.2)                    
#>  devtools      2.3.2    2020-09-18 [1] CRAN (R 4.0.2)                    
#>  digest        0.6.27   2020-10-24 [1] CRAN (R 4.0.3)                    
#>  dplyr         1.0.2    2020-08-18 [1] CRAN (R 4.0.2)                    
#>  e1071         1.7-4    2020-10-14 [1] CRAN (R 4.0.3)                    
#>  ellipsis      0.3.1    2020-05-15 [1] CRAN (R 4.0.2)                    
#>  evaluate      0.14     2019-05-28 [1] CRAN (R 4.0.2)                    
#>  fansi         0.4.1    2020-01-08 [1] CRAN (R 4.0.2)                    
#>  fs            1.5.0    2020-07-31 [1] CRAN (R 4.0.2)                    
#>  generics      0.1.0    2020-10-31 [1] CRAN (R 4.0.3)                    
#>  glue          1.4.2    2020-08-27 [1] CRAN (R 4.0.2)                    
#>  highr         0.8      2019-03-20 [1] CRAN (R 4.0.2)                    
#>  htmltools     0.5.0    2020-06-16 [1] CRAN (R 4.0.2)                    
#>  KernSmooth    2.23-18  2020-10-29 [4] CRAN (R 4.0.3)                    
#>  knitr         1.30     2020-09-22 [1] CRAN (R 4.0.2)                    
#>  lifecycle     0.2.0    2020-03-06 [1] CRAN (R 4.0.2)                    
#>  link2GI       0.4-5    2020-12-10 [1] Github (r-spatial/link2GI@395124a)
#>  magrittr      2.0.1    2020-11-17 [1] CRAN (R 4.0.3)                    
#>  memoise       1.1.0    2017-04-21 [1] CRAN (R 4.0.2)                    
#>  pillar        1.4.7    2020-11-20 [1] CRAN (R 4.0.3)                    
#>  pkgbuild      1.1.0    2020-07-13 [1] CRAN (R 4.0.2)                    
#>  pkgconfig     2.0.3    2019-09-22 [1] CRAN (R 4.0.2)                    
#>  pkgload       1.1.0    2020-05-29 [1] CRAN (R 4.0.2)                    
#>  prettyunits   1.1.1    2020-01-24 [1] CRAN (R 4.0.2)                    
#>  processx      3.4.5    2020-11-30 [1] CRAN (R 4.0.3)                    
#>  ps            1.5.0    2020-12-05 [1] CRAN (R 4.0.3)                    
#>  purrr         0.3.4    2020-04-17 [1] CRAN (R 4.0.2)                    
#>  R6            2.5.0    2020-10-28 [1] CRAN (R 4.0.3)                    
#>  Rcpp          1.0.5    2020-07-06 [1] CRAN (R 4.0.2)                    
#>  remotes       2.2.0    2020-07-21 [1] CRAN (R 4.0.2)                    
#>  rgrass7     * 0.2-4    2021-01-06 [1] Github (rsbivand/rgrass7@9ac72ef) 
#>  rlang         0.4.9    2020-11-26 [1] CRAN (R 4.0.3)                    
#>  rmarkdown     2.5      2020-10-21 [1] CRAN (R 4.0.3)                    
#>  roxygen2      7.1.1    2020-06-27 [1] CRAN (R 4.0.2)                    
#>  rprojroot     2.0.2    2020-11-15 [1] CRAN (R 4.0.3)                    
#>  sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 4.0.2)                    
#>  sf            0.9-6    2020-09-13 [1] CRAN (R 4.0.3)                    
#>  stringi       1.5.3    2020-09-09 [1] CRAN (R 4.0.2)                    
#>  stringr       1.4.0    2019-02-10 [1] CRAN (R 4.0.2)                    
#>  testthat      3.0.0    2020-10-31 [1] CRAN (R 4.0.3)                    
#>  tibble        3.0.4    2020-10-12 [1] CRAN (R 4.0.3)                    
#>  tidyselect    1.1.0    2020-05-11 [1] CRAN (R 4.0.2)                    
#>  units         0.6-7    2020-06-13 [1] CRAN (R 4.0.2)                    
#>  usethis       1.6.3    2020-09-17 [1] CRAN (R 4.0.2)                    
#>  vctrs         0.3.5    2020-11-17 [1] CRAN (R 4.0.3)                    
#>  withr         2.3.0    2020-09-22 [1] CRAN (R 4.0.2)                    
#>  xfun          0.19     2020-10-30 [1] CRAN (R 4.0.3)                    
#>  XML         * 3.99-0.5 2020-07-23 [1] CRAN (R 4.0.2)                    
#>  xml2          1.3.2    2020-04-23 [1] CRAN (R 4.0.2)                    
#>  yaml          2.2.1    2020-02-01 [1] CRAN (R 4.0.2)                    
#> 
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

While debugging, it seems to happens because the OSGEO4W_ROOT object does not exist in Linux, when running line 230:

https://github.com/rsbivand/rgrass7/blob/9ac72ef7fbc669266cd16745253a0f8deaa2b9b9/R/initGRASS.R#L228-L230

@florisvdh
Copy link
Collaborator

BTW no need to provide the Windows binary build; remotes::install_github("rsbivand/rgrass7") will work OK for testing in Windows.

@rsbivand
Copy link
Owner Author

rsbivand commented Jan 6, 2021

OK, thanks, I was looking at the WinGRASS/OSGeo4W contrast. And I do not trust remotes, i always use R CMD INSTALL --build which IIUC remotes does not do, and most Windows users do not have RTools.

@florisvdh
Copy link
Collaborator

OK, thanks for the hints.

rsbivand added a commit that referenced this issue Jan 6, 2021
@florisvdh
Copy link
Collaborator

Intrigued by your comment on remotes, I had a quick look. (I'm writing it down for later reference) It seems (but that should be verified) that it essentially tries a R CMD INSTALL through processx(), run by callr::rcmd_safe() in a separate R process, which itself is called by pkgbuild::build() through pkgbuild::rcmd_build_tools(). remotes seems to prefer the latter, and if not, remotes uses callr::rcmd() directly. However, that is a very superficial analysis from looking through R code at GitHub - a lot is happening along the way to adjust settings (and hence the outcome is not clear from the code at first sight). So it would need a debug cycle to actually verify the command that is sent.

Certainly, it takes a long way compared to directly calling R CMD, which gives you direct control over what is happening.

@florisvdh
Copy link
Collaborator

florisvdh commented Jan 6, 2021

Have tested this in Windows 7, with OSGeo4W GRASS and R 4.0.3. Launching GRASS GUI independently (from the start menu, i.e. with the installed batch file) works. No success from RStudio within OSGeo4W shell:

> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
> list.files(gisbase_grass)
 [1] "AUTHORS"                 "bin"                     "CHANGES"                
 [4] "CITING"                  "config.status"           "contributors.csv"       
 [7] "contributors_extra.csv"  "COPYING"                 "demolocation"           
[10] "docs"                    "driver"                  "etc"                    
[13] "fonts"                   "GPL.TXT"                 "gui"                    
[16] "include"                 "INSTALL"                 "lib"                    
[19] "locale"                  "REQUIREMENTS.html"       "scripts"                
[22] "share"                   "tools"                   "translation_status.json"
[25] "translators.csv"        
> initGRASS(gisBase = gisbase_grass, 
+           home = tempdir())
gisdbase    C:/Users/FLORIS~1/AppData/Local/Temp/RtmpAbxW6V 
location    file21b42d9e3234 
mapset      file21b41ebb2163 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection:
 XY location (unprojected) 
> execGRASS("g.gui")
Traceback (most recent call last):
  File "C:/OSGeo4W64/apps/grass/grass78/gui/wxpython/wxgui.py", line 32, in <module>
    from core.utils import registerPid, unregisterPid
  File "C:\OSGeo4W64\apps\grass\grass78\gui\wxpython\core\utils.py", line 29, in <module>
    from core.gcmd import RunCommand
  File "C:\OSGeo4W64\apps\grass\grass78\gui\wxpython\core\gcmd.py", line 43, in <module>
    from win32file import ReadFile, WriteFile
ImportError: DLL load failed: Kan opgegeven module niet vinden.
Launching <wxpython> GUI in the background, please wait...
WX GUI lauched - Close GUI manually when finished

A message comes through that the GUI has launched, however it didn't. The above problems may have to do with other things than the PYTHON env variables though, possibly OSGeo4W-specific.

It's certainly not an essential thing to be able to run g.gui from R.

@ToonHub: you use more or less the same Windows setup (Win7+OSGeo4W GRASS). Can you run the above lines - do you get the same result? @hansvancalster: what happens in Win7 +WinGRASS (standalone)?

I can retest in Linux after the problem for Linux is fixed. Beside Mint 20 (Focal), I still have a partition with Mint 18 (Xenial) that has GRASS 7.6, so can try that too.

@florisvdh
Copy link
Collaborator

It should be added that official support for Windows 7 has stopped since nearly a year (unless one purchases extended security updates). So any issues that are Win7-only may not be worth the trouble.

Besides the same will be true for Ubuntu Xenial (16.04) in a matter of months. Ubuntu-based distros since Bionic (18.04) have easy access to precompiled GRASS 7.8 through the ubuntugis-unstable PPA, but Xenial only has 7.6 there.

@rsbivand
Copy link
Owner Author

rsbivand commented Jan 7, 2021

Since this didn't work before, it is not a regression for GRASS 7.6 users. Unless it can be shown to detract from pre-existing usability for 7.6, there is absolutely no need to do anything. Should I install GRASS 7.6 on Windows 10 to check for a regression, or is there no regression? 0.2-4 source is on CRAN now.

Part of the implicit bargain of FOSS is that users keep up with version updates, to be able to contribute useful reports aiding further development. FOSS may try to keep things that ran before running, but back-porting new functionality to EOL platforms really isn't a priority.

@rsbivand
Copy link
Owner Author

rsbivand commented Jan 7, 2021

For the Win7 OSGeo4W 7.8 example, please try with rgrass7 0.2-3 first, with the option to permit no flags or parameters, then with 0.2-4. If they are the same, there is no regression. Please also try starting RStudio in the OSGeo4W console, Rgui in the OSGeo4W console, and command line R in rge OSGeo4W console. I don't have Win7, so cannot replicate.

@florisvdh
Copy link
Collaborator

Thank you for the CRAN release 🎉 . (I missed that you already solved the initGRASS() problem for Linux)

Just re-tested the earlier code in Mint 20 (Focal), and it now works perfectly 👍. execGRASS("g.gui") runs nicely, thank you.

Will test this (and stringexecGRASS) for GRASS 7.6 in Linux (Xenial) and look at your 0.2-3/0.2-4 recommendations for Win7 OSGeo4W ASAP.

@hansvancalster
Copy link

I can confirm that - after updating to rgrass7 v0.2-4 - execGRASS("g-gui") also works on my system with Windows 7 and a stand-alone installation of GRASS. Nice to know that this is possible 👍

@florisvdh
Copy link
Collaborator

florisvdh commented Jan 7, 2021

Test results for execGRASS("g.gui") and stringexecGRASS() on Xenial with GRASS 7.6.1 below. Successful!

Results for older Linux environment (near EOL): Linux Mint 18 (~ Xenial 16.04) + GRASS 7.6.1 + R 3.6.3
library(rgrass7)
#> Loading required package: XML
#> GRASS GIS interface loaded with GRASS version: (GRASS not running)
link2GI::findGRASS("/usr/bin")
#>            instDir version installation_type
#> 1 /usr/lib/grass76   7.6.1           grass76
gisbase_grass <-
  if (.Platform$OS.type == "windows") link2GI::paramGRASSw()$gisbase_GRASS[1] else {
    link2GI::paramGRASSx(MP = "/usr/bin")$gisbase_GRASS[1]
  }
gisbase_grass
#> [1] "/usr/lib/grass76"
initGRASS(gisBase = gisbase_grass,
          home = tempdir(),
          mapset = "PERMANENT")
#> gisdbase    /tmp/RtmpPeoaHV 
#> location    file2fe04bf6591f 
#> mapset      PERMANENT 
#> rows        1 
#> columns     1 
#> north       1 
#> south       0 
#> west        0 
#> east        1 
#> nsres       1 
#> ewres       1 
#> projection:
#>  XY location (unprojected)
execGRASS("g.gui")
#> Warning in execGRASS("g.gui"): The command:
#> g.gui 
#> produced at least one warning during execution:
#> Launching <wxpython> GUI in the background, please wait...
#> WARNING: GRASS_ADDON_BASE is not defined, installing to ~/.grass7/addons
#> Launching <wxpython> GUI in the background, please wait...
#> WARNING: GRASS_ADDON_BASE is not defined, installing to ~/.grass7/addons
#> WX GUI launched - Close GUI manually when finished
stringexecGRASS("g.proj -w -f epsg=31370")
#> PROJCS["Belge 1972 / Belgian Lambert 72",GEOGCS["Belge 1972",DATUM["Reseau_National_Belge_1972",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-106.8686,52.2978,-103.7239,0.3366,-0.457,1.8422,-1.2747],AUTHORITY["EPSG","6313"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4313"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",51.16666723333333],PARAMETER["standard_parallel_2",49.8333339],PARAMETER["latitude_of_origin",90],PARAMETER["central_meridian",4.367486666666666],PARAMETER["false_easting",150000.013],PARAMETER["false_northing",5400088.438],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","31370"]]
stringexecGRASS("g.proj -c georef=/vsicurl/https://download.osgeo.org/geotiff/samples/made_up/bogota.tif")
#> Default region was updated to the new projection, but if you have multiple
#> mapsets `g.region -d` should be run in each to update the region from the
#> default
#> Projection information updated
stringexecGRASS("r.in.gdal input=/vsicurl/https://download.osgeo.org/geotiff/samples/made_up/bogota.tif output=bogota memory=2000")
#> Importing raster map <bogota>...
#>    0%�����   3%�����   6%�����   9%�����  12%�����  15%�����  18%�����  21%�����  24%�����  27%�����  30%�����  33%�����  36%�����  39%�����  42%�����  45%�����  48%�����  51%�����  54%�����  57%�����  60%�����  63%�����  66%�����  69%�����  72%�����  75%�����  78%�����  81%�����  84%�����  87%�����  90%�����  93%�����  96%�����  99%����� 100%�����
stringexecGRASS("g.region raster=bogota -p")
#> projection: 99 (Bogota 1975 / Colombia Bogota zone (deprecated))
#> zone:       0
#> datum:      towgs84=307,304,-318,0,0,0,0
#> ellipsoid:  international
#> north:      100000
#> south:      69280
#> west:       440720
#> east:       471440
#> nsres:      60
#> ewres:      60
#> rows:       512
#> cols:       512
#> cells:      262144

Created on 2021-01-07 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.3 (2020-02-29)
#>  os       Linux Mint 18.1             
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  nl_BE.UTF-8                 
#>  ctype    nl_BE.UTF-8                 
#>  tz       Europe/Brussels             
#>  date     2021-01-07                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version  date       lib source                            
#>  assertthat    0.2.1    2019-03-21 [1] CRAN (R 3.6.0)                    
#>  backports     1.1.8    2020-06-17 [1] CRAN (R 3.6.3)                    
#>  callr         3.4.3    2020-03-28 [1] CRAN (R 3.6.3)                    
#>  class         7.3-17   2020-04-26 [4] CRAN (R 3.6.3)                    
#>  classInt      0.4-3    2020-04-07 [1] CRAN (R 3.6.3)                    
#>  cli           2.0.2    2020-02-28 [1] CRAN (R 3.6.3)                    
#>  crayon        1.3.4    2017-09-16 [1] CRAN (R 3.6.0)                    
#>  DBI           1.1.0    2019-12-15 [1] CRAN (R 3.6.2)                    
#>  desc          1.2.0    2018-05-01 [1] CRAN (R 3.6.0)                    
#>  devtools      2.3.1    2020-07-21 [1] CRAN (R 3.6.3)                    
#>  digest        0.6.25   2020-02-23 [1] CRAN (R 3.6.3)                    
#>  dplyr         1.0.1    2020-07-31 [1] CRAN (R 3.6.3)                    
#>  e1071         1.7-3    2019-11-26 [1] CRAN (R 3.6.2)                    
#>  ellipsis      0.3.1    2020-05-15 [1] CRAN (R 3.6.3)                    
#>  evaluate      0.14     2019-05-28 [1] CRAN (R 3.6.1)                    
#>  fansi         0.4.1    2020-01-08 [1] CRAN (R 3.6.2)                    
#>  fs            1.5.0    2020-07-31 [1] CRAN (R 3.6.3)                    
#>  generics      0.0.2    2018-11-29 [1] CRAN (R 3.6.0)                    
#>  glue          1.4.1    2020-05-13 [1] CRAN (R 3.6.3)                    
#>  highr         0.8      2019-03-20 [1] CRAN (R 3.6.0)                    
#>  htmltools     0.5.0    2020-06-16 [1] CRAN (R 3.6.3)                    
#>  KernSmooth    2.23-17  2020-04-26 [4] CRAN (R 3.6.3)                    
#>  knitr         1.29     2020-06-23 [1] CRAN (R 3.6.3)                    
#>  lifecycle     0.2.0    2020-03-06 [1] CRAN (R 3.6.3)                    
#>  link2GI       0.4.3    2020-06-17 [1] Github (r-spatial/link2GI@df28d1c)
#>  magrittr      1.5      2014-11-22 [1] CRAN (R 3.6.0)                    
#>  memoise       1.1.0    2017-04-21 [1] CRAN (R 3.6.0)                    
#>  pillar        1.4.6    2020-07-10 [1] CRAN (R 3.6.3)                    
#>  pkgbuild      1.1.0    2020-07-13 [1] CRAN (R 3.6.3)                    
#>  pkgconfig     2.0.3    2019-09-22 [1] CRAN (R 3.6.1)                    
#>  pkgload       1.1.0    2020-05-29 [1] CRAN (R 3.6.3)                    
#>  prettyunits   1.1.1    2020-01-24 [1] CRAN (R 3.6.3)                    
#>  processx      3.4.3    2020-07-05 [1] CRAN (R 3.6.3)                    
#>  ps            1.3.3    2020-05-08 [1] CRAN (R 3.6.3)                    
#>  purrr         0.3.4    2020-04-17 [1] CRAN (R 3.6.3)                    
#>  R6            2.4.1    2019-11-12 [1] CRAN (R 3.6.2)                    
#>  Rcpp          1.0.5    2020-07-06 [1] CRAN (R 3.6.3)                    
#>  remotes       2.2.0    2020-07-21 [1] CRAN (R 3.6.3)                    
#>  reprex        0.3.0    2019-05-16 [1] CRAN (R 3.6.1)                    
#>  rgrass7     * 0.2-4    2021-01-07 [1] Github (rsbivand/rgrass7@a9d1b5d) 
#>  rlang         0.4.7    2020-07-09 [1] CRAN (R 3.6.3)                    
#>  rmarkdown     2.3      2020-06-18 [1] CRAN (R 3.6.3)                    
#>  roxygen2      7.1.1    2020-06-27 [1] CRAN (R 3.6.3)                    
#>  rprojroot     1.3-2    2018-01-03 [1] CRAN (R 3.6.0)                    
#>  sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 3.6.0)                    
#>  sf            0.9-5    2020-07-14 [1] CRAN (R 3.6.3)                    
#>  stringi       1.4.6    2020-02-17 [1] CRAN (R 3.6.3)                    
#>  stringr       1.4.0    2019-02-10 [1] CRAN (R 3.6.0)                    
#>  testthat      2.3.2    2020-03-02 [1] CRAN (R 3.6.3)                    
#>  tibble        3.0.3    2020-07-10 [1] CRAN (R 3.6.3)                    
#>  tidyselect    1.1.0    2020-05-11 [1] CRAN (R 3.6.3)                    
#>  units         0.6-7    2020-06-13 [1] CRAN (R 3.6.3)                    
#>  usethis       1.6.1    2020-04-29 [1] CRAN (R 3.6.3)                    
#>  vctrs         0.3.2    2020-07-15 [1] CRAN (R 3.6.3)                    
#>  withr         2.2.0    2020-04-20 [1] CRAN (R 3.6.3)                    
#>  xfun          0.16     2020-07-24 [1] CRAN (R 3.6.3)                    
#>  XML         * 3.99-0.3 2020-01-20 [1] CRAN (R 3.6.3)                    
#>  xml2          1.3.2    2020-04-23 [1] CRAN (R 3.6.3)                    
#>  yaml          2.2.1    2020-02-01 [1] CRAN (R 3.6.2)                    
#> 
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

Do note, there are some warnings from GRASS about the missing GRASS_ADDON_BASE environment variable. It appeared in Focal as well. However, it is no show-stopper!

Screenshot: the bogota sample raster in the GRASS map display

Schermafdruk van 2021-01-07 18-28-36

@florisvdh
Copy link
Collaborator

florisvdh commented Jan 7, 2021

Windows 7 + OSGeo4W GRASS 7.8 results for the Win7 installation on my (multiboot) PC. Due to history specifics of this Win7 installation (it is not new, although rarely used), results could still be different when run on another machine with a Win7/OSGeo4W setup (just a tiny chance I guess).

In this setup, execGRASS("g.gui") consistently does not launch the GRASS GUI, both for rgrass7 0.2-3 and 0.2-4, although the standard output/error differs between both package versions. Per package version, results are identical between R/Rgui/RStudio (RStudio also in interactive use, not shown here). All programs are started from within the OSGeo4W shell.

stringexecGRASS() also worked successfully in this setup (rgrass7 0.2-4).

GRASS GUI successfully launches on this system when started from its batch file (i.e. windows start menu).

Test script for rgrass7 0.2-3:

library(rgrass7)
invisible(set.stop_on_no_flags_parasOption(FALSE))
gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
initGRASS(gisBase = gisbase_grass, home = tempdir())
execGRASS("g.gui")

Test script for rgrass7 0.2-4:

library(rgrass7)
gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
initGRASS(gisBase = gisbase_grass, home = tempdir())
stringexecGRASS("g.proj -w -f epsg=4258", intern = TRUE)
execGRASS("g.gui")

Results for rgrass7 0.2-3 (CRAN)

Returned Dutch standard error means: 'The system cannot find the specified path'.

R-4.0.3\bin\x64\R.exe

image

R-4.0.3\bin\x64\Rgui.exe
> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> invisible(set.stop_on_no_flags_parasOption(FALSE))
> gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
> initGRASS(gisBase = gisbase_grass, home = tempdir())
gisdbase    C:/Users/FLORIS~1/AppData/Local/Temp/RtmpWatgrh 
location    file217c2995710d 
mapset      file217c15d2402a 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection:
 XY location (unprojected) 
Warning message:
In initGRASS(gisBase = gisbase_grass, home = tempdir()) :
  working directory not writable, using tempfile for GISRC
> execGRASS("g.gui")
Het systeem kan het opgegeven pad niet vinden.
Launching <wxpython> GUI in the background, please wait...
Warning message:
In doGRASS(cmd, flags = flags, ..., parameters = parameters, echoCmd = echoCmd,  :
  No flags or parameters provided
reprex::reprex(si=TRUE, std_out_err=TRUE) in RStudio 1.3.1093 + R 4.0.3
library(rgrass7)
#> Loading required package: XML
#> GRASS GIS interface loaded with GRASS version: (GRASS not running)
invisible(set.stop_on_no_flags_parasOption(FALSE))
gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
initGRASS(gisBase = gisbase_grass, home = tempdir())
#> gisdbase    C:/Users/FLORIS~1/AppData/Local/Temp/RtmpOIJ3ox 
#> location    file187853197b5d 
#> mapset      file1878430f1886 
#> rows        1 
#> columns     1 
#> north       1 
#> south       0 
#> west        0 
#> east        1 
#> nsres       1 
#> ewres       1 
#> projection:
#>  XY location (unprojected)
execGRASS("g.gui")
#> Warning in doGRASS(cmd, flags = flags, ..., parameters = parameters, echoCmd =
#> echoCmd, : No flags or parameters provided

standard output and standard error

Het systeem kan het opgegeven pad niet vinden.
Launching <wxpython> GUI in the background, please wait...

Created on 2021-01-07 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Windows 7 x64 SP 1          
#>  system   i386, mingw32               
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Dutch_Belgium.1252          
#>  ctype    Dutch_Belgium.1252          
#>  tz       Europe/Paris                
#>  date     2021-01-07                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version  date       lib source        
#>  assertthat    0.2.1    2019-03-21 [1] CRAN (R 4.0.3)
#>  callr         3.5.1    2020-10-13 [1] CRAN (R 4.0.3)
#>  cli           2.2.0    2020-11-20 [1] CRAN (R 4.0.3)
#>  crayon        1.3.4    2017-09-16 [1] CRAN (R 4.0.3)
#>  desc          1.2.0    2018-05-01 [1] CRAN (R 4.0.3)
#>  devtools      2.3.2    2020-09-18 [1] CRAN (R 4.0.3)
#>  digest        0.6.27   2020-10-24 [1] CRAN (R 4.0.3)
#>  ellipsis      0.3.1    2020-05-15 [1] CRAN (R 4.0.3)
#>  evaluate      0.14     2019-05-28 [1] CRAN (R 4.0.3)
#>  fansi         0.4.1    2020-01-08 [1] CRAN (R 4.0.3)
#>  fs            1.5.0    2020-07-31 [1] CRAN (R 4.0.3)
#>  glue          1.4.2    2020-08-27 [1] CRAN (R 4.0.3)
#>  highr         0.8      2019-03-20 [1] CRAN (R 4.0.3)
#>  htmltools     0.5.0    2020-06-16 [1] CRAN (R 4.0.3)
#>  knitr         1.30     2020-09-22 [1] CRAN (R 4.0.3)
#>  lifecycle     0.2.0    2020-03-06 [1] CRAN (R 4.0.3)
#>  magrittr      2.0.1    2020-11-17 [1] CRAN (R 4.0.3)
#>  memoise       1.1.0    2017-04-21 [1] CRAN (R 4.0.3)
#>  pkgbuild      1.2.0    2020-12-15 [1] CRAN (R 4.0.3)
#>  pkgload       1.1.0    2020-05-29 [1] CRAN (R 4.0.3)
#>  prettyunits   1.1.1    2020-01-24 [1] CRAN (R 4.0.3)
#>  processx      3.4.5    2020-11-30 [1] CRAN (R 4.0.3)
#>  ps            1.5.0    2020-12-05 [1] CRAN (R 4.0.3)
#>  purrr         0.3.4    2020-04-17 [1] CRAN (R 4.0.3)
#>  R6            2.5.0    2020-10-28 [1] CRAN (R 4.0.3)
#>  remotes       2.2.0    2020-07-21 [1] CRAN (R 4.0.3)
#>  rgrass7     * 0.2-3    2020-12-07 [1] CRAN (R 4.0.3)
#>  rlang         0.4.9    2020-11-26 [1] CRAN (R 4.0.3)
#>  rmarkdown     2.6      2020-12-14 [1] CRAN (R 4.0.3)
#>  rprojroot     2.0.2    2020-11-15 [1] CRAN (R 4.0.3)
#>  sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 4.0.3)
#>  stringi       1.5.3    2020-09-09 [1] CRAN (R 4.0.3)
#>  stringr       1.4.0    2019-02-10 [1] CRAN (R 4.0.3)
#>  testthat      3.0.1    2020-12-17 [1] CRAN (R 4.0.3)
#>  usethis       2.0.0    2020-12-10 [1] CRAN (R 4.0.3)
#>  withr         2.3.0    2020-09-22 [1] CRAN (R 4.0.3)
#>  xfun          0.19     2020-10-30 [1] CRAN (R 4.0.3)
#>  XML         * 3.99-0.5 2020-07-23 [1] CRAN (R 4.0.3)
#>  yaml          2.2.1    2020-02-01 [1] CRAN (R 4.0.3)
#> 
#> [1] C:/R/library
#> [2] C:/Program Files/R/R-4.0.3/library

Results for rgrass7 0.2-4 at 89a195a (on CRAN)

Returned (partially) Dutch standard error means: 'ImportError: DLL load failed: Cannot find specified module'.

R-4.0.3\bin\x64\R.exe

image

R-4.0.3\bin\x64\Rgui.exe
> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
> initGRASS(gisBase = gisbase_grass, home = tempdir())
gisdbase    C:/Users/FLORIS~1/AppData/Local/Temp/RtmpY54iRs 
location    file1ed079217642 
mapset      file1ed01dde1d73 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection:
 XY location (unprojected) 
Warning message:
In initGRASS(gisBase = gisbase_grass, home = tempdir()) :
  working directory not writable, using tempfile for GISRC
> stringexecGRASS("g.proj -w -f epsg=4258", intern = TRUE)
[1] "GEOGCS[\"ETRS89\",DATUM[\"European_Terrestrial_Reference_System_1989\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6258\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4258\"]]"
> execGRASS("g.gui")
Traceback (most recent call last):
  File "C:/OSGeo4W64/apps/grass/grass78/gui/wxpython/wxgui.py", line 32, in <module>
    from core.utils import registerPid, unregisterPid
  File "C:\OSGeo4W64\apps\grass\grass78\gui\wxpython\core\utils.py", line 29, in <module>
    from core.gcmd import RunCommand
  File "C:\OSGeo4W64\apps\grass\grass78\gui\wxpython\core\gcmd.py", line 43, in <module>
    from win32file import ReadFile, WriteFile
ImportError: DLL load failed: Kan opgegeven module niet vinden.
Launching <wxpython> GUI in the background, please wait...
WX GUI lauched - Close GUI manually when finished
reprex::reprex(si=TRUE, std_out_err=TRUE) in RStudio 1.3.1093 + R 4.0.3
library(rgrass7)
#> Loading required package: XML
#> GRASS GIS interface loaded with GRASS version: (GRASS not running)
gisbase_grass <- "C:/OSGeo4W64/apps/grass/grass78"
initGRASS(gisBase = gisbase_grass, home = tempdir())
#> gisdbase    C:/Users/FLORIS~1/AppData/Local/Temp/RtmpOUFsq9 
#> location    file259849227d27 
#> mapset      file25982aaf41fe 
#> rows        1 
#> columns     1 
#> north       1 
#> south       0 
#> west        0 
#> east        1 
#> nsres       1 
#> ewres       1 
#> projection:
#>  XY location (unprojected)
stringexecGRASS("g.proj -w -f epsg=4258", intern = TRUE)
#> [1] "GEOGCS[\"ETRS89\",DATUM[\"European_Terrestrial_Reference_System_1989\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6258\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4258\"]]"
execGRASS("g.gui")
#> WX GUI lauched - Close GUI manually when finished

standard output and standard error

Traceback (most recent call last):
  File "C:/OSGeo4W64/apps/grass/grass78/gui/wxpython/wxgui.py", line 32, in <module>
    from core.utils import registerPid, unregisterPid
  File "C:\OSGeo4W64\apps\grass\grass78\gui\wxpython\core\utils.py", line 29, in <module>
    from core.gcmd import RunCommand
  File "C:\OSGeo4W64\apps\grass\grass78\gui\wxpython\core\gcmd.py", line 43, in <module>
    from win32file import ReadFile, WriteFile
ImportError: DLL load failed: Kan opgegeven module niet vinden.
Launching <wxpython> GUI in the background, please wait...

Created on 2021-01-07 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Windows 7 x64 SP 1          
#>  system   i386, mingw32               
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Dutch_Belgium.1252          
#>  ctype    Dutch_Belgium.1252          
#>  tz       Europe/Paris                
#>  date     2021-01-07                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version  date       lib source                           
#>  assertthat    0.2.1    2019-03-21 [1] CRAN (R 4.0.3)                   
#>  callr         3.5.1    2020-10-13 [1] CRAN (R 4.0.3)                   
#>  cli           2.2.0    2020-11-20 [1] CRAN (R 4.0.3)                   
#>  crayon        1.3.4    2017-09-16 [1] CRAN (R 4.0.3)                   
#>  desc          1.2.0    2018-05-01 [1] CRAN (R 4.0.3)                   
#>  devtools      2.3.2    2020-09-18 [1] CRAN (R 4.0.3)                   
#>  digest        0.6.27   2020-10-24 [1] CRAN (R 4.0.3)                   
#>  ellipsis      0.3.1    2020-05-15 [1] CRAN (R 4.0.3)                   
#>  evaluate      0.14     2019-05-28 [1] CRAN (R 4.0.3)                   
#>  fansi         0.4.1    2020-01-08 [1] CRAN (R 4.0.3)                   
#>  fs            1.5.0    2020-07-31 [1] CRAN (R 4.0.3)                   
#>  glue          1.4.2    2020-08-27 [1] CRAN (R 4.0.3)                   
#>  highr         0.8      2019-03-20 [1] CRAN (R 4.0.3)                   
#>  htmltools     0.5.0    2020-06-16 [1] CRAN (R 4.0.3)                   
#>  knitr         1.30     2020-09-22 [1] CRAN (R 4.0.3)                   
#>  lifecycle     0.2.0    2020-03-06 [1] CRAN (R 4.0.3)                   
#>  magrittr      2.0.1    2020-11-17 [1] CRAN (R 4.0.3)                   
#>  memoise       1.1.0    2017-04-21 [1] CRAN (R 4.0.3)                   
#>  pkgbuild      1.2.0    2020-12-15 [1] CRAN (R 4.0.3)                   
#>  pkgload       1.1.0    2020-05-29 [1] CRAN (R 4.0.3)                   
#>  prettyunits   1.1.1    2020-01-24 [1] CRAN (R 4.0.3)                   
#>  processx      3.4.5    2020-11-30 [1] CRAN (R 4.0.3)                   
#>  ps            1.5.0    2020-12-05 [1] CRAN (R 4.0.3)                   
#>  purrr         0.3.4    2020-04-17 [1] CRAN (R 4.0.3)                   
#>  R6            2.5.0    2020-10-28 [1] CRAN (R 4.0.3)                   
#>  remotes       2.2.0    2020-07-21 [1] CRAN (R 4.0.3)                   
#>  rgrass7     * 0.2-4    2021-01-07 [1] Github (rsbivand/rgrass7@89a195a)
#>  rlang         0.4.9    2020-11-26 [1] CRAN (R 4.0.3)                   
#>  rmarkdown     2.6      2020-12-14 [1] CRAN (R 4.0.3)                   
#>  rprojroot     2.0.2    2020-11-15 [1] CRAN (R 4.0.3)                   
#>  sessioninfo   1.1.1    2018-11-05 [1] CRAN (R 4.0.3)                   
#>  stringi       1.5.3    2020-09-09 [1] CRAN (R 4.0.3)                   
#>  stringr       1.4.0    2019-02-10 [1] CRAN (R 4.0.3)                   
#>  testthat      3.0.1    2020-12-17 [1] CRAN (R 4.0.3)                   
#>  usethis       2.0.0    2020-12-10 [1] CRAN (R 4.0.3)                   
#>  withr         2.3.0    2020-09-22 [1] CRAN (R 4.0.3)                   
#>  xfun          0.19     2020-10-30 [1] CRAN (R 4.0.3)                   
#>  XML         * 3.99-0.5 2020-07-23 [1] CRAN (R 4.0.3)                   
#>  yaml          2.2.1    2020-02-01 [1] CRAN (R 4.0.3)                   
#> 
#> [1] C:/R/library
#> [2] C:/Program Files/R/R-4.0.3/library

Afterthought

I agree there is no need to pursue this further for Windows 7. It's good to know that it works on Windows 10, and it's a bonus that it works on Windows 7 with WinGRASS.

@rsbivand
Copy link
Owner Author

rsbivand commented Jan 8, 2021

OK, I'll close this now. I wonder whether OSGEO4W differs from OSGEO4W64.

@rsbivand rsbivand closed this as completed Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants