- changed status to wontfix
nargs=inf can't be used as last optional argument if a position argument follows
Issue #26
wontfix
I spotted this issue when using an optional argument with infinite number of args, and a positional argument. When the last optional arg has nargs=Inf
it will also gobble up the required args that follow.
Test code:
Example that works as intended:
Rscript argparser_test.R --inf a b c --one 2 something
[1] "This is a test script"
[[1]]
[1] FALSE
$help
[1] FALSE
$opts
[1] NA
$inf
[1] "a" "b" "c"
$one
[1] 2
$pos
[1] "something"
However when placing the inf
right before mock
positional argument causes an error:
Rscript argparser_test.R --one 2 --inf a b c something
usage: argparser_test.R [--] [--help] [--opts OPTS] [--inf INF] [--one
ONE] pos
Infinite nargs is causing issues
positional arguments:
pos mock argument
flags:
-h, --help show this help message and exit
optional arguments:
-x, --opts RDS file containing argument values
-i, --inf Character argument
-o, --one Integer argument.
Error in parse_args(p, argv = commandArgs(TRUE)) :
Missing required arguments: expecting 1 values but got 0 values: ().
Execution halted
> packageVersion("argparser")
[1] ‘0.6’
Is this an intended behaviour? I would expect that it would be possible to place optional arguments anywhere before the positional arguments.
Cheers,
António
Comments (2)
-
repo owner -
reporter Cheers @David Shih I should have read the docs more throughly before posting
I don’t have a solution at the moment, and since this is not critical, we can leave it at that.
- Log in to comment
This is expected behaviour. Please read
?add_argument
.If you have a fix that does not break existing features, feel free to send a pull request.