Optional integer vectors fail to parse when not specified and character argument supplied.

Issue #21 resolved
Former user created an issue

Looks like a bug in parsing. Adding a character argument changes the behaviour of the parsing of an integer vector argument.

library(argparser)
argp = arg_parser("OK")
argp = add_argument(argp, "--ivec", type="integer", narg=Inf, help="Vectors should default to zero length if not specified")
argp = add_argument(argp, "--i", type="integer", help="NA default works here")
argv = parse_args(argp, argv=c())

argp = arg_parser("Parse error")
argp = add_argument(argp, "--c", type="character", help="NA default works here")
argp = add_argument(argp, "--ivec", type="integer", narg=Inf, help="Vectors should default to zero length if not specified")
argp = add_argument(argp, "--i", type="integer", help="NA default works here")
argv = parse_args(argp, argv=c("--c", "value"))
#Error in (function (object, class, nargs)  : 
#  Invalid argument value: expecting integer but got: (NA).

Comments (2)

  1. David Shih repo owner

    Fixed in commit d75d49c6.

    Issue was introduced by feature request to check inputs. I forgot to handle NA, which is set by default to unspecified arguments. The first case passes because checking is not done when no input is supplied.

  2. Log in to comment