I have a package X in R. The package has a function foo(). I want to call the function foo() in a cpp file (using Rcpp). Is it possible?
#include <Rcpp.h>
void function01() {
// call foo() from package X ??
}
I have a package X in R. The package has a function foo(). I want to call the function foo() in a cpp file (using Rcpp). Is it possible?
#include <Rcpp.h>
void function01() {
// call foo() from package X ??
}
This is sort of a duplicate. Though, the majority of cases do not involve calling from a user defined package.
As a result, the mold to use is:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void function01(){
// Obtain environment containing function
Rcpp::Environment package_env("package:package_name_here");
// Make function callable from C++
Rcpp::Function rfunction = package_env["function_name"];
// Call the function and receive output (might not be list)
Rcpp::List test_out = rfunction(....);
}