Run GRASS interface in an R session not started within GRASS. In general, most users will use initGRASS in throwaway locations, to use GRASS modules on R objects without the need to define and populate a location. The function initializes environment variables used by GRASS, the .gisrc used by GRASS for further environment variables, and a temporary location.
The locking functions are used internally, but are exposed for experienced R/GRASS scripters needing to use the GRASS module “g.mapset” through initGRASS in an existing GRASS location. In particular, “g.mapset” may leave a .gislock file in the current MAPSET, so it may be important to call unlink_.gislock to clean up before quitting the R session. remove_GISRC may be used to try to remove the file given in the “GISRC” environment variable if created by initGRASS with argument remove_GISRC= TRUE.
initGRASS(gisBase, home, SG, gisDbase, addon_base, location, mapset,
override = FALSE, use_g.dirseps.exe = TRUE, pid, remove_GISRC=FALSE)
get.GIS_LOCK()
set.GIS_LOCK(pid)
unset.GIS_LOCK()
unlink_.gislock()
remove_GISRC()The directory path to GRASS binaries and libraries, containing bin and lib subdirectories among others
The directory in which to create the .gisrc file; defaults to $HOME on Unix systems and to USERPROFILE on Windows systems; can usually be set to tempdir()
An optional SpatialGrid object to define the DEFAULT_WIND of the temporary location
if missing, tempdir() will be used; GRASS GISDBASE directory for the working session
if missing, assumed to be “$HOME/.grass7/addons” on Unix-like platforms, on MS Windows “%APPDATA%\GRASS7\addons”, and checked for existence
if missing, basename(tempfile()) will be used; GRASS location directory for the working session
if missing, basename(tempfile()) will be used; GRASS mapset directory for the working session
default FALSE, set to TRUE if accidental trashing of GRASS .gisrc files and locations is not a problem
default TRUE; when TRUE appears to work for WinGRASS Native binaries, when FALSE for QGIS GRASS binaries; ignored on other platforms.
default as.integer(round(runif(1, 1, 1000))), integer used to identify GIS_LOCK; the value here is arbitrary, but probably should be set correctly
default FALSE; if TRUE, attempt to unlink the temporary file named in the “GISRC” environment variable when the R session terminates or when this package is unloaded
The function runs gmeta6 before returning the current values of the running GRASS session that it provides.
The function establishes an out-of-GRASS working environment providing GRASS commands with the environment variable support required, and may also provide a temporary location for use until the end of the running R session if the home argument is set to tempdir(), and the gisDbase argument is not given. Running gmeta6 shows where the location is, should it be desired to archive it before leaving R.
# NOT RUN {
initGRASS("/usr/bin/grass-7.0.0", home=tempdir())
initGRASS("C:/GRASS", home=tempdir())
# }
Run the code above in your browser using DataLab