Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments have hidden positional dependency #28

Open
eyzhao opened this issue Jul 12, 2017 · 4 comments
Open

Arguments have hidden positional dependency #28

eyzhao opened this issue Jul 12, 2017 · 4 comments

Comments

@eyzhao
Copy link

eyzhao commented Jul 12, 2017

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.

@shntnu
Copy link

shntnu commented Sep 1, 2017

@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" )

@eyzhao
Copy link
Author

eyzhao commented Sep 1, 2017

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?

@shntnu
Copy link

shntnu commented Sep 1, 2017

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.

@eyzhao
Copy link
Author

eyzhao commented Sep 1, 2017

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants