Preview data-selection filtering

Description

Applies IGNORE/ACCEPT record-level filters to a NONMEM dataset in pure R, approximating the semantics of the [data_selection] model block. This is a preview function: the canonical, engine-validated filtering happens in Rust at fit time. The R-side implementation is intentionally lenient: unparseable expressions and unknown column names are silently treated as non-matching (no exclusion), whereas Rust will error on invalid filters. Use ferx_apply_selection() to inspect which records will be excluded before committing to a fit, or to pass pre-built conditions directly to [ferx_fit](ferx_fit.qmd).

Usage

ferx_apply_selection(
  data,
  ignore = NULL,
  accept = NULL,
  ignore_ids = NULL,
  excluded = FALSE
)

Arguments

  • data: One of:
  • a character path to a NONMEM CSV file (recorded on the returned object so [ferx_fit](ferx_fit.qmd)(data = <result>) can pass it through to Rust without writing a temporary file),
  • a data.frame already read into memory,
  • a ferx_data object returned by an earlier call (its cached selection is reused; combine with excluded = TRUE to pull the excluded records back out), or
  • a ferx_fit object, whose fired data-selection rules are replayed against the original dataset.
  • ignore: Character vector of filter expressions. A record is excluded when any expression evaluates to TRUE. Expressions use column names with standard comparison operators (==, !=, <, <=, >, >=); use && for AND within one expression. Example: c("DV < 0.001", "EVID != 0").
  • accept: Character vector of filter expressions. A record is kept only when all conditions pass; excluded if any fail.
  • ignore_ids: Numeric or character vector of subject IDs to exclude entirely.
  • excluded: Logical. When FALSE (default) the retained records are returned as a ferx_data object. When TRUE the function returns a plain data.frame of the excluded records instead, with an extra .exclude_reason column naming the first rule that dropped each record (this replaces the former ferx_selection_excluded() accessor).

Seealso

[ferx_fit](ferx_fit.qmd) which accepts a ferx_data object as data. Pass excluded = TRUE to retrieve the excluded rows.

Concept

data selection

Value

When excluded = FALSE, an object of class "ferx_data"(also a data.frame) containing the retained records. When excluded = TRUE, a plain data.frame of the excluded records. The ferx_data object carries these attributes:

  • source_path: Character path supplied as data, or NULL when data was a data.frame.
  • ignore, accept, ignore_ids: The filter conditions used (character / character / character vectors).
  • excluded_rows: A data.frame of the excluded records with an extra column .exclude_reason (first matching rule string).
  • exclusions: A named list mirroring fit$exclusions: n_records_total, n_obs_excluded, n_dose_excluded, n_other_excluded, excluded_subject_ids, fired_ignore, fired_accept.