Error: length(arg) == length(default) is not TRUE when adding multiple args at once
Issue #6
resolved
In this MWE the lengths are definitely same
#!/usr/bin/env Rscript
library('argparser')
p <- arg_parser("desc")
argmt <- c('--mode', '--debug', '--cores')
add_argument(p, argmt, help=argmt, default=argmt )
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" Platform: x86_64-pc-linux-gnu (64-bit)
package v. 0.3 from CRAN
Comments (4)
-
repo owner -
repo owner - changed status to invalid
-
repo owner I'll add more examples for clarity.
-
repo owner - changed status to resolved
Clarified error message in ab6766c
- Log in to comment
As per the help page:
Therefore, you need to supply default as a list. Otherwise, all the values in default will be casted to the most permissive variable type.
This works as intended:
Note that in real world usage, you will not want to store
argmt
as a vector and cast it to a list, as the value types will already have been converted inappropriately. Instead, you would want to create the list directly so that the types are preserved.Vectors, unlike lists, can only contain elements of a single type.
a
is converted a character vector, whereasb
preserves the types of the elements.