How to call and pass parameter to R function in C++? -
i m writing 1 function in r plotting graph. need call function using c++ program.
r program (script.r)
genplot<-function(x,y,outfile) { plot(outfile) plot(x,y) dev.off() } c++ program (run.cpp)
#include <iostream.h> using namespace std; int main() { int x[] = (1,2,3,4,5); int y[] = (2,3,4,1,3); genplot(x,y); #need call r function passing these 2 variables. return 0; }
you can use rinside. reading rinside page , come , haven't test yet. basic idea passe data r using rcpp wrappers evalute function string.
#include <rinside.h> int main(int argc, char *argv[]) { rinside r(argc, argv); // create embedded r instance int x[] = (1,2,3,4,5); int y[] = (2,3,4,1,3); r.assign(x,"x"); r.assign(y,"y"); r["outfile"] = "output.txt"; r.parseevalq("genplot(x,y,outfile)"); // eval init string, ignoring returns exit(0); }
Comments
Post a Comment