knitr::opts_chunk$set(echo = TRUE, comment = '.')
library(pmtables) vars <- dplyr::vars
I wanted a way to capture column names as a character vector along with a second set of names for renaming those data items. The primary need was a vector of names to use rather columns to select from a data set.
new_names
class with methods for character and quosure. This is two methods
and the generic.
pmtables:::new_names("a,b,c")
pmtables:::new_names(c("a", "b", "c"))
pmtables:::new_names(vars(a,b,c))
pmtables:::new_names(vars(A = a, B = b, C = c))
re <- list(A = "a", B = "b") pmtables:::new_names("A,B", table = re)
This is a little backward from the rename(new_name = old_name)
syntax; but
it is made to handle output from yspec, where things are already keyed by the
existing column name. This could easily be modified to invert names / values
during this lookup process.
library(dplyr) x <- pmtables:::new_names(vars(b = B, a = A)) x tab <- tibble(A = 1, B = 2) tab select(tab,all_of(x))
rename(tab, all_of(x))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.