Learn R Programming

table.express (version 0.1.1)

transmute_sd: Transmute subset of data

Description

Like transmute-table.express but for a single call and maybe specifying .SDcols.

Usage

transmute_sd(.data, .how = identity, ..., .SDcols = everything(),
  .parse = getOption("table.express.parse", FALSE),
  .chain = getOption("table.express.chain", TRUE))

Arguments

.data

An instance of ExprBuilder.

.how

The function or function call that will perform the transformation.

...

Possibly more arguments for .how.

.SDcols

See data.table::data.table and the details here.

.parse

Logical. Whether to apply rlang::parse_expr() to obtain the expressions.

.chain

Logical. Should a new frame be automatically chained to the expression if the clause being set already exists?

Details

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 includes 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.

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 using the captured data.table. See the examples here or in table.express-package.

Examples

Run this code
# NOT RUN {
data("mtcars")

data.table::as.data.table(mtcars) %>%
    start_expr %>%
    transmute_sd(.COL * 2, .SDcols = grepl("^d", .COLNAME))

# }

Run the code above in your browser using DataLab