FilterStates: 'FilterStates' 'R6' class

FilterStatesR Documentation

FilterStates R6 class

Description

Abstract class that manages adding and removing FilterState objects and builds a subset expression.

A FilterStates object tracks all condition calls (logical predicates that limit observations) associated with a given dataset and composes them into a single reproducible R expression that will assign a subset of the original data to a new variable. This expression is hereafter referred to as subset expression.

The subset expression is constructed differently for different classes of the underlying data object and FilterStates sub-classes. Currently implemented for data.frame, matrix, SummarizedExperiment, and MultiAssayExperiment.

Methods

Public methods


Method new()

Initializes FilterStates object by setting dataname, and datalabel.

Usage
FilterStates$new(
  data,
  data_reactive = function(sid = "") NULL,
  dataname,
  datalabel = NULL
)
Arguments
data

(data.frame or MultiAssayExperiment or SummarizedExperiment or matrix) the R object which subset function is applied on.

data_reactive

(⁠function(sid)⁠) should return an object of the same type as data object or NULL. This object is needed for the FilterState counts being updated on a change in filters. If function returns NULL then filtered counts are not shown. Function has to have sid argument being a character.

dataname

(character(1)) name of the dataset, used in the subset expression. Passed to the function argument attached to this FilterStates.

datalabel

(character(1)) optional text label.

Returns

Object of class FilterStates, invisibly.


Method format()

Returns a formatted string representing this FilterStates object.

Usage
FilterStates$format(show_all = FALSE, trim_lines = TRUE)
Arguments
show_all

(logical(1)) passed to format.teal_slices

trim_lines

(logical(1)) passed to format.teal_slices

Returns

character(1) the formatted string


Method get_call()

Filter call

Builds subset expression from condition calls generated by FilterState. The lhs of the expression is a dataname_prefixed, where word prefixed refers to situation when call is evaluated on elements of the original data, for example dataname[[x]]. By default dataname_prefixed = dataname and it's not alterable through class methods. Customization of private$dataname_prefixed is done through inheriting classes.

The rhs is a call to private$fun with following arguments:

  • dataname_prefixed

  • list of logical expressions generated by FilterState objects stored in private$state_list. Each logical predicate is combined with & operator. Variables in these logical expressions by default are not prefixed but this can be changed by setting private$extract_type (change in the similar way as dataname_prefixed) Possible call outputs depending on a custom fields/options:

# default
dataname <- subset(dataname, col == "x")

# fun = dplyr::filter
dataname <- dplyr::filter(dataname, col == "x")

# fun = MultiAssayExperiment::subsetByColData; extract_type = "list"
dataname <- MultiAssayExperiment::subsetByColData(dataname, dataname$col == "x")

# teal_slice objects having `arg = "subset"` and `arg = "select"`
dataname <- subset(dataname, subset = row_col == "x", select = col_col == "x")

# dataname = dataname[[element]]
dataname[[element]] <- subset(dataname[[element]], subset = col == "x")

If no filters are applied, NULL is returned to avoid no-op calls such as dataname <- dataname.

Usage
FilterStates$get_call(sid = "")
Arguments
sid

(character) when specified then method returns code containing condition calls (logical predicates) of FilterState objects which "sid" attribute is different than this sid argument.

Returns

call or NULL


Method print()

Prints this FilterStates object.

Usage
FilterStates$print(...)
Arguments
...

additional arguments passed to format.


Method remove_filter_state()

Remove one or more FilterStates from the state_list along with their UI elements.

Usage
FilterStates$remove_filter_state(state)
Arguments
state

(teal_slices) specifying FilterState objects to remove; teal_slices may contain only dataname and varname, other elements are ignored

Returns

NULL, invisibly.


Method get_filter_state()

Gets reactive values from active FilterState objects.

Get active filter state from FilterState objects stored in state_list(s). The output is a list compatible with input to self$set_filter_state.

Usage
FilterStates$get_filter_state()
Returns

Object of class teal_slices.


Method set_filter_state()

Sets active FilterState objects.

Usage
FilterStates$set_filter_state(state)
Arguments
state

(teal_slices)

Returns

Function that raises an error.


Method clear_filter_states()

Remove all FilterState objects from this FilterStates object.

Usage
FilterStates$clear_filter_states(force = FALSE)
Arguments
force

(logical(1)) flag specifying whether to include anchored filter states.

Returns

NULL, invisibly.


Method ui_active()

shiny UI definition that stores FilterState UI elements. Populated with elements created with renderUI in the module server.

Usage
FilterStates$ui_active(id)
Arguments
id

(character(1)) shiny module instance id.

Returns

shiny.tag


Method srv_active()

shiny server module.

Usage
FilterStates$srv_active(id)
Arguments
id

(character(1)) shiny module instance id.

Returns

NULL.


Method ui_add()

shiny UI module to add filter variable.

Usage
FilterStates$ui_add(id)
Arguments
id

(character(1)) shiny module instance id.

Returns

shiny.tag


Method srv_add()

shiny server module to add filter variable.

This module controls available choices to select as a filter variable. Once selected, a variable is removed from available choices. Removing a filter variable adds it back to available choices.

Usage
FilterStates$srv_add(id)
Arguments
id

(character(1)) shiny module instance id.

Returns

NULL.


Method clone()

The objects of this class are cloneable with this method.

Usage
FilterStates$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


teal.slice documentation built on May 29, 2024, 1:39 a.m.