In R you can use system calls or the spgrass6 package to run GRASS GIS functions. To do this, you need to run R from within GRASS GIS. This is as simple as starting GRASS GIS and subsequently starting R from the command line. See the GRASS-wiki for a more detailed background.
The issue at hand
One of the user-cases is when you want to (1) run a GRASS function on e.g., a raster layer and (2) capture the console output in a R data frame. For example, you can run the following in R:
MyVariables <- execGRASS("r.stats", flags="c", input="MyMap", separator=",", intern=TRUE)
However, the output is not in a very convenient format. Continue reading “Import GRASS function console output as data.frame in R”