简体   繁体   中英

how do i run an R script in batch mode by passing different arguments each time

I have zero knowledge about running an R script in batch mode. I need to run an R script multiple times automatically by taking different arguments each time.

I want to create some kind of file which has some commands something like below (I have no knowledge about the commands too)

 COMMAND   myscript.R arg1 arg2
 COMMAND   myscript.R arg3 arg4
 COMMAND   myscript.R arg5 arg6
 COMMAND   myscript.R arg7 arg8
 COMMAND   myscript.R arg9 arg10

I want to run this file in the end and go to sleep.

Can someone please help me with create this file and instructions on how to run it?

I understand that I can spend some time on google to figure this out but I honestly don't have time to do that much research. My other plan backfired and have no other option left apart from somehow being able to run the script in batch mode. I need to finish this task overnight. Any help would be really appreciated. Thanks a lot.

You may use environment variables. Something like

ARG1=arg1 ARG2=arg2 Rscript script.R
ARG1=arg3 ARG2=arg4 Rscript script.R
...

and later in the code you use `Sys.getenv("ARG1") etc.

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