-
Notifications
You must be signed in to change notification settings - Fork 11
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
It affects the functionality of callback #46
Conversation
…lt value type, rather than using the type to convert again, and more importantly, this affects the functionality of the callback, callback is best for raw character processing, but this will make the callback type not consistent with the default value.
We definitely don't want to change this in the general case of a non-callback function e.g. if we set a numeric default for a "store" action default we want values like I'm not entirely persuaded we need to change this for callback functions. Can you provide a minimal reproducible example where this causes an issue?
If you set a logical default value won't it coerce to logical, not character and if already logical not change it at all? library("optparse")
parser <- OptionParser()
parser <- add_option(parser, "--bool", default=TRUE)
parse_args(parser, "--bool=F") $help
[1] FALSE
$bool
[1] FALSE Note also that normally when you'd want to store a boolean value you should probably be using the |
Thank you for your reply!
yes,I think developers should understand the meaning of the default value, because this value is set in the code. ` r$> library("optparse") r$> str2bool <- function(option, flag, option_value, parser) { r$> parser <- OptionParser(option_list = list(make_option("--test", type = "character", default = FALSE, callback = str2bool))) r$> parse_args(parser, "--test=f") $help r$> parse_args(parser) $help r$> parser <- add_option(parser, "--bool", default = TRUE) r$> parse_args(parser, "--bool=f") $help $bool Warning message: r$> parser <- add_option(parser, "--bool2", default = TRUE, callback = str2bool) r$> parser <- OptionParser() r$> parser <- add_option(parser, "--bool2", type = "logical", default = TRUE) r$> parse_args(parser, "--bool2=f") $bool2 Warning message: |
|
@trevorld it's good! |
I think this is not necessary, the user should understand their default value type, rather than using the type to convert again, and more importantly, this affects the functionality of the callback, callback is best for raw character processing, but this will make the callback type not consistent with the default value.
for example, I have a callback:
str2bool <- function(option, flag, option_value, parser) { s <- tolower(as.character(option_value)) if (s %in% c("0", "false", "f", "no", "n")) { FALSE } else { TRUE } }
It handles strings, and return logical, but if I set a logical default value, it will become character, not logical.