.Call
interface provided by R.The mapping of data types works in both directions. It is as straightforward to pass data from R to C++, as it is it return data from C++ to R. The following two sections list supported data types.
lib
. From within R, you can compute
the directory location via system.file("lib", "Rcpp.h",
package="Rcpp")
. For Windows, it will be a static library
To use Rcpp
in another package, you need to include the header
during compilation. This typically requires use of the -I
to
provide the location as in -I/usr/local/lib/R/site-library/Rcpp/lib
.
Similarly, for linking we need to provide the location of the library
via -L
as well as the actual library. An example for Linux
would be -L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp
.
In order to make it more convenient to use Rcpp
, functions
providing these arguments were added. To use these, simply use a file
src/Makevars
such as this (which was taken from the
emdL1
package)
# compile flag providing header directory containing Rcpp.h PKG_CXXFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'`
# link flag providing libary as well as path to library, and optionally rpath PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'`
Alternatively, one can also encode the test for these variables using
the GNU autoconf
system. The RQuantLib
package
provides an example of that.
Lastly, on Linux, and during development, it can convenient to simply
provide these files via soft links (or copies) from the usual locations like
ldconfig
after creating the
link for the library. Alternatively, you can hardcode the dynamic
library location using the rpath
linker directive:
Use on Windows is identical to the use in Linux. However only a static
library is provided. The two Rcpp
functions detailed
above provide the relevant content.