1

My cpp source code:

#include <iostream>
using namespace std;

int main(int argc, char **argv) {
cout<<"Before"<<endl;
system("Rscript /Desktop/R_TENS/rtest.R");
return 0;
}

rtest.R

rtest = function(input ,output){
     a <- input

   b<- output

   outpath<-a*b
   print(a*b)
   return(outpath)
 }

Compile: g++ name.cpp

This creates a executable file. But how the parameters (eg:2,3) is could be passed? ./a.out 2 3 is not working. Expected result for this input is 6.

9113303
  • 852
  • 1
  • 16
  • 30
  • 1
    Guessing, maybe because we are not passing args in `system` call in cpp code, also we are just defining a function in rtest.R and not calling it? – zx8754 Jul 11 '18 at 07:19
  • 1
    In `rtest.R` you just defined the function without actually calling it. See `?commandArgs` to pass arguments from the command line to a R script. – nicola Jul 11 '18 at 07:19
  • Your R script only defines a function. Change it to call the function using command line arguments as input. Once the script works on the command line, you have to add the command line arguments of the C++ program to the system call. – Ralf Stubner Jul 11 '18 at 09:08

0 Answers0