filter_sd {table.express}R Documentation

Filter subset of data

Description

Helper to filter rows with the same condition applied to a subset of the data.

Usage

filter_sd(.data, .SDcols, .how = Negate(is.na), ...)

## S3 method for class 'ExprBuilder'
filter_sd(
  .data,
  .SDcols,
  .how = Negate(is.na),
  ...,
  which,
  .collapse = `&`,
  .parse = getOption("table.express.parse", FALSE),
  .chain = getOption("table.express.chain", TRUE),
  .caller_env_n = 1L
)

## S3 method for class 'data.table'
filter_sd(.data, ..., .expr = FALSE)

Arguments

.data

An instance of ExprBuilder.

.SDcols

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

.how

The filtering function or predicate.

...

Possibly more arguments for .how.

which

Passed to data.table::data.table.

.collapse

See where-table.express.

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

.caller_env_n

Internal. Passed to rlang::caller_env() to find the function specified in .how and standardize its call.

.expr

If the input is a data.table and .expr is TRUE, an instance of EagerExprBuilder will be returned. Useful if you want to add clauses to j, e.g. with mutate-table.express.

Details

This function adds/chains an i expression that will be evaluated by data.table::data.table, and it supports the .COL pronoun and lambdas as formulas. The .how condition is applied to all .SDcols.

Additionally, .SDcols supports:

The caveat is that the expression is evaluated eagerly, i.e. with the currently captured data.table. Consider using chain() to explicitly capture intermediate results as actual data.tables.

To see more examples, check the vignette, or the table.express-package entry.

Examples


data("mtcars")

data.table::as.data.table(mtcars) %>%
    filter_sd(c("vs", "am"), ~ .x == 1)


[Package table.express version 0.4.2 Index]