简体   繁体   中英

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!

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 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM