-
Notifications
You must be signed in to change notification settings - Fork 418
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
replace_na.data.frame() should be able to handle single values #1108
Comments
I think we're mostly moving away from functions like this in favour of vectorised functions + across, e.g. library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = 1:5, y = rep("huh",5))
df[1:2,] <- NA
df %>% mutate(across(where(is.character), coalesce, "Missing"))
#> # A tibble: 5 × 2
#> x y
#> <int> <chr>
#> 1 NA Missing
#> 2 NA Missing
#> 3 3 huh
#> 4 4 huh
#> 5 5 huh Created on 2021-08-23 by the reprex package (v2.0.0) This isn't to say that |
Hmmmm, but we have this api in |
On second thought, this might look more like correcting a bug than adding a feature. IMHO, the fact that To me, the example you provided is a lot longer and more verbous than the simple call to But of course |
Note to self: Remember to update |
Actually, do we really want this? This feels like a step in the wrong direction. With the library(tidyr)
df <- tibble(
x = 1:5,
y = rep("huh",5)
)
replace_na(df, list(x = "Missing", y = "Missing"))
#> Error: Can't convert `replace$x` <character> to match type of `data$x` <integer>.
# So this wouldn't work!
# replace_na(df, "Missing") Implementing this would mean that every column in It would also make code harder to read. i.e. is |
Well, you are right, this would have to cast every column to the target class. While it is definitely not as elegant as I initially thought, I don't think this is error-prone and I would still use this feature (for what it's worth). Moreover, warnings could be implemented in case of multiple classes (e.g. |
Yeah, based on @DavisVaughan's further exploration I've gone back to my original position and I don't think it's worth changing |
When using
replace_na()
on a dataframe, you have to use the columns names, as using a single value will raise an error:Created on 2021-03-13 by the reprex package (v1.0.0)
However, this is quite troublesome when you don't know the names of the dataframe beforehand.
Moreover, I see no obvious place where
replace_na(x, "Missing")
would be error-prone, so I do not understand whyreplace
has to be a list in this case.Would this behavior be considered as a feature?
The text was updated successfully, but these errors were encountered: