Rename only if field exists, otherwise ignore
One can rename a field:
mtcars %>% rename(bla = mpg)
But if the field doesn't exist, an error:
mtcars %>% rename(MPG = mpg, CYL = cyl, bla = uyhgfrtgf)
Error: Can't rename columns that don't exist.
x Column `uyhgfrtgf` doesn't exist
In
I looked at ?rename_if
and it says this is now superseded by rename_with()
.
What's the 'right' way to attempt to rename fields but with a possibility they don't exist (e.g. in this case a ShinyApp with filter selectors).
from Recent Questions - Stack Overflow https://ift.tt/3gDL6he
https://ift.tt/eA8V8J
Comments
Post a Comment