data.frame
.R/DefOps.R
, R/LocalOps.R
, R/relops.R
build_pivot_control.Rd
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
)
data.frame to scan for new column names (in-memory data.frame).
character name of column build new column names from.
character name of column to get values from.
not used, force later args to be by name
column name prefix (only used when sep is not NULL)
separator to build complex column names.
a tempNameGenerator from cdata::mk_tmp_name_source()
logical, if TRUE use temporary tables
control table
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