how to rename tibble with named vecor?

I would like to rename tibble with named vector, even if there is some columns does not exist.

z <- c(x = "a", y = "b", w = "c")
tibble(a = 1:5, b = 2:6) %>% 
  rename(!!!z)

Error in stop_subscript():
! Can't rename columns that don't exist.
x Column c doesn't exist.
Run rlang::last_error() to see where the error occurred.

z <- c(x = "a", y = "b", w = "c")
tibble(a = 1:5, b = 2:6) %>% 
  rename(any_of(z))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.