-2

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
  • 13
  • 116
  • 190
E_1996
  • 33
  • 5
  • You don't install it, it's a header-only template library, it tells you how to include the headers in your project in the profile. – user438383 Feb 15 '23 at 20:28
  • How does this improve over your question from [two days ago](https://stackoverflow.com/questions/75431501/how-to-install-new-c-libraries-in-rcpp) that was closed? What part of the suggested readings have you done? This is still programming, you can't just declaratively say "I want Rcpp and FastAD". – Dirk Eddelbuettel Feb 15 '23 at 20:30
  • Two days ago I pointed you at ['Thirteen Simple Steps for Creating An R Package with an External C++ Library'](https://cloud.r-project.org/web/packages/Rcpp/vignettes/Rcpp-libraries.pdf) which was written to ... explain exactly this (and alternatives). 'How to use a template header library with Rcpp' is just about the easiest way. I still suggest you study the vignette. Rcpp also has a mailing list. – Dirk Eddelbuettel Feb 15 '23 at 20:32
  • @DirkEddelbuettel Sorry i'm new to all of this. I have made an R package for use with Rcpp and pasted the files for FastAD into the /src directory however when trying to compile the .rcpp file I get an error saying there's no such file or directory (however the error points to a different file to the one I #include on, but nonetheless it is still there). I read the "Rcpp extending" document you linked me to but i don't quite see how it's relevant to loading the library headers I need – E_1996 Feb 15 '23 at 20:55

1 Answers1

2

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
> 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks so much for this Dirk. I'm not sure what is going on but I get an error when trying to install the package (using "devtools::install_github("eddelbuettel/rcppfastad", force = T)") - the errors are quite vague but the last few lines say: " make: *** [/usr/lib/R/etc/Makeconf:177: black_scholes_example.o] Error 1 ERROR: compilation failed for package ‘RcppFastAD’ ─ removing ‘/tmp/RtmprDcOct/Rinst992aa1348c7fe/RcppFastAD’" – E_1996 Feb 16 '23 at 13:48
  • Glad you found it, but you have many things to learn, among them that the previous comment contained no actionable item for. So you had an error. Your compiler may be to old, but you haven't even told me what OS you are and what compiler you are using. Don't reply here in comments on that either -- it is not the place. I appreciate that you have a lot of appetite and energy, but I feel you are jumping in at the wrong end of the pond. I really recommend taking baby steps. And more reading and re-creating of (known working!) examples. Good luck. – Dirk Eddelbuettel Feb 16 '23 at 14:48
  • Try now -- I was not setting C++17 as the compilation standard _explicitly_ as my compiler defaults to it. – Dirk Eddelbuettel Feb 16 '23 at 18:18
  • With that it builds "everywhere": https://eddelbuettel.r-universe.dev/RcppFastAD – Dirk Eddelbuettel Feb 16 '23 at 22:07