1

I have written an R program which opens a GUI. I want to make this file executable. When I searched over internet, I got some answers which said it can't be done. But the answers were of 2012. Is there any improvement done which will help my R file to be converted to an executable file?

Divi
  • 7,621
  • 13
  • 47
  • 63
  • Depends on your operating system, but all you need might be probably a [shebang](http://stackoverflow.com/questions/3128122/shebang-line-not-working-in-r-script/3128133#3128133) – Beasterfield Jul 02 '14 at 07:45

1 Answers1

0

You can embed R using C. An example of this:

void
init_R()
{
extern Rf_initEmbeddedR(int argc, char **argv);
  int argc = 1;
  char *argv[] = {"ggobi"};

  Rf_initEmbeddedR(argc, argv);
}

 /*
  Calls the equivalent of 
    x <- integer(10)
    for(i in 1:length(x))
       x[i] <- 1
    print(x)
 */
int
eval_R_command()
{
 SEXP e;
 SEXP fun;
 SEXP arg;
 int i;
 void init_R(void);

  init_R();

    fun = Rf_findFun(Rf_install("print"),  R_GlobalEnv);
    PROTECT(fun);
    arg = NEW_INTEGER(10);
    for(i = 0; i < GET_LENGTH(arg); i++)
      INTEGER_DATA(arg)[i]  = i + 1;
    PROTECT(arg);

    e = allocVector(LANGSXP, 2);
    PROTECT(e);
    SETCAR(e, fun);
    SETCAR(CDR(e), arg);

      /* Evaluate the call to the R function.
         Ignore the return value.
       */
    eval(e, R_GlobalEnv);
    UNPROTECT(3);   
  return(0);
}

I do hope you find it helpful. If this isn't the case, let me know by leaving a comment.

hd1
  • 33,938
  • 5
  • 80
  • 91
  • I am novice in programming. Is there any easy way without using C. However, I will study this and try to do. Thanks alot. – user3796176 Jul 02 '14 at 05:05
  • Does [this](http://stackoverflow.com/questions/6345613/interfacing-r-with-other-non-java-languages-compiling-r-to-executable?rq=1) help? – hd1 Jul 02 '14 at 05:35