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

execGRASS() and commands with no flags or parameters #20

Closed
florisvdh opened this issue Jan 4, 2021 · 7 comments
Closed

execGRASS() and commands with no flags or parameters #20

florisvdh opened this issue Jan 4, 2021 · 7 comments

Comments

@florisvdh
Copy link
Collaborator

florisvdh commented Jan 4, 2021

Should GRASS commands be allowed to lack flags and parameters?

  • For g.gisenv, which works in the shell without flags or parameters, gmeta() is a fine R alternative of course.
  • For the case of g.gui, when allowing it through execGRASS(), one could go as far as allowing the launch of the GRASS GUI from R to explore the GRASS datasets on a map. This works well in Linux (with system()) provided that the GRASS_PYTHON variable is set (see also linkGRASS(): suggestion to let 'g.gui' work r-spatial/link2GI#24).
  • Maybe there are more such commands.
library(rgrass7)
#> Loading required package: XML
#> GRASS GIS interface loaded with GRASS version: (GRASS not running)
link2GI::findGRASS()
#>            instDir version installation_type
#> 1 /usr/lib/grass78   7.8.4           grass78
initGRASS(gisBase = link2GI::findGRASS()[1, "instDir"], 
          home = tempdir())
#> gisdbase    /tmp/RtmphWUEYc 
#> location    file590233fbc48 
#> mapset      file590227880b9d 
#> rows        1 
#> columns     1 
#> north       1 
#> south       0 
#> west        0 
#> east        1 
#> nsres       1 
#> ewres       1 
#> projection:
#>  XY location (unprojected)
stringexecGRASS("g.gisenv")
#> Error in doGRASS(cmd, flags = flags, ..., parameters = parameters, echoCmd = echoCmd, : No flags or parameters provided
execGRASS("g.gisenv")
#> Error in doGRASS(cmd, flags = flags, ..., parameters = parameters, echoCmd = echoCmd, : No flags or parameters provided
gmeta()
#> gisdbase    /tmp/RtmphWUEYc 
#> location    file590233fbc48 
#> mapset      file590227880b9d 
#> rows        1 
#> columns     1 
#> north       1 
#> south       0 
#> west        0 
#> east        1 
#> nsres       1 
#> ewres       1 
#> projection:
#>  XY location (unprojected)
system("g.gisenv")

standard output and standard error

GISDBASE='/tmp/RtmphWUEYc';
LOCATION_NAME='file590233fbc48';
MAPSET='file590227880b9d';
GRASS_GUI='text';

Created on 2021-01-04 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-04                  
#> 
#> ─ 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-04 [1] local                             
#>  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
@rsbivand
Copy link
Owner

rsbivand commented Jan 4, 2021

Letting no required parameter or flag commands run is feasible (I can check in parseGRASS() and record the state). I'm not at all sure that g.gui is a good idea, but have struggled to get d.mon to behave. It may be the PYTHON environment variable, I don't know. g.gui just works if you start R in a GRASS LOCATION.

@rsbivand
Copy link
Owner

rsbivand commented Jan 4, 2021

In fact, the first case is controlled by get.stop_on_no_flags_parasOption() and set.stop_on_no_flags_parasOption(), where the option is TRUE by default. So

set.stop_on_no_flags_parasOption(FALSE)
suppressWarnings(execGRASS("g.gisenv"))

works. Is this enough?

@florisvdh
Copy link
Collaborator Author

Thanks for pointing at the option, I was not aware of that. Does execGRASS() check for the presence of all required flags and parameters? (At least I see it happen for parameters in the source code of doGRASS().) In that case, the option may be unneeded, or a default FALSE may be sensible as well.

@rsbivand
Copy link
Owner

rsbivand commented Jan 5, 2021

If required parameters are missing or if they are of the wrong storage mode, doGRASS() should stop the operation being called. The default TRUE and the warning if FALSE and no flags or parameters was decided to support script authors. These are not meant for simple interactive use of GRASS, as GRASS has its own interactive interface. The aim has been to support using R to script GRASS, which isn't very convenient in the GRASS GUI, and where R is more flexible than shell scripts.

@florisvdh
Copy link
Collaborator Author

OK then that's clear @rsbivand. The fact that it can be tweaked with the option is certainly a good approach for the usecase I had in mind. Hence, will close this.

@rsbivand
Copy link
Owner

rsbivand commented Jan 5, 2021

I'll re-open and try to do the same as GRASS does to set GRASS_PYTHON, and then maybe only special-case "g.gui" with no parameters.

@rsbivand rsbivand reopened this Jan 5, 2021
@rsbivand
Copy link
Owner

rsbivand commented Jan 5, 2021

The current initGRASS() sets GRASS_PYTHON and PYTHONPATH probably wrongly, so this question needs resolving. I'll open a new issue and close here.

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

2 participants