[GRASS-stats] Using Rcpp to interface GRASS from R and vice versa
wenzeslaus at gmail.com
Wed Jul 18 06:45:17 PDT 2012
I've tried the R packages Rcpp  and inline  to write a function
which returns values from a GRASS raster map using GRASS C functions.
In attached demo function returns only one value but more complex
objects can be returned too. There is also an option to pass C++
classes and R data frames.
In general Rcpp (+inline) can be used to write efficient C++ code and
use it in R. In case of GRASS and R it can be used to access large
raster datasets from R without the need to load everything to memory.
There is also another possibility. One can use Rcpp with RInside
package  and write C/C++ code which calls R internally. So GRASS
module which does some specific computations in R but handles memory
itself can be created. Note that RInside is R instance within C++
program, it can run any R code.
I'm sending a very simplified example how things are working. For
running it, you need latest R, Rcpp package and inline package .
Tested only on GNU/Linux (Ubuntu) but Rcpp should work even on MS
I'm interested (as an programmer) in this topic and I would like to
write something which uses these possibilities. I'm not experienced
with R so I'm not sure which way to go. So there are several
* Would it be useful to have something like R raster package  but
with GRASS raster maps as data format (direct access to GRASS maps
from R within GRASS session)?
* Should some GRASS modules or even wxGUI provide some R functionality?
* Not sure, but I think that something like R-based raster calculator
can be also created. Would be this helpful?
* Why are Rcpp and inline not used in spgrass6 ? Is there some
other reason than Rcpp is relatively new so it may be considered as
* Would it be more useful to bring some functionality from GRASS to R
or in the opposite way, trying to use Rcpp within spgrass6 (or
spgrass7) or just to have some general tools or just to create a guide
how to combine things?
Comments and suggestions are welcome.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1353 bytes
Desc: not available
More information about the grass-stats