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

Behavior of str_remove when called with NA_character_ pattern #546

Open
davidciani opened this issue Apr 11, 2024 · 0 comments
Open

Behavior of str_remove when called with NA_character_ pattern #546

davidciani opened this issue Apr 11, 2024 · 0 comments

Comments

@davidciani
Copy link

When called with NA as a pattern, str_remove fails loudly about a type mismatch. When called with NA_character_ as a pattern, it silently returns NA. Is this the expected behavior? If so it doesn't seem to be documented anywhere. Personally, I was expecting that str_remove would have returned the input string unmodified in this scenario (as there is nothing specified to remove), or alternatively failed with an error message.

library(stringr)

str_remove("test", NA)
#> Error in `str_replace()`:
#> ! `pattern` must be a string, not `NA`.

str_remove("test", NA_character_)
#> [1] NA

# What lead to discovery of this, though str_c is behaving as expected returning NA_character_

string_to_remove = NA # a blank cell in a data frame

str_remove_all("test", str_c("\\b",string_to_remove,"\\b"))
#> [1] NA

Created on 2024-04-11 with reprex v2.1.0

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