New to C++, I would like to make functions compiled in a DLL available in R.
So far, I managed to do that for a basic function taking integer as input and returning the same, by following these steps in VisualStudio, then using dyn.load from R to load the created dll.
However, my C++ functions will need to handle R data.frame objects, and I am not sure how to make that possible. I saw from the Rcpp gallery that Rcpp might include some kind of translations between R and c++ data types including data.frame objects, but I don't know if I can generate a dll using Rcpp that I can then include in R using dyn.load.
From this answer by Dirk Eddelbuettel, it seems possible to generate a "dynamic library" using Rcpp, however, I could not find any dll when I tried generating a package with a source .cpp file using rcpp.package.skeleton(). The function I'd like to have a dll for is from the Rcpp gallery
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
DataFrame modifyDataFrame(DataFrame df) {
// access the columns
IntegerVector a = df["a"];
CharacterVector b = df["b"];
// make some changes
a[2] = 42;
b[1] = "foo";
// return a new data frame
return DataFrame::create(_["a"]= a, _["b"]= b);
}
I tried to just paste that code into VisualStudio to try and generate that DLL, however I have the error "cannot find Rcpp.h" which I quite expected.
I then followed these steps in RStudio:
- Create new project / Package
- Include this cpp source file as a source file for this package
includeRcpp and enterRcpp.package.skeleton("mypackage")so far, no DLL in the package folders- Tried to build the package in RStudio by going to Build/Install and Restart, but then I get an error message "Building R Packages needs installation of additional build tools, do you want to install them?" However I already have RbuildTools 3.4 installed, and when I click "YES" in RStudio nothing happens.
PS: Happy to hear about other methods but here the DLL format should be used if possible. Any piece of info is greatly appreciated since I have basically no idea of how Rcpp or C++ work