How to install the "FastAD" C++ library in Rcpp?

92 views Asked by At

I am trying to install a C++ library called FastAD ( https://github.com/JamesYang007/FastAD#user-guide) in Rcpp but the installation instructions are generic (not specifically for Rcpp).

It would be greatly appreciated if someone coule give me some guidance for how to install and be able to #include the files?

1

There are 1 answers

4
Dirk is no longer here On

FastAD is a header-only library which only depends on Eigen3. That makes for a pretty straightforward application for Rcpp and friends.

First, rely on the RcppEigen.package.skeleton() function to create the barebones RcppEigen-using package.

Second, we copy the FastAD library into inst/include. We add a PKG_CPPFLAGS variable in src/Makevars to let R know to source it from there. That is all the compiler needs with a header-only library. (Edit: We also set CXX_STD=CXX17 unless one has a new enough compiler or R (currently: r-devel) which already default to C++17.)

Third, we create a simple example in src/ based on an example in FastAD. We picked the Black-Scholes example.

Fourth, minor cleanups like removing the hello* stanza files.

That is pretty much it. In its embryonic form the package is now here on GitHub. An example is

> library(RcppFastAD)
> blackScholesExamples()
56.5136
0.773818
51.4109
-0.226182
>