View source: R/VERBS-transmute_sd.R
| transmute_sd | R Documentation |
Like transmute-table.express but for a single call and maybe specifying .SDcols.
transmute_sd(.data, .SDcols = everything(), .how = identity, ...)
## S3 method for class 'ExprBuilder'
transmute_sd(
.data,
.SDcols = everything(),
.how = identity,
...,
.parse = getOption("table.express.parse", FALSE),
.chain = getOption("table.express.chain", TRUE)
)
## S3 method for class 'EagerExprBuilder'
transmute_sd(.data, ..., .parent_env = rlang::caller_env())
## S3 method for class 'data.table'
transmute_sd(.data, ...)
.data |
An instance of ExprBuilder. |
.SDcols |
See data.table::data.table and the details here. |
.how |
The function(s) or function call(s) that will perform the transformation. If many,
a list should be used, either with |
... |
Possibly more arguments for all functions/calls in |
.parse |
Logical. Whether to apply |
.chain |
Logical. Should a new frame be automatically chained to the expression if the clause being set already exists? |
.parent_env |
See |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.