Like transmute-table.express but for a single call and maybe specifying .SDcols
.
transmute_sd(.data, .SDcols = everything(), .how = identity, ...)# S3 method for ExprBuilder
transmute_sd(
.data,
.SDcols = everything(),
.how = identity,
...,
.parse = getOption("table.express.parse", FALSE),
.chain = getOption("table.express.chain", TRUE)
)
# S3 method for EagerExprBuilder
transmute_sd(.data, ..., .parent_env = rlang::caller_env())
# S3 method for data.table
transmute_sd(.data, ...)
An instance of ExprBuilder.
See data.table::data.table and the details here.
The function(s) or function call(s) that will perform the transformation. If many,
a list should be used, either with list()
or .()
. If the list is named, the names will be
used for the new columns' names. Lambdas specified as formulas are supported.
Possibly more arguments for all functions/calls in .how
.
Logical. Whether to apply rlang::parse_expr()
to obtain the expressions.
Logical. Should a new frame be automatically chained to the expression if the clause being set already exists?
See end_expr()
Like transmute-table.express, this function never modifies the input by reference. This
function adds/chains a select
expression that will be evaluated by data.table::data.table,
possibly specifying the helper function .transmute_matching
, which is assigned to the final
expression's evaluation environment when calling end_expr()
(i.e., ExprBuilder's eval
method).
Said function supports two pronouns that can be used by .how
and .SDcols
:
.COL
: the actual values of the column.
.COLNAME
: the name of the column currently being evaluated.
Additionally, lambdas specified as formulas are also supported. In those cases, .x
is
equivalent to .COL
and .y
to .COLNAME
.
Unlike a call like DT[, (vars) := expr]
, .SDcols
can be created dynamically with an
expression that evaluates to something that would be used in place of vars
without eagerly
using the captured data.table
. See the examples here or in table.express-package.
data("mtcars")
data.table::as.data.table(mtcars) %>%
transmute_sd(~ grepl("^d", .y), ~ .x * 2)
data.table::as.data.table(mtcars) %>%
transmute_sd(~ is.numeric(.x), ~ .x * 2)
Run the code above in your browser using DataLab