filterDTColumn: Filter 'DT' columns

View source: R/filterDTColumn.R

filterDTColumnR Documentation

Filter DT columns

Description

Filter a data.frame based on the DT datatable widget column search string.

Usage

filterDTColumn(x, search)

filterDT(df, column, global)

Arguments

x

A numeric or character vector, usually representing a column of a data.frame.

search

A string specifying the search filter to apply to x.

df

A data.frame that was used in the datatable widget.

column

A character vector of per-column search strings to apply to df. If any entry is an empty string, the corresponding column is not used for any filtering.

global

String containing a regular expression to search for across all columns in df (and row names, if present). If an empty string, no filtering is performed.

Details

For character x, search is treated as a regular expression.

For numeric x, search should have the form LOWER ... UPPER where all elements in [LOWER, UPPER] are retained.

For factor x, search should have the form ["choice_1", "choice_2", etc.]. This is also the case for logical x, albeit with the only choices being "true" or "false".

filterDT will retain all rows where (i) any value in any column (after coercion to a string) matches global, and (ii) the value in each column satisfies the filter specified in the corresponding entry of column. Setting global to an empty string will skip requirement (i) while setting any entry of column to an empty string will skip requirement (ii) for the affected column.

Ideally, ncol(df) and length(searches) would be the same, but if not, filterDT will simply filter on the first N entries where N is the smaller of the two.

Any NA element in x will be treated as a no-match. The same applies for each column of df that has non-empty column. Note that a no-match in one column does not preclude a successful match in another column by global.

Value

A logical vector indicating which entries of x or rows of df are to be retained.

Author(s)

Aaron Lun

See Also

datatable and associated documentation for more details about column searches.

Examples

# Regular expression:
filterDTColumn(LETTERS, "A|B|C")

# Range query:
filterDTColumn(runif(20), "0.1 ... 0.5")

# Factor query:
filterDTColumn(factor(letters), "['a', 'b', 'c']")

# Works on DataFrames:
X <- data.frame(row.names=LETTERS, thing=runif(26), 
    stuff=sample(letters[1:3], 26, replace=TRUE),
    stringsAsFactors=FALSE)

filterDT(X, c("0 ... 0.5", "a|b"), global="")
filterDT(X, "", global="A")


csoneson/iSEE documentation built on April 9, 2024, 3:17 p.m.