Is it possible to specify command line parameters to R-script in RStudio?

前端 未结 6 1983
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 23:10

I want to use RStudio to edit an R-script having command line parameters, e.g.,

my_rscript --dataset mydataset

and then to read the optiion

6条回答
  •  一生所求
    2020-12-08 23:34

    You can call your programs using Rscript programname.r arg1 arg2 arg3. The arguments are passed to commandArgs, so the following would be true:

    Rscript programname.r F N 32
    
    > args <- commandArgs(trailingOnly=TRUE)
    > args[1]
    [1] F
    > args[2]
    [1] N
    > args[3]
    [1] 32
    

提交回复
热议问题