Skip to contents

Class to encapsulate filtered datasets

Class to encapsulate filtered datasets

Details

The main purpose of this class is to provide a collection of reactive datasets, each dataset having a filter state that determines how it is filtered.

For each dataset, get_filter_expr returns the call to filter the dataset according to the filter state. The data itself can be obtained through get_data.

The datasets are filtered lazily, i.e. only when requested / needed in a Shiny app.

By design, any dataname set through set_dataset cannot be removed because other code may already depend on it. As a workaround, the underlying data can be set to NULL.

The class currently supports variables of the following types within datasets:

  • choices: variable of type factor, e.g. ADSL$COUNTRY, iris$Species zero or more options can be selected, when the variable is a factor

  • logical: variable of type logical, e.g. ADSL$TRT_FLAG exactly one option must be selected, TRUE or FALSE

  • ranges: variable of type numeric, e.g. ADSL$AGE, iris$Sepal.Length numerical range, a range within this range can be selected

  • dates: variable of type Date, POSIXlt Other variables cannot be used for filtering the data in this class.

Common arguments are:

  1. filtered: whether to return a filtered result or not

  2. dataname: the name of one of the datasets in this FilteredData

  3. varname: one of the columns in a dataset

Methods


Method new()

Initialize a FilteredData object

Usage

FilteredData$new(data_objects, join_keys = NULL, code = NULL, check = FALSE)

Arguments

data_objects

(list) should contain.

  • dataset data object object supported by FilteredDataset.

  • metatada (optional) additional metadata attached to the dataset.

  • keys (optional) primary keys.

  • datalabel (optional) label describing the dataset.

  • parent (optional) which NULL is a parent of this one.

join_keys

(JoinKeys or NULL) see teal.data::join_keys().

code

(CodeClass or NULL) see teal.data::CodeClass.

check

(logical(1)) whether data has been check against reproducibility.


Method datanames()

Gets datanames

The datanames are returned in the order in which they must be evaluated (in case of dependencies).

Usage

FilteredData$datanames()

Returns

(character vector) of datanames Gets data label for the dataset

Useful to display in Show R Code.


Method get_datalabel()

Usage

