Given a name you want and a possible alternative, this function renames an object as you want or errs with an informative message.
nms_try_rename(x, want, try)
A named object.
String of length 1 giving the name you want the object to have.
String of length 1 giving the name the object might have.
nms
Other functions for developers:
check_crucial_names()
,
extract_insensitive()
,
flag_if_group()
,
is_multiple()
,
rename_matches()
,
type_ensure()
nms_try_rename(c(a = 1), "A", "a")
#> A
#> 1
nms_try_rename(data.frame(a = 1), "A", "a")
#> A
#> 1 1
# Passes
nms_try_rename(c(a = 1, 1), "A", "a")
#> A
#> 1 1
if (FALSE) {
# Errs
# nms_try_rename(1, "A", "A")
}