Defaults set to small floating point number cause validation error

Issue #22 resolved
Jochen Weile created an issue

Setting the default value of an argument to a floating point number small enough for R to automatically display in scientific format, leads to an argument type validation error.

Example:

> p <- add_argument(p, "--cutoff", default=0.0005, help="Example cutoff")
> args <- parse_args(p)
Error in (function (object, class, nargs)  : 
  Invalid argument value: expecting numeric but got: (5e-04).

> p <- add_argument(p, "--cutoff", default=5e-4, help="Example cutoff")
> args <- parse_args(p)
Error in (function (object, class, nargs)  : 
  Invalid argument value: expecting numeric but got: (5e-04).

Comments (2)

  1. David Shih repo owner

    I can’t reproduce this.

    library(argparser)
    p <- arg_parser("test")
    p <- add_argument(p, "--cutoff", default=0.0005, help="Example cutoff")
    args <- parse_args(p, c("--cutoff", "5e-04"))
    

    gives

    > args
    [[1]]
    [1] FALSE
    
    $help
    [1] FALSE
    
    $opts
    [1] NA
    
    $cutoff
    [1] 5e-04
    

    as expected.

    Try updating your package to the master head following the README’s instructions – I have not released the updates yet.

    I’ll prepare a new release soon.

  2. Log in to comment