FilteredData$get_datalabel(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(character) keys of dataset


Method get_filterable_datanames()

Gets dataset names of a given dataname for the filtering.

Usage

FilteredData$get_filterable_datanames(dataname)

Arguments

dataname

(character vector) names of the dataset

Returns

(character vector) of dataset names


Method get_filterable_varnames()

Gets variable names of a given dataname for the filtering.

Usage

FilteredData$get_filterable_varnames(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(character vector) of variable names


Method get_call()

Gets a call to filter the dataset according to the filter state

It returns a call to filter the dataset only, assuming the other (filtered) datasets it depends on are available.

Together with self$datanames() which returns the datasets in the correct evaluation order, this generates the whole filter code, see the function FilteredData$get_filter_code.

For the return type, note that rlang::is_expression returns TRUE on the return type, both for base R expressions and calls (single expression, capturing a function call).

The filtered dataset has the name given by self$filtered_dataname(dataname)

This can be used for the Show R Code generation.

Usage

FilteredData$get_call(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(call or list of calls) to filter dataset calls


Method get_code()

Gets the R preprocessing code string that generates the unfiltered datasets

Usage

FilteredData$get_code(dataname = self$datanames())

Arguments

dataname

(character(1)) name(s) of dataset(s)

Returns

(character(1)) deparsed code


Method get_filtered_dataset()

Gets FilteredDataset object which contains all informations related to specific dataset.

Usage

FilteredData$get_filtered_dataset(dataname = character(0))

Arguments

dataname

(character(1))
name of the dataset.

Returns

FilteredDataset object or list of FilteredDataset


Method get_data()

Gets filtered or unfiltered dataset

For filtered = FALSE, the original data set with set_data is returned including all attributes.

Usage

FilteredData$get_data(dataname, filtered = TRUE)

Arguments

dataname

(character(1)) name of the dataset

filtered

(logical) whether to return a filtered or unfiltered dataset


Method get_check()

Returns whether the datasets in the object have had a reproducibility check

Usage

FilteredData$get_check()

Returns

logical


Method get_metadata()

Gets metadata for a given dataset

Usage

FilteredData$get_metadata(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

value of metadata for given data (or NULL if it does not exist)


Method get_join_keys()

Get join keys between two datasets.

Usage

FilteredData$get_join_keys(dataset_1, dataset_2)

Arguments

dataset_1

(character(1)) one dataset name

dataset_2

(character(1)) other dataset name

Returns

(named character) vector with column names


Method get_filter_overview()

Get filter overview table in form of X (filtered) / Y (non-filtered)

This is intended to be presented in the application. The content for each of the data names is defined in get_filter_overview_info method.

Usage

FilteredData$get_filter_overview(datanames)

Arguments

datanames

(character vector) names of the dataset

Returns

(matrix) matrix of observations and subjects of all datasets Get keys for the dataset


Method get_keys()

Usage

FilteredData$get_keys(dataname)

Arguments

dataname

(character(1)) name of the dataset

Returns

(character) keys of dataset


Method get_varlabels()

Gets labels of variables in the data

Variables are the column names of the data. Either, all labels must have been provided for all variables in set_data or NULL.

Usage

FilteredData$get_varlabels(dataname, variables = NULL)

Arguments

dataname

(character(1)) name of the dataset

variables

(character) variables to get labels for; if NULL, for all variables in data

Returns

(character or NULL) variable labels, NULL if column_labels attribute does not exist for the data


Method get_varnames()

Gets variable names

Usage

FilteredData$get_varnames(dataname)

Arguments

dataname

(character) the name of the dataset

Returns

(character vector) of variable names When active_datanames is "all", sets them to all datanames otherwise, it makes sure that it is a subset of the available datanames


Method handle_active_datanames()

Usage

FilteredData$handle_active_datanames(datanames)

Arguments

datanames

character vector datanames to pick

Returns

the intersection of self$datanames() and datanames


Method set_dataset()

Adds a dataset to this FilteredData

Usage

FilteredData$set_dataset(dataset_args, dataname)

Arguments

dataset_args

(list)
containing the arguments except (dataname) needed by init_filtered_dataset

dataname

(string)
the name of the dataset to be added to this object

Details

set_dataset creates a FilteredDataset object which keeps dataset for the filtering purpose.

Returns

(self) invisibly this FilteredData


Method set_join_keys()

Set the join_keys

Usage

FilteredData$set_join_keys(join_keys)

Arguments

join_keys

(JoinKeys) join_key (converted to a nested list)

Returns

(self) invisibly this FilteredData


Method set_check()

sets whether the datasets in the object have had a reproducibility check

Usage

FilteredData$set_check(check)

Arguments

check

(logical) whether datasets have had reproducibility check

Returns

(self)


Method set_code()

Sets the R preprocessing code for single dataset

Usage

FilteredData$set_code(code)

Arguments

code

(CodeClass)
preprocessing code that can be parsed to generate the unfiltered datasets

Returns

(self)


Method get_filter_state()

Gets the reactive values from the active FilterState objects.

Gets all active filters in the form of a nested list. The output list is a compatible input to self$set_filter_state.

Usage

FilteredData$get_filter_state()

Returns

list with named elements corresponding to FilteredDataset objects with active filters.


Method get_formatted_filter_state()

Returns the filter state formatted for printing to an IO device.

Usage

FilteredData$get_formatted_filter_state()

Returns

character the pre-formatted filter state

Examples

utils::data(miniACC, package = "MultiAssayExperiment")
datasets <- teal.slice:::FilteredData$new(
  list(iris = list(dataset = iris),
       mae = list(dataset = miniACC)
  ),
  join_keys = NULL
)
fs <- list(
  iris = list(
    Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = FALSE),
    Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE)
  ),
  mae = list(
    subjects = list(
      years_to_birth = list(selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE),
      vital_status = list(selected = "1", keep_na = FALSE),
      gender = list(selected = "female", keep_na = TRUE)
    ),
    RPPAArray = list(
      subset = list(ARRAY_TYPE = list(selected = "", keep_na = TRUE))
    )
  )
)
datasets$set_filter_state(state = fs)
cat(shiny::isolate(datasets$get_formatted_filter_state()))


Method set_filter_state()

Sets active filter states.

Usage

FilteredData$set_filter_state(state)

Arguments

state

(named list)
nested list of filter selections applied to datasets.

Returns

NULL

Examples

utils::data(miniACC, package = "MultiAssayExperiment")

datasets <- teal.slice:::FilteredData$new(
  list(iris = list(dataset = iris),
       mae = list(dataset = miniACC)
  ),
  join_keys = NULL
)
fs <- list(
  iris = list(
    Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = FALSE),
    Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE)
  ),
  mae = list(
    subjects = list(
      years_to_birth = list(selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE),
      vital_status = list(selected = "1", keep_na = FALSE),
      gender = list(selected = "female", keep_na = TRUE)
    ),
    RPPAArray = list(
      subset = list(ARRAY_TYPE = list(selected = "", keep_na = TRUE))
    )
  )
)
datasets$set_filter_state(state = fs)
shiny::isolate(datasets$get_filter_state())


