Open TTTPOB opened 3 years ago
Can you please give an example how the corresponding R/Rscript call would look like?
Can you please give an example how the corresponding R/Rscript call would look like?
sorry for the late reply
it will looks like a python argparse script
Rscript path/to/the/script --step 1 --dist 100
inside the script
library(argparse)
parser<-ArgumentParser(description="demo")
attach(parser)
add_argument("--step", "-s", help="step of the counter")
add_argument("--dist", "-d", help="dist of the counter")
detatch(parser)
args<-parser$parse_args()
cat(
"the dist is: ",
dist,
"\n",
"the step is: ",
step,
"\n"
)
as you see, the arguments lies after the script, not the R
/Rscript
I need this too!
Also I'd love to see the option to set Rscript
args (like --vanilla
, because my .Rprofile may mess with the debugging or the script).
Yes IMO this is required for developing any non-trivial real-world script that needs to be configurable at runtime
One can make this work by setting the --args
flag, followed by whatever command line arguments one wants to supply to the script. One can then use commandArgs(trailingOnly = TRUE)
to obtain the passed CL arguments. To do this, add a commandLineArgs
entry into the launch.json
.
Caveat is that 'proper' command line parsing with e.g. argparse isn't supporte (or at least I don't expect it to work)
argparse isn't supporte (or at least I don't expect it to work)
It actually does work with argparse!
library(argparse)
parser <- ArgumentParser()
parser$add_argument("-n", "--name", help = "Whom shall I greet?", default = "World")
args <- parser$parse_args(commandArgs(trailingOnly = TRUE))
cat(paste0("Hello, ", args$name, "!\n"))
$ Rscript hello_name.R --name Kevin
Hello, Kevin!
maybe related #114 I cannot find where I can add command line arguments to the R script file itself rather than R itself, to debug a script file using
argparse
, this feature is needed