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
This worked for me: My Rscript is as follows:
args <- commandArgs()
print(paste0("args:", args))
print(paste0("args[1]:",args[1]))
print(paste0("args[2]:",args[2]))
print(paste0("args[3]:",args[3]))
print(paste0("# of args:",length(args)))
'
To emulate the command line input I would use with Rscript, I entered this in RStudio:
commandArgs <- function() c("AMZN", 10, 200)
which gave the desired result:
[1] "args:AMZN" "args:10" "args:200"
[1] "args[1]:AMZN"
[1] "args[2]:10"
[1] "args[3]:200"
[1] "# of args:3"