Some discussion and examples can be found here: https://winvector.github.io/FluidData/FluidData.html.

build_pivot_control(
  table,
  columnToTakeKeysFrom,
  columnToTakeValuesFrom,
  ...,
  prefix = columnToTakeKeysFrom,
  sep = NULL,
  tmp_name_source = wrapr::mk_tmp_name_source("bpc"),
  temporary = FALSE
)

# S3 method for default
build_pivot_control(
  table,
  columnToTakeKeysFrom,
  columnToTakeValuesFrom,
  ...,
  prefix = columnToTakeKeysFrom,
  sep = NULL,
  tmp_name_source = wrapr::mk_tmp_name_source("bpcd"),
  temporary = TRUE
)

# S3 method for relop
build_pivot_control(
  table,
  columnToTakeKeysFrom,
  columnToTakeValuesFrom,
  ...,
  prefix = columnToTakeKeysFrom,
  sep = NULL,
  tmp_name_source = wrapr::mk_tmp_name_source("bpc"),
  temporary = FALSE
)

Arguments

table

data.frame to scan for new column names (in-memory data.frame).

columnToTakeKeysFrom

character name of column build new column names from.

columnToTakeValuesFrom

character name of column to get values from.

...

not used, force later args to be by name

prefix

column name prefix (only used when sep is not NULL)

sep

separator to build complex column names.

tmp_name_source

a tempNameGenerator from cdata::mk_tmp_name_source()

temporary

logical, if TRUE use temporary tables

Value

control table

See also

Examples

d <- data.frame(measType = c("wt", "ht"), measValue = c(150, 6), stringsAsFactors = FALSE) build_pivot_control(d, 'measType', 'measValue', sep = '_')
#> measType measValue #> 1 wt measType_wt #> 2 ht measType_ht
d <- data.frame(measType = c("wt", "ht"), measValue = c(150, 6), stringsAsFactors = FALSE) ops <- rquery::local_td(d) %.>% build_pivot_control(., 'measType', 'measValue', sep = '_') cat(format(ops))
#> mk_td("d", c( #> "measType", #> "measValue")) %.>% #> non_sql_node(., build_pivot_control(., columnToTakeKeysFrom="measType", columnToTakeValuesFrom="measValue"))
if(requireNamespace("rqdatatable", quietly = TRUE)) { library("rqdatatable") d %.>% ops %.>% print(.) }
#> measType measValue #> 1 wt measType_wt #> 2 ht measType_ht
if(requireNamespace("RSQLite", quietly = TRUE)) { db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbWriteTable(db, 'd', d, overwrite = TRUE, temporary = TRUE) db %.>% ops %.>% print(.) DBI::dbDisconnect(db) }
#> measType measValue #> 1 ht measType_ht #> 2 wt measType_wt