Method remove_filter_state()

Remove one or more FilterState of a FilteredDataset in a FilteredData object

Usage

FilteredData$remove_filter_state(state)

Arguments

state

(named list)
nested list of filter selections applied to datasets.

Returns

NULL


Method remove_all_filter_states()

Remove all FilterStates of a FilteredDataset or all FilterStates of a FilteredData object

Usage

FilteredData$remove_all_filter_states(datanames = self$datanames())

Arguments

datanames

(character)
datanames to remove their FilterStates or empty which removes all FilterStates in the FilteredData object.

Returns

NULL


Method restore_state_from_bookmark()

Sets this object from a bookmarked state

Only sets the filter state, does not set the data and the preprocessing code. The data should already have been set. Also checks the preprocessing code is identical if provided in the state.

Since this function is used from the end-user part, its error messages are more verbose. We don't call the Shiny modals from here because this class may be used outside of a Shiny app.

Usage

FilteredData$restore_state_from_bookmark(state, check_data_hash = TRUE)

Arguments

state

(named list)
containing fields data_hash, filter_states and preproc_code.

check_data_hash

(logical) whether to check that md5sums agree for the data; may not make sense with randomly generated data per session Module for the right filter panel in the teal app with a filter overview panel and a filter variable panel.

This panel contains info about the number of observations left in the (active) datasets and allows to filter the datasets.


Method ui_filter_panel()

Usage

FilteredData$ui_filter_panel(id)

Arguments

id

(character(1))
module id Server function for filter panel


Method srv_filter_panel()

Usage

FilteredData$srv_filter_panel(id, active_datanames = function() "all")

Arguments

id

(character(1))
an ID string that corresponds with the ID used to call the module's UI function.

active_datanames

function / reactive returning datanames that should be shown on the filter panel, must be a subset of the datanames argument provided to ui_filter_panel; if the function returns NULL (as opposed to character(0)), the filter panel will be hidden

Returns

moduleServer function which returns NULL Creates the UI for the module showing counts for each dataset contrasting the filtered to the full unfiltered dataset

Per dataset, it displays the number of rows/observations in each dataset, the number of unique subjects.


Method ui_filter_overview()

Usage

FilteredData$ui_filter_overview(id)

Arguments

id

module id Server function to display the number of records in the filtered and unfiltered data


Method srv_filter_overview()

Usage

FilteredData$srv_filter_overview(id, active_datanames = function() "all")

Arguments

id

(character(1))
an ID string that corresponds with the ID used to call the module's UI function.

active_datanames

(function, reactive)
returning datanames that should be shown on the filter panel, must be a subset of the datanames argument provided to ui_filter_panel; if the function returns NULL (as opposed to character(0)), the filter panel will be hidden.

Returns

moduleServer function which returns NULL


Method clone()

The objects of this class are cloneable with this method.

Usage

FilteredData$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(shiny)
datasets <- teal.slice:::FilteredData$new(
  list(
    iris = list(dataset = iris),
    mtcars = list(dataset = mtcars, metadata = list(type = "training"))
  )
)

# get datanames
datasets$datanames()
#> [1] "iris"   "mtcars"


