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

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

Open
florisvdh opened this issue Oct 24, 2019 · 5 comments
Open

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

florisvdh opened this issue Oct 24, 2019 · 5 comments

Comments

@florisvdh
Copy link
Member

florisvdh commented Oct 24, 2019

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
Copy link
Member

gisma commented Oct 24, 2019

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
Copy link
Member

gisma commented Oct 26, 2019

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
Copy link
Member Author

florisvdh commented May 14, 2020

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
Copy link
Member Author

florisvdh commented Aug 18, 2020

Because of recent changes in reticulate (see rstudio/reticulate#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 😄

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
Copy link
Member

gisma commented Nov 7, 2020

uuh great thanks for this findings...

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