Call This Function from a C Program
In the C program:
/* open file for R instructions */
sprintf(str,"%s/rfile.input", Dxmenu_Dir);
if ( (fpR = creat(str, MODE)) == -1) {
fprintf(stderr, "Cannot open file for R instructions.\n");
return;
}
/* load the file to be plotted */
sprintf(datafilename, "%s_%d_%d_profile", name, slice,where);
/* Put this in the file opened above and close the file*/
sprintf(str, "rplot(\"%s\")\n", datafilename);
write(fpR,str,sizeof(char)*strlen(str));
close(fpR);
/* run the R program */
sprintf(str, "/bin/csh %s/rfile.sh %s", Path1, Path2);
system(str);
}
Transcript
So, in this case, I'm now writing in C. I sprint() into a buffer a string - I form the file name, I create the file, I can load my data file in. Again, I create the file name based upon the things that I've constructed with these parameters, "_profile". I read it in, and I write data, I close it. I run my program and violà; I can use the system command to now invoke R, passing it the R function that I want to have executed on the data that I just read it. And I dynamically can do that.