简体   繁体   English

我如何通过每次传递不同的参数以批处理模式运行 R 脚本

[英]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.我对以批处理模式运行 R 脚本的知识为零。 I need to run an R script multiple times automatically by taking different arguments each time.我需要通过每次采用不同的参数自动多次运行 R 脚本。

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.稍后在代码中使用`Sys.getenv("ARG1") 等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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