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

req()/isTruthy() can give suprising results for matrices (with NAs) #4092

Open
cpsievert opened this issue Jul 2, 2024 · 0 comments
Open

Comments

@cpsievert
Copy link
Collaborator

cpsievert commented Jul 2, 2024

Some might consider this surprising behavior:

m <- matrix(c(NA, "b", "c", NA), 2, 2)
#>     [,1] [,2]
#> [1,] NA   "c" 
#> [2,] "b"  NA 
shiny::isTruthy(m)
#> FALSE

The reason m is falsy is that stats::na.omit() returns a 0 row matrix:

x <- stats::na.omit(m)
str(x)
#> chr[0 , 1:2] 
#> - attr(*, "na.action")= 'omit' num [1:2] 1 2
nzchar(x)
#> logical(0)

I suppose this might be expected if you truly want to discard all rows with any NA, but that may not always be the case. It would probably make sense for req()/isTruthy() to gain a na.action = na.omit argument to customize the handling of NAs

@cpsievert cpsievert changed the title isTruthy() can return FALSE for character matrices with NA values req()/isTruthy() can give suprising results for matrices (with NAs) Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant