rsbivand / rgrass

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

Get path to GRASS GIS installation from an executable #71

Closed wenzeslaus closed 1 year ago

wenzeslaus commented 2 years ago

Asking user to provide path to executable seems to me more doable than asking for path to installation. On Windows, it will be something like C:/Program Files/GRASS GIS 8.2/grass82.bat, but on Linux, it will likely be simply grass (possibly a good default value?).

This is what I used myself:

#' Get path to GRASS GIS installation
#'
#' Asks GRASS GIS where is its installation directory on the system.
#'
#' @param grassExecutable GRASS GIS executable (full path or command)
#' @return Path to the installation
getGRASSpath <- function (grassExecutable) {
  command <- paste("\"", grassExecutable, "\" --config path", sep = "")
  path <- system(command, intern = TRUE)
  return(trimws(path))
}

# ...

initGRASS(gisBase = getGRASSpath(grassExecutable),
          # ...
)

The executable can be then used to provide the install path like I did above or it can be used to provide whatever else is needed.

florisvdh commented 2 years ago

Something like this is already implemented for the Linux case with grass in the PATH, as a fall-back, see #64, #63 and f6c6a38.

A wider implementation to get this path for typical (automated) installations, cross-platform, should be available in the link2GI package.

Considering the GRASS_INSTALLATION environment variable, @rsbivand: it is documented (in Rd and in NEWS) as being used if available, but actually what @Robinlovelace implemented in f6c6a38 is only the grass --config path fallback in case the variable is not available. Do I overlook something? Still missing IMO: if GRASS_INSTALLATION is set to a value and is.missing(gisBase): set gisBase to this value (perhaps with a message), still followed by the checks on the value of gisBase (does it exist etc).