Essentially I modified the default CMakeLists.txt file to be:
From http://stackoverflow.com/questions/28761323/how-to-include-external-library-boost-into-clion-c-project-with-cmake
Essentially I modified the default CMakeLists.txt file to be:
0 Comments
Write your .cpp file, including whatever Boost libraries you need, and including Rcpp:
#include <Rcpp.h> #include <boost/math/common_factor.hpp> // included in BH #include <boost/math/special_functions/bessel.hpp> // ... etc. Between the includes and the other functions, type // [[Rcpp::depends(BH)]] BH is a package that must be installed in R (install.packages(-) and library(-)) (so is Rcpp). Before each function in your .cpp file you need // [[Rcpp::export]] in a line by itself. This allows the function to be accessible from R. This syntax is for an *attribute* in C++. See my file pvm.cpp (in the git .gist below) for an example of everything so far. Once the .cpp file is correctly written, use it from R as follows: > library(BH); library(Rcpp) > sourceCpp('~/.../mypvm.cpp') > mypvm(1,2,3) That's all there is to it! More detailed information at the following links: // - http://dirk.eddelbuettel.com/code/bh.html // - http://gallery.rcpp.org/articles/a-first-boost-example/ // - After "which builds and runs..." at http://stackoverflow.com/questions/16131462/how-to-use-boost-library-in-c-with-rcpp |
Categories
All
Archives
December 2016
AboutThis blog is mainly for statistics, R, or Duke-related stuff that is not directly relating to research activity. |