Skip to content
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

If "type" is "logical" cast according to "as.logical()" logic #39

Closed
trevorld opened this issue Apr 15, 2022 · 2 comments
Closed

If "type" is "logical" cast according to "as.logical()" logic #39

trevorld opened this issue Apr 15, 2022 · 2 comments
Assignees

Comments

@trevorld
Copy link
Owner

  • instead of Python's bool() logic (everything but "" is TRUE instead use R's as.logical()'s logic)
  • write a custom function in our Python code and use that as our "type"
@trevorld trevorld self-assigned this Apr 15, 2022
@trevorld
Copy link
Owner Author

  • @Lain-inrae although Support custom function 'type' in 'add_argument()' #37 hasn't been supported, casting to the "logical" type now follows R's logic instead of Python's logic.
  • Doesn't seem to be quite what you wanted with a custom bool type but perhaps closer than before. "T", "True", "TRUE", "true", "F", "False", "FALSE", "false" (but not "0" / "1") now cast to "reasonable" values.
parser <- ArgumentParser(prog='PROG')
parser$add_argument('-p', type="logical", action="append", help="a list of booleans")
args <- strsplit("-p T -p F -p True -p False -p 1 -p 0 -p badValue", " ")[[1]]
parser$parse_args(args)
[1]  TRUE FALSE  TRUE FALSE    NA    NA    NA

@Lain-inrae
Copy link

Thanks that's great!

trevorld added a commit that referenced this issue Apr 19, 2022
* To match behavior with integers and doubles we now
  throw an error if logical coercion would produce an NA.

follow-up on #39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants