r-spatial / link2GI

Simplify the linking of GIS/RS and CLI tools
https://r-spatial.github.io/link2GI
GNU General Public License v3.0
25 stars 7 forks source link

linkGRASS(): suggestion to let 'g.gui' work #24

Open florisvdh opened 5 years ago

florisvdh commented 5 years ago

FYI, and perhaps you can use the idea. Some time ago (using the CRAN version) I noticed that g.gui did not work from R, using system() or execGRASS(). At least in Linux (Mint) it seems that this can be solved by setting an environment variable GRASS_PYTHON:

if (.Platform$OS.type == "unix") {
  Sys.setenv(GRASS_PYTHON = reticulate::py_discover_config() %>% 
                          as.character() %>% 
                          .[1])
}

Maybe you can manage to set this with link2GI, cross-platform? Being able to open the GUI from R seems an interesting feature; it comes in handy to do some quick inspections.

EDIT: the above code won't run anymore as intended, when using recent reticulate. See below for an update.

gisma commented 5 years ago

Pretty cool idea. I'd never think about that way around probably because I'm not really native to the r community so I always start GRASS or SAGA outside of R or rstudio. I will check it under Windows and I will also look how the Linux flavours deal with it. It maybe take some time because the lectures are running....

gisma commented 5 years ago

Well I spent quite a bit of effort to get it working under Arch and Mint are not willing to do the job. At least Mint as it is based on Ubuntu should do it. I am running in a cascade of malfunctions and error messages. So for the first I will pause this. Seems to be a job for the time between Christmas and new year...

florisvdh commented 4 years ago

An extension to this idea is launching the GRASS-terminal in Linux right from R (below it is the gnome-terminal, but it could be extended).

mapset_path <- 
  system("g.gisenv get=GISDBASE,LOCATION_NAME,MAPSET sep='/'", 
         intern = TRUE)
system(paste0("gnome-terminal --working-directory=",
              mapset_path,
              " -- grass --text .")
)
florisvdh commented 4 years ago

Because of recent changes in reticulate (see https://github.com/rstudio/reticulate/issues/754) which make it hard to return the system python executable, my current approach to prepare for launching the GUI (with g.gui) is (for GRASS 7.8 in Ubuntu 20.04, by which I actually mean Linux Mint 20):

if (.Platform$OS.type == "unix") {
  Sys.setenv(GRASS_PYTHON = system("which python3", intern = TRUE))
}

And yet again, it works :smile:

Note however that some Ubuntu version dependency may be at stake for this code. I believe that which python would have worked in Ubuntu 16.04, for example. In 20.04, only python2 and python3 are on the PATH. Plus, I don't know for sure whether python3 is the right choice in GRASS 7.6 (Ubuntu 16.04).

gisma commented 3 years ago

uuh great thanks for this findings...