Reputation: 71
Is there a way to call an R-Script within C-Code?
I did find the R Api for C (chaper 6. of the 'Writing R Extensions' manual), but as far as I understood this does "only" allow to call the C-Implementation of R. Of cause I could call the R-Script via shell, but that's no solution for me, since this does not allow proper passing of data (at least no if I don't what to write the data into a Csv-File or something like this).
Is there a easy way of using the R to C parser beforehand?
Upvotes: 5
Views: 10564
Reputation: 1
I found this works to run Rscript in C++ for Mac systems:
string r_command = "/usr/local/bin/RScript --vanilla /Users/<enter file path here>/your_script.R \"" + argument_1 + "\" " + "\"" + argument_2 + "\"";
system(r_command.c_str());
You can also pass variables into the arguments. Watch out on the escapes. Things can get tricky.
Upvotes: 0
Reputation: 100174
is there some reason that you don't want to embed it? This is covered in this question: R from C — Simplest Possible Helloworld…
Upvotes: 2