Package 'filters'

Title: A "Snake_case" Filter System for R
Description: Enables filtering datasets by a prior specified identifiers which correspond to saved filter expressions.
Authors: Thomas Neitman [aut] (Original creator of the package), Joe Zhu [ctb, cre], F. Hoffmann-La Roche AG [cph, fnd]
Maintainer: Joe Zhu <[email protected]>
License: Apache License 2.0
Version: 0.3.1
Built: 2024-09-15 05:31:47 UTC
Source: https://github.com/cran/filters

Help Index


filters Package

Description

Enables filtering datasets by a prior specified identifiers which correspond to saved filter expressions.

Author(s)

Maintainer: Joe Zhu [email protected] [contributor]

Authors:

  • Thomas Neitman (Original creator of the package)

Other contributors:

  • F. Hoffmann-La Roche AG [copyright holder, funder]


Add a New Filter Definition

Description

Add a new filter definition or overwrite an existing one

Usage

add_filter(
  id,
  title,
  target,
  condition,
  character_only = FALSE,
  overwrite = FALSE
)

Arguments

id

character The id or name of this filter, e.g. "SE".

title

character The title of the filter

target

character The target dataset of the filter

condition

The filter condition

character_only

logical. Is condition a string? Defaults to FALSE.

overwrite

logical Should existing filters be overwritten? Defaults to FALSE.

Value

The function returns a list of title, target and condition invisibly

Author(s)

Thomas Neitmann (neitmant)

Examples

add_filter(
  id = "CTC5",
  title = "Grade 5 Adverse Event",
  target = "ADAE",
  condition = AETOXGR == "5"
)

add_filter(
  id = "CTC4",
  title = "Grade 4 Adverse Event",
  target = "ADAE",
  condition = "AETOXGR == '4'",
  character_only = TRUE
)

add_filter(
  id = "IT",
  title = "ITT Population",
  target = "ADSL",
  condition = ITTFL == "Y",
  overwrite = TRUE
)

add_filter(
  id = "5PER",
  title = "Adverse Events with a Difference of at Least 5% between Treatment Arms",
  target = "adae",
  condition = 1 == 1,
  overwrite = TRUE
)

Apply a Filter to a Dataset or List of Datasets

Description

Apply a Filter to a Dataset or List of Datasets

Usage

apply_filter(data, ...)

## Default S3 method:
apply_filter(data, ...)

## S3 method for class 'data.frame'
apply_filter(data, id, target = deparse(substitute(data)), verbose = TRUE, ...)

## S3 method for class 'list'
apply_filter(data, id, verbose = TRUE, ...)

Arguments

data

data.frame of list of data.frames

...

Not used.

id

character. The ID of a filter defined with add_filter()

target

character. The name of the dataset, e.g. ADSL or ADTTE

verbose

logical. Should informative messages be printed? Defaults to TRUE.

Value

A new data.frame or list of data.frames filtered based upon the condition defined for id

Author(s)

Thomas Neitmann (neitmant)

Examples

adsl <- random.cdisc.data::cadsl
adae <- random.cdisc.data::cadae
datasets <- list(adsl = adsl, adae = adae)

add_filter("REL", "Related AEs", "ADAE", AEREL == "Y", overwrite = TRUE)

apply_filter(adsl, "SE")
apply_filter(adae, "SER_REL")
apply_filter(datasets, "SER_REL_SE")

Get a Filter Definition

Description

Get a Filter Definition

Usage

get_filter(id)

Arguments

id

character. The filter ID

Value

A list with elements title, target and condition

Author(s)

Thomas Neitmann (neitmant)

Examples

get_filter("SE")
get_filter("SER")

## Filter `FOO` does not exist
try(get_filter("FOO"))

Get Multiple Filter Definitions

Description

Get Multiple Filter Definitions

Usage

get_filters(ids)

Arguments

ids

character. The filter IDs as a single string separated by underscores

Value

A named list of filter definitions

Author(s)

Thomas Neitmann (neitmant)

Examples

get_filters("REL_SER")
get_filters("OS_IT")

List All Filters

Description

List all available filters

Usage

list_all_filters()

Value

A data.frame with columns id, title, target and condition

Author(s)

Thomas Neitmann (neitmant)

Examples

list_all_filters()

Load Filter Definitions

Description

Load filter definitions from a yaml file

Usage

load_filters(yaml_file, overwrite = FALSE)

Arguments

yaml_file

character. A path to a yaml file containing filter definitions

overwrite

logical. Should existing filter definitions be overwritten? Defaults to FALSE.

Value

On success, load_filters() returns TRUE invisibly

Author(s)

Thomas Neitmann (neitmant)

Examples

filter_definitions <- system.file("filters.yaml", package = "filters")
if (interactive()) file.edit(filter_definitions)
load_filters(filter_definitions, overwrite = TRUE)