df <- datasets$get_data("iris", filtered = FALSE)
print(df)
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> 1            5.1         3.5          1.4         0.2     setosa
#> 2            4.9         3.0          1.4         0.2     setosa
#> 3            4.7         3.2          1.3         0.2     setosa
#> 4            4.6         3.1          1.5         0.2     setosa
#> 5            5.0         3.6          1.4         0.2     setosa
#> 6            5.4         3.9          1.7         0.4     setosa
#> 7            4.6         3.4          1.4         0.3     setosa
#> 8            5.0         3.4          1.5         0.2     setosa
#> 9            4.4         2.9          1.4         0.2     setosa
#> 10           4.9         3.1          1.5         0.1     setosa
#> 11           5.4         3.7          1.5         0.2     setosa
#> 12           4.8         3.4          1.6         0.2     setosa
#> 13           4.8         3.0          1.4         0.1     setosa
#> 14           4.3         3.0          1.1         0.1     setosa
#> 15           5.8         4.0          1.2         0.2     setosa
#> 16           5.7         4.4          1.5         0.4     setosa
#> 17           5.4         3.9          1.3         0.4     setosa
#> 18           5.1         3.5          1.4         0.3     setosa
#> 19           5.7         3.8          1.7         0.3     setosa
#> 20           5.1         3.8          1.5         0.3     setosa
#> 21           5.4         3.4          1.7         0.2     setosa
#> 22           5.1         3.7          1.5         0.4     setosa
#> 23           4.6         3.6          1.0         0.2     setosa
#> 24           5.1         3.3          1.7         0.5     setosa
#> 25           4.8         3.4          1.9         0.2     setosa
#> 26           5.0         3.0          1.6         0.2     setosa
#> 27           5.0         3.4          1.6         0.4     setosa
#> 28           5.2         3.5          1.5         0.2     setosa
#> 29           5.2         3.4          1.4         0.2     setosa
#> 30           4.7         3.2          1.6         0.2     setosa
#> 31           4.8         3.1          1.6         0.2     setosa
#> 32           5.4         3.4          1.5         0.4     setosa
#> 33           5.2         4.1          1.5         0.1     setosa
#> 34           5.5         4.2          1.4         0.2     setosa
#> 35           4.9         3.1          1.5         0.2     setosa
#> 36           5.0         3.2          1.2         0.2     setosa
#> 37           5.5         3.5          1.3         0.2     setosa
#> 38           4.9         3.6          1.4         0.1     setosa
#> 39           4.4         3.0          1.3         0.2     setosa
#> 40           5.1         3.4          1.5         0.2     setosa
#> 41           5.0         3.5          1.3         0.3     setosa
#> 42           4.5         2.3          1.3         0.3     setosa
#> 43           4.4         3.2          1.3         0.2     setosa
#> 44           5.0         3.5          1.6         0.6     setosa
#> 45           5.1         3.8          1.9         0.4     setosa
#> 46           4.8         3.0          1.4         0.3     setosa
#> 47           5.1         3.8          1.6         0.2     setosa
#> 48           4.6         3.2          1.4         0.2     setosa
#> 49           5.3         3.7          1.5         0.2     setosa
#> 50           5.0         3.3          1.4         0.2     setosa
#> 51           7.0         3.2          4.7         1.4 versicolor
#> 52           6.4         3.2          4.5         1.5 versicolor
#> 53           6.9         3.1          4.9         1.5 versicolor
#> 54           5.5         2.3          4.0         1.3 versicolor
#> 55           6.5         2.8          4.6         1.5 versicolor
#> 56           5.7         2.8          4.5         1.3 versicolor
#> 57           6.3         3.3          4.7         1.6 versicolor
#> 58           4.9         2.4          3.3         1.0 versicolor
#> 59           6.6         2.9          4.6         1.3 versicolor
#> 60           5.2         2.7          3.9         1.4 versicolor
#> 61           5.0         2.0          3.5         1.0 versicolor
#> 62           5.9         3.0          4.2         1.5 versicolor
#> 63           6.0         2.2          4.0         1.0 versicolor
#> 64           6.1         2.9          4.7         1.4 versicolor
#> 65           5.6         2.9          3.6         1.3 versicolor
#> 66           6.7         3.1          4.4         1.4 versicolor
#> 67           5.6         3.0          4.5         1.5 versicolor
#> 68           5.8         2.7          4.1         1.0 versicolor
#> 69           6.2         2.2          4.5         1.5 versicolor
#> 70           5.6         2.5          3.9         1.1 versicolor
#> 71           5.9         3.2          4.8         1.8 versicolor
#> 72           6.1         2.8          4.0         1.3 versicolor
#> 73           6.3         2.5          4.9         1.5 versicolor
#> 74           6.1         2.8          4.7         1.2 versicolor
#> 75           6.4         2.9          4.3         1.3 versicolor
#> 76           6.6         3.0          4.4         1.4 versicolor
#> 77           6.8         2.8          4.8         1.4 versicolor
#> 78           6.7         3.0          5.0         1.7 versicolor
#> 79           6.0         2.9          4.5         1.5 versicolor
#> 80           5.7         2.6          3.5         1.0 versicolor
#> 81           5.5         2.4          3.8         1.1 versicolor
#> 82           5.5         2.4          3.7         1.0 versicolor
#> 83           5.8         2.7          3.9         1.2 versicolor
#> 84           6.0         2.7          5.1         1.6 versicolor
#> 85           5.4         3.0          4.5         1.5 versicolor
#> 86           6.0         3.4          4.5         1.6 versicolor
#> 87           6.7         3.1          4.7         1.5 versicolor
#> 88           6.3         2.3          4.4         1.3 versicolor
#> 89           5.6         3.0          4.1         1.3 versicolor
#> 90           5.5         2.5          4.0         1.3 versicolor
#> 91           5.5         2.6          4.4         1.2 versicolor
#> 92           6.1         3.0          4.6         1.4 versicolor
#> 93           5.8         2.6          4.0         1.2 versicolor
#> 94           5.0         2.3          3.3         1.0 versicolor
#> 95           5.6         2.7          4.2         1.3 versicolor
#> 96           5.7         3.0          4.2         1.2 versicolor
#> 97           5.7         2.9          4.2         1.3 versicolor
#> 98           6.2         2.9          4.3         1.3 versicolor
#> 99           5.1         2.5          3.0         1.1 versicolor
#> 100          5.7         2.8          4.1         1.3 versicolor
#> 101          6.3         3.3          6.0         2.5  virginica
#> 102          5.8         2.7          5.1         1.9  virginica
#> 103          7.1         3.0          5.9         2.1  virginica
#> 104          6.3         2.9          5.6         1.8  virginica
#> 105          6.5         3.0          5.8         2.2  virginica
#> 106          7.6         3.0          6.6         2.1  virginica
#> 107          4.9         2.5          4.5         1.7  virginica
#> 108          7.3         2.9          6.3         1.8  virginica
#> 109          6.7         2.5          5.8         1.8  virginica
#> 110          7.2         3.6          6.1         2.5  virginica
#> 111          6.5         3.2          5.1         2.0  virginica
#> 112          6.4         2.7          5.3         1.9  virginica
#> 113          6.8         3.0          5.5         2.1  virginica
#> 114          5.7         2.5          5.0         2.0  virginica
#> 115          5.8         2.8          5.1         2.4  virginica
#> 116          6.4         3.2          5.3         2.3  virginica
#> 117          6.5         3.0          5.5         1.8  virginica
#> 118          7.7         3.8          6.7         2.2  virginica
#> 119          7.7         2.6          6.9         2.3  virginica
#> 120          6.0         2.2          5.0         1.5  virginica
#> 121          6.9         3.2          5.7         2.3  virginica
#> 122          5.6         2.8          4.9         2.0  virginica
#> 123          7.7         2.8          6.7         2.0  virginica
#> 124          6.3         2.7          4.9         1.8  virginica
#> 125          6.7         3.3          5.7         2.1  virginica
#> 126          7.2         3.2          6.0         1.8  virginica
#> 127          6.2         2.8          4.8         1.8  virginica
#> 128          6.1         3.0          4.9         1.8  virginica
#> 129          6.4         2.8          5.6         2.1  virginica
#> 130          7.2         3.0          5.8         1.6  virginica
#> 131          7.4         2.8          6.1         1.9  virginica
#> 132          7.9         3.8          6.4         2.0  virginica
#> 133          6.4         2.8          5.6         2.2  virginica
#> 134          6.3         2.8          5.1         1.5  virginica
#> 135          6.1         2.6          5.6         1.4  virginica
#> 136          7.7         3.0          6.1         2.3  virginica
#> 137          6.3         3.4          5.6         2.4  virginica
#> 138          6.4         3.1          5.5         1.8  virginica
#> 139          6.0         3.0          4.8         1.8  virginica
#> 140          6.9         3.1          5.4         2.1  virginica
#> 141          6.7         3.1          5.6         2.4  virginica
#> 142          6.9         3.1          5.1         2.3  virginica
#> 143          5.8         2.7          5.1         1.9  virginica
#> 144          6.8         3.2          5.9         2.3  virginica
#> 145          6.7         3.3          5.7         2.5  virginica
#> 146          6.7         3.0          5.2         2.3  virginica
#> 147          6.3         2.5          5.0         1.9  virginica
#> 148          6.5         3.0          5.2         2.0  virginica
#> 149          6.2         3.4          5.4         2.3  virginica
#> 150          5.9         3.0          5.1         1.8  virginica

