1

I want to execute an R script via command line parsing arguments to it. I know this can be done like this: Rscript script.R arg1 arg2, and that the arguments can be read in the R script as:

args <- commandArgs(trailingOnly = TRUE) input1 = args[1] input2 = args[2]

but I was wondering: is there a way to define flags (e.g., --input) those arguments can be provided with, so that I do not have to worry about the order in which I provide them? I have looked around quite a while, but was not able to find a way.

Any help would be much appreciated!

Thank you!

fjvh84w
  • 11
  • 1

1 Answers1

0

Use the library optArgs. It gives you all functionality you need. You can add options via command:

 add_option()

and parse arguments with:

parse_args()

See optparse for more details.

StefanG
  • 1,234
  • 2
  • 22
  • 46