JavaNewbie
JavaNewbie

Reputation: 251

How to call Rscript from R?

I am developing a package that exposes an R interface (a bunch of functions to be used interactively) and a command line interface via Rscript. This second one works via a small launcher, for instance, at the command line:

Rscript mylauncher.R arg1 arg2 arg3

would call a function of my package. I would like to test a couple of command lines from R. Nothing fancy, just make sure that everything runs without errors. If I test these calls doing in an R source file:

system("Rscript mylauncher.R arg1 arg2 arg3")

How can I be sure that I called the right Rscript? In case there are multiple R installations? (which is actually the case in my setting). Another approach would be write in the R source file:

source("mylauncher.R")

But I don't see how to specify the command line (I would avoid the trick of overwriting the function commandArgs, because I want to test also the right tokenization of the command line). Does anybody have an idea?

Thanks!

Upvotes: 4

Views: 1782

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368181

Regarding

How can I be sure that I called the right Rscript? In case there are multiple R installations?

you would query R RHOME on the command-line and Sys.getenv("R_HOME") from wihthin R.

You then append bin/RScript and should have the Rscript corresponding to your current session. I still design my libraries in such a way that I can call them from R ...

Upvotes: 5

Related Questions