datasets$get_metadata("mtcars")
#> $type
#> [1] "training"
#> 

datasets$set_filter_state(
  list(iris = list(Species = list(selected = "virginica")))
)
isolate(datasets$get_call("iris"))
#> $filter
#> iris_FILTERED <- dplyr::filter(iris, Species == "virginica")
#> 

datasets$set_filter_state(
  list(mtcars = list(mpg = list(selected = c(15, 20))))
)

isolate(datasets$get_filter_state())
#> $iris
#> $iris$Species
#> $iris$Species$selected
#> [1] "virginica"
#> 
#> $iris$Species$keep_na
#> [1] FALSE
#> 
#> 
#> 
#> $mtcars
#> $mtcars$mpg
#> $mtcars$mpg$selected
#> [1] 15 20
#> 
#> $mtcars$mpg$keep_na
#> [1] FALSE
#> 
#> $mtcars$mpg$keep_inf
#> [1] FALSE
#> 
#> 
#> 
isolate(datasets$get_filter_overview("iris"))
#>      Obs      Subjects
#> iris "50/150" ""      
isolate(datasets$get_filter_overview("mtcars"))
#>        Obs     Subjects
#> mtcars "13/32" ""      
isolate(datasets$get_call("iris"))
#> $filter
#> iris_FILTERED <- dplyr::filter(iris, Species == "virginica")
#> 
isolate(datasets$get_call("mtcars"))
#> $filter
#> mtcars_FILTERED <- dplyr::filter(mtcars, mpg >= 15 & mpg <= 20)
#> 

