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

yn_to_tf returning NA instead of T/F for Y/N #47

Closed
esimms999-gsk opened this issue Jun 2, 2022 · 2 comments
Closed

yn_to_tf returning NA instead of T/F for Y/N #47

esimms999-gsk opened this issue Jun 2, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@esimms999-gsk
Copy link
Contributor

image

Test at "A" in screenshot is checking for 'Yes' or 'yes' or 'No' or 'no' or 'Y' or 'y' or 'N' or 'n', so a 'Y' or 'N' would pass the test. But then at "B" in screenshot, the values of only 'Yes' or 'yes' are assigned TRUE and the values of only 'No' or 'no' are assigned FALSE. 'Y', 'y', 'N', 'n' are assigned to NA.

I discovered this because spec_type_to_ds_vars() calls yn_to_tf() for the keep variable.

Also, a value of 'YES' or 'NO' is unacceptable and triggers the Warning message in the "else" block of the yn_to_tf function.

@mstackhouse mstackhouse added the bug Something isn't working label Jun 2, 2022
@mstackhouse
Copy link
Contributor

mstackhouse commented Jun 2, 2022

@statasaurus I think there are two ways we could approach this. First would be to update the regex to be case insensitive (and plug a small logic hole:

test <- c("Yes", "YES", "Y", "yes", "y", "NO", "N", "No", "n", "Yo", "None")

stringr::str_detect(test, regex("^y$|^n$|yes$|no$", ignore_case = T))
# [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE

Second would be to loosen our assumptions and just look for strings starting with Y or N:

test <- c("Yes", "YES", "Y", "yes", "y", "NO", "N", "No", "n", "Yo", "None")

stringr::str_detect(test, regex("^y|^n", ignore_case = T))
#  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

@esimms999-gsk do you have any thoughts on expectations as a user?

@esimms999-gsk
Copy link
Contributor Author

I think it should be the first way you suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants