I had an understanding of R guts and came up with some smelly intestines that I could play with.
The command line is copied from C argc / argv to the global variable C with this function in the source code:
void R_set_command_line_arguments(int argc, char **argv)
So, we need a little C shell to get around the fact that the first parameter is not a pointer:
#include "Rh" #include "R_ext/RStartup.h" void set_command(int *pargc, char **argv){ R_set_command_line_arguments(*pargc, argv); }
compile in the usual way:
R CMD SHLIB setit.c
Download, call:
> dyn.load("setit.so") > commandArgs() [1] "/usr/lib/R/bin/exec/R" > invisible(.C("set_command",as.integer(2),c("Foo","Bar"))) > commandArgs() [1] "Foo" "Bar"
and then commandArgs() will return this vector until you change it.
source share