Make a rename columns node (copies columns not renamed).

rename_columns(source, cmap, env = parent.frame())

Arguments

source

source to rename from.

cmap

map written as new column names as keys and old column names as values.

env

environment to look to.

Value

rename columns node.

Examples

if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) { my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") d <- rq_copy_to(my_db, 'd', data.frame(AUC = 0.6, R2 = 0.2, z = 3)) op_tree <- rename_columns(d, c('R2' %:=% 'AUC', 'AUC' %:=% 'R2')) cat(format(op_tree)) sql <- to_sql(op_tree, my_db) cat(sql) print(DBI::dbGetQuery(my_db, sql)) DBI::dbDisconnect(my_db) }
#> mk_td("d", c( #> "AUC", #> "R2", #> "z")) %.>% #> rename_columns(., #> c('R2' = 'AUC', #> 'AUC' = 'R2')) #> SELECT #> `AUC` AS `R2`, #> `R2` AS `AUC`, #> `z` AS `z` #> FROM ( #> SELECT #> `AUC`, #> `R2`, #> `z` #> FROM #> `d` #> ) tsql_78511307080891805818_0000000000 #> R2 AUC z #> 1 0.6 0.2 3