-
Notifications
You must be signed in to change notification settings - Fork 184
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
Code using startsWith
recommended by string_boundary_linter
is not functionally identical when data has NA
s
#1376
Comments
surprised I never caught this 😳 I guess that explains #1331 too. personally I think we have a similar recommendation for so I lean towards just improving the lint message and linter documentation. |
I am amazed that this even works:
I am aware of short-circuit evaluation, of course, but I was not aware it's applied element-wise in R. Indeed, That said, while I was surprised that the result of |
this is good extended boolean logic at work -- NA means "either TRUE or FALSE, but we're not sure which", i.e., there's a value, it's boolean, but identity unknown. but regardless of identity of y, TRUE & y is always TRUE, hence the result |
|
😅 right. TRUE | y is TRUE. mixed them up |
WDYT about suggesting |
Agree with all of the above. I just wonder if with this suggestion, the readability argument still holds. I find Also, what do you want users to do if What about
|
Technically, we could also suggest NB that we also lint |
right, So I think an
Hopefully this conveys both situations: (1) i have missing values and I expected/wanted
please no 😂 much more practical is assigning the expensive result first: x <- expensive_computation(...)
!is.na(x) & startsWith(x, pattern) PS FWIW, I suspect a lot of people are using grepl in |
Sounds good - I think I would turn this on immediately in my code, and I would not be sad if it were on by default :) But either default value is fine.
This message is perfect IMO.
For the record, I noticed its use in logical indexing of vectors and data frames, where it does make a difference: strs <- c("AB", "CD", NA)
strs[grepl("^A", strs)] # "AB"
strs[startsWith(strs, "A")] # "AB" NA
as.data.frame(strs)[grepl("^A", strs), ] # "AB"
as.data.frame(strs)[startsWith(strs, "A"), ] # "AB" NA |
I would expect that the warning gives enough details to either
NA
s the same asgrepl
(I am not aware of any short in-line way), orNA
will require special treatment.I fear that this necessary special treatment will be bad for readability, anyway.
The text was updated successfully, but these errors were encountered: