3

I am using the rgrass7 package in R in order to work with GRASS GIS. After having set the needed enviornment variables, I can now launch a GRASS session from R and and work on my GRASS data using RStudio.

I would like to work with the GRASS GUI and the rgrass7 interface the same way as when I start R (RStudio) from the GRASS terminal (Using RStudio in a GRASS GIS session). The only difference is that I would like to work mainly in RStudio and only open the GRASS GUI only when needed.

Is it possible to launch the GRASS GUI from R within a running GRASS session?

When I try the sollowing command, the GUI does not open and I get a warning message:

> execGRASS("g.gui", ui="wxpython")
Warning message:
running command 'g.gui.exe ui=wxpython' had status 5 
3

Yes, it is possible to launch the GRASS GUI from R within a running GRASS session.

It did not work because the environment variables where not correctly set. Modifiying the environment variables as follows solved the problem:

# Set PYTHONPATH
Sys.setenv(PYTHONPATH = paste0("C:\\OSGEO4~1\\apps\\grass\\grass-7.0.3\\etc\\python;C:\\OSGEO4~1\\apps\\grass\\grass-7.0.3\\gui\\wxpython"))

# Set PYTHONHOME
Sys.setenv(PYTHONHOME = "C:\\OSGEO4~1\\apps\\Python27")

# Set PATHS for case of OSGEO4W
newPath <- "C:\\OSGEO4~1\\bin"
Sys.setenv("PATH" = paste(newPath, Sys.getenv("PATH"), sep=.Platform$path.sep))
newPath <- "C:\\OSGEO4~1\\apps\\grass\\grass-7.0.3\\lib"
Sys.setenv("PATH" = paste(newPath, Sys.getenv("PATH"), sep=.Platform$path.sep))
newPath <- "C:\\OSGEO4~1\\apps\\grass\\grass-7.0.3\\bin"
Sys.setenv("PATH" = paste(newPath, Sys.getenv("PATH"), sep=.Platform$path.sep))
newPath <- "C:\\OSGEO4~1\\apps\\Python27\\Scripts"
Sys.setenv("PATH" = paste(newPath, Sys.getenv("PATH"), sep=.Platform$path.sep))

# Set GISBASE
  # (directory where GRASS lives)
Sys.setenv(GISBASE = "C:\\OSGEO4~1\\apps\\grass\\grass-7.0.3")

# Set GRASS_PYTHON
  # (To override Python executable)
Sys.setenv(GRASS_PYTHON = "C:\\OSGEO4~1\\bin\\python.exe")

Although, not all the variable setting might have been directly related to solving the problem.

But now, the GUI can be lauchned by simply calling:

execGRASS("g.gui", ui="wxpython")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.