## ------------------------------------------------
## Method `FilteredData$get_formatted_filter_state`
## ------------------------------------------------

utils::data(miniACC, package = "MultiAssayExperiment")
datasets <- teal.slice:::FilteredData$new(
  list(iris = list(dataset = iris),
       mae = list(dataset = miniACC)
  ),
  join_keys = NULL
)
#> Loading required package: MultiAssayExperiment
#> Loading required package: SummarizedExperiment
#> Loading required package: MatrixGenerics
#> Loading required package: matrixStats
#> 
#> Attaching package: ‘MatrixGenerics’
#> The following objects are masked from ‘package:matrixStats’:
#> 
#>     colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
#>     colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
#>     colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
#>     colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
#>     colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
#>     colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
#>     colWeightedMeans, colWeightedMedians, colWeightedSds,
#>     colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
#>     rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
#>     rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
#>     rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
#>     rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
#>     rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
#>     rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
#>     rowWeightedSds, rowWeightedVars
#> Loading required package: GenomicRanges
#> Loading required package: stats4
#> Loading required package: BiocGenerics
#> 
#> Attaching package: ‘BiocGenerics’
#> The following objects are masked from ‘package:stats’:
#> 
#>     IQR, mad, sd, var, xtabs
#> The following objects are masked from ‘package:base’:
#> 
#>     Filter, Find, Map, Position, Reduce, anyDuplicated, append,
#>     as.data.frame, basename, cbind, colnames, dirname, do.call,
#>     duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
#>     lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
#>     pmin.int, rank, rbind, rownames, sapply, setdiff, sort, table,
#>     tapply, union, unique, unsplit, which.max, which.min
#> Loading required package: S4Vectors
#> 
#> Attaching package: ‘S4Vectors’
#> The following objects are masked from ‘package:base’:
#> 
#>     I, expand.grid, unname
#> Loading required package: IRanges
#> Loading required package: GenomeInfoDb
#> Loading required package: Biobase
#> Welcome to Bioconductor
#> 
#>     Vignettes contain introductory material; view with
#>     'browseVignettes()'. To cite Bioconductor, see
#>     'citation("Biobase")', and for packages 'citation("pkgname")'.
#> 
#> Attaching package: ‘Biobase’
#> The following object is masked from ‘package:MatrixGenerics’:
#> 
#>     rowMedians
#> The following objects are masked from ‘package:matrixStats’:
#> 
#>     anyMissing, rowMedians
#> 
#> Attaching package: ‘MultiAssayExperiment’
#> The following object is masked _by_ ‘.GlobalEnv’:
#> 
#>     miniACC
fs <- list(
  iris = list(
    Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = FALSE),
    Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE)
  ),
  mae = list(
    subjects = list(
      years_to_birth = list(selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE),
      vital_status = list(selected = "1", keep_na = FALSE),
      gender = list(selected = "female", keep_na = TRUE)
    ),
    RPPAArray = list(
      subset = list(ARRAY_TYPE = list(selected = "", keep_na = TRUE))
    )
  )
)
datasets$set_filter_state(state = fs)
cat(shiny::isolate(datasets$get_formatted_filter_state()))
#> Filters for dataset: iris
#>   Filtering on: Sepal.Length
#>     Selected range: 5.100 - 6.400
#>     Include missing values: TRUE
#>   Filtering on: Species
#>     Selected values: setosa     versicolor
#>     Include missing values: FALSE
#> Filters for dataset: mae
#>   Subject filters:
#>     Filtering on: years_to_birth
#>       Selected range: 30.000 - 50.000
#>       Include missing values: TRUE
#>     Filtering on: vital_status
#>       Selected values: 1
#>       Include missing values: FALSE
#>     Filtering on: gender
#>       Selected values: female
#>       Include missing values: TRUE
#>   Assay RPPAArray filters:
#>     Subsetting:
#>       Filtering on: ARRAY_TYPE
#>         Selected values: 
#>         Include missing values: TRUE


