FilterStates {teal.slice} | R 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
orMultiAssayExperiment
orSummarizedExperiment
ormatrix
) theR
object whichsubset
function is applied on.data_reactive
(
function(sid)
) should return an object of the same type asdata
object orNULL
. This object is needed for theFilterState
counts being updated on a change in filters. If function returnsNULL
then filtered counts are not shown. Function has to havesid
argument being a character.dataname
(
character(1)
) name of the dataset, used in the subset expression. Passed to the function argument attached to thisFilterStates
.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 toformat.teal_slices
trim_lines
(
logical(1)
) passed toformat.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 inprivate$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 settingprivate$extract_type
(change in the similar way asdataname_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) ofFilterState
objects which"sid"
attribute is different than thissid
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 FilterState
s from the state_list
along with their UI elements.
Usage
FilterStates$remove_filter_state(state)
Arguments
state
(
teal_slices
) specifyingFilterState
objects to remove;teal_slice
s may contain onlydataname
andvarname
, 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 finalize()
Object cleanup.
Destroy inputs and observers stored in
private$session_bindings
Clean
state_list
Usage
FilterStates$finalize()
Returns
NULL
, invisibly.
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.