Arguments have hidden positional dependency
Hello there,
Thank you for bringing this phenomenal tool to R!
I'm on docopt_0.4.5 and I've noticed a strange behaviour regarding order of arguments. Here's an example:
' Usage: combine_germline_files.R -p PATHS -o OUTPUT [ -n GENENAME ]
' -> doc
library(docopt)
args = docopt(doc)
When I run
Rscript scripts/pipelines/pog-germline/combine_germline_files.R -p paths/germline_paths.txt -o meta/mutyh_germline.txt -n MUTYH
it works just fine, but if I reverse the argument order of -p and -o as follows:
Rscript scripts/pipelines/pog-germline/combine_germline_files.R -o meta/mutyh_germline.txt -p paths/germline_paths.txt -n MUTYH
I get an error. The script loads meta/mutyh_germline into PATHS instead of correctly loading paths/germline_paths.txt into PATHS. This seems to suggest a hidden dependency on the order of arguments, not just which flags they follow.
@eyzhao I would have written that opt string differently: (and this works fine)
library(docopt)
'Usage:
test.R -a <A> -b <B>
Options:
-a <A> option 1
-b <B> option 2
' -> doc
docopt(doc, args = "-a x -b y" )
docopt(doc, args = "-b y -a x" )
Thanks shntnu,
Follow-up question. If there's a more complex set of arguments, would that necessitate encoding every possible ordering of parameters? Or is there a more elegant solution?
Ah, but the version I have above is order invariant i.e.
docopt(doc, args = "-a x -b y" )
docopt(doc, args = "-b y -a x" )
give the same result.
Oh! My apologies. I misunderstood those last two lines. Yes, I have been sure to include the "Options:" section recently and glad to know that this addresses the issue. Thanks for your help :)