## ------------------------------------------------
## Method `FilteredData$set_filter_state`
## ------------------------------------------------

utils::data(miniACC, package = "MultiAssayExperiment")

datasets <- teal.slice:::FilteredData$new(
  list(iris = list(dataset = iris),
       mae = list(dataset = miniACC)
  ),
  join_keys = NULL
)
fs <- list(
  iris = list(
    Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = FALSE),
    Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE)
  ),
  mae = list(
    subjects = list(
      years_to_birth = list(selected = c(30, 50), keep_na = TRUE, keep_inf = FALSE),
      vital_status = list(selected = "1", keep_na = FALSE),
      gender = list(selected = "female", keep_na = TRUE)
    ),
    RPPAArray = list(
      subset = list(ARRAY_TYPE = list(selected = "", keep_na = TRUE))
    )
  )
)
datasets$set_filter_state(state = fs)
shiny::isolate(datasets$get_filter_state())
#> $iris
#> $iris$Sepal.Length
#> $iris$Sepal.Length$selected
#> [1] 5.1 6.4
#> 
#> $iris$Sepal.Length$keep_na
#> [1] TRUE
#> 
#> $iris$Sepal.Length$keep_inf
#> [1] FALSE
#> 
#> 
#> $iris$Species
#> $iris$Species$selected
#> [1] "setosa"     "versicolor"
#> 
#> $iris$Species$keep_na
#> [1] FALSE
#> 
#> 
#> 
#> $mae
#> $mae$subjects
#> $mae$subjects$years_to_birth
#> $mae$subjects$years_to_birth$selected
#> [1] 30 50
#> 
#> $mae$subjects$years_to_birth$keep_na
#> [1] TRUE
#> 
#> $mae$subjects$years_to_birth$keep_inf
#> [1] FALSE
#> 
#> 
#> $mae$subjects$vital_status
#> $mae$subjects$vital_status$selected
#> [1] "1"
#> 
#> $mae$subjects$vital_status$keep_na
#> [1] FALSE
#> 
#> 
#> $mae$subjects$gender
#> $mae$subjects$gender$selected
#> [1] "female"
#> 
#> $mae$subjects$gender$keep_na
#> [1] TRUE
#> 
#> 
#> 
#> $mae$RPPAArray
#> $mae$RPPAArray$subset
#> $mae$RPPAArray$subset$ARRAY_TYPE
#> $mae$RPPAArray$subset$ARRAY_TYPE$selected
#> [1] ""
#> 
#> $mae$RPPAArray$subset$ARRAY_TYPE$keep_na
#> [1] TRUE
#> 
#> 
#> 
#> 
#>