rsbivand / rgrass

Interpreted interface between the GRASS geographical information system and R
https://rsbivand.github.io/rgrass/
24 stars 8 forks source link

initGRASS error for GRASS 8.3.1 mac ARM #85

Closed wxyang007 closed 4 months ago

wxyang007 commented 4 months ago

Dear staff,

I have encountered the following issue when trying to initialize GRASS from RStudio.

R version 4.2.2 Mac OS Sonoma Version 14.3.1 (M1 chip) GRASS 8.3.1

library(rgrass)
library(terra)

gisBase <- "/Applications/GRASS-8.3.app/Contents/Resources"

x <- rast()
initGRASS(gisBase = gisBase,
          home=tempdir(),
          SG=x,
          override=TRUE)

Error messages:

sh: g.gisenv: command not found sh: g.gisenv: command not found sh: g.gisenv: command not found sh: g.gisenv: command not found sh: g.gisenv: command not found sh: g.version: command not found Error in system(paste("g.version", get("addEXE", envir = .GRASS_CACHE), : error in running command In addition: Warning messages: 1: In system(paste(paste("g.gisenv", get("addEXE", envir = .GRASS_CACHE), : error in running command 2: In system(paste(paste("g.gisenv", get("addEXE", envir = .GRASS_CACHE), : error in running command 3: In system(paste(paste("g.gisenv", get("addEXE", envir = .GRASS_CACHE), : error in running command 4: In system(paste(paste("g.gisenv", get("addEXE", envir = .GRASS_CACHE), : error in running command 5: In system(paste(paste("g.gisenv", get("addEXE", envir = .GRASS_CACHE), : error in running command

I was able to run the same script successfully through the GRASS command line but not from RStudio. I found people having a similar issue here.

Any help/hint would be appreciated! Many thanks!

rsbivand commented 4 months ago

There are no staff here, only a retired professor.

From https://cran.r-project.org/web/packages/rgrass/vignettes/use.html you will see that rstudio has to be started from the GRASS console, This means that trying to instantiate a temporary GRASS location has never worked in conjunction with rstudio. It does work running R in a terminal, and in the R.app (equivalently Rgui.exeon Windows). Running this Quarto document in VScode works: rgrass_code.zip. but running the same file in rstudio fails (all on macOS, latest GRASS, VScode, Rstudio, R, etc.) This is an issue for Posit, not this package, they take over paths to executables but do not document how they do it.

Please update the stackexchange thread - this is known never to have worked. Also ask stackexchange users to use https://lists.osgeo.org/mailman/listinfo/grass-stats as the most direct route to accurate information.

wxyang007 commented 4 months ago

Dear Dr. Bivand,

Thank you so much for the fast response! The solution (opening Rstudio from GRASS) worked perfectly. I will update it in the stackexchange thread and also share the link osgeo link. Many thanks!