4

I'm not very sure if we can still connect GRASS with R. I was trying with my GRASS 7.8 and R 3.6.2 in both directions suggested in R statistics wiki.

I have installed and loaded rgrass7, but have difficulty running functions. Here is an example of my setting the GRASS environment:

initGRASS(gisBase = "C:/Program Files/GRASS GIS 7.8",
          home = getwd(), 
          override = TRUE)
Error : XML content does not seem to be XML: ''
In addition: Warning message:
In system(cmd0, intern = TRUE) :
  running command 'g.proj.exe --interface-description' had status 5
Error in parseGRASS(cmd, legacyExec = legacyExec) : g.proj not parsed

I have the same problem starting R in GRASS either. I can type in rstudio in the GRASS command line to initiate R, but when I was trying to run any functions (e.g. execGRASS), I got the exact same error information.

Has anyone had the same problem before? I'm not sure what the error message means.

2

2 Answers 2

2

For those who stumble upon this, I found a solution that works for me. It appears that some combination of of installing via OSGeo and calling this from RStudio has left important environment variables incorrectly set.

To fix, see https://gist.github.com/obrl-soil/d74f58b137970364458ad41270a1c8f9. You can just source the file from your R code, which will fix up your environment variables, and then everything worked for me.

1

It seems that you need to set the required GRASS GIS related environmental variables (the OSGeo4W shell would do that for you) for your use case.

Find them here:https://github.com/OSGeo/grass/blob/master/mswindows/env.bat

Note that %GISBASE% needs to point to your local installation path.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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