Helper to filter rows with the same condition applied to a subset of the data.
filter_sd(.data, .SDcols, .how = Negate(is.na), ...)
# S3 method for 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 data.table
filter_sd(.data, ..., .expr = FALSE)
An instance of ExprBuilder.
See data.table::data.table and the details here.
The filtering function or predicate.
Possibly more arguments for .how
.
Passed to data.table::data.table.
See where-table.express.
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?
Internal. Passed to rlang::caller_env()
to find the function specified in
.how
and standardize its call.
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.
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:
A predicate using the .COL
pronoun that should return a single logical when .COL
is
replaced by a column of the data.
A formula using .
or .x
instead of the aforementioned .COL
.
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.table
s.
To see more examples, check the vignette, or the table.express-package entry.
data("mtcars")
data.table::as.data.table(mtcars) %>%
filter_sd(c("vs", "am"), ~ .x == 1)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> 1: 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
#> 2: 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
#> 3: 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
#> 4: 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
#> 5: 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
#> 6: 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
#> 7: 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2