Skip to contents

[Experimental] Set, get and remove filter states of FilteredData object

Usage

set_filter_state(datasets, filter)

get_filter_state(datasets)

remove_filter_state(datasets, filter)

clear_filter_states(datasets)

Arguments

datasets

(FilteredData)
object to store filter state and filtered datasets, shared across modules. For more details see FilteredData

filter

(list)
You can define filters that show when the app starts. List names should be named according to datanames passed to the data argument. In case of data.frame` the list should be composed as follows:

list(<dataname1> = list(<varname1> = ..., <varname2> = ...),
     <dataname2> = list(...),
     ...)

For example, filters for variable Sepal.Length in iris can be specified as follows:

list(iris = list(Sepal.Length = list(selected = c(5.0, 7.0))))
# or
list(iris = list(Sepal.Length = c(5.0, 7.0)))

In case developer would like to include NA and Inf values in the filtered dataset.

list(Species = list(selected = c(5.0, 7.0), keep_na = TRUE, keep_inf = TRUE))
list(Species = c(c(5.0, 7.0), NA, Inf))

To initialize with specific variable filter with all values on start, one can use

list(Species = list())

filter should be set with respect to the class of the column:

  • numeric: selected should be a two elements vector defining the range of the filter.

  • Date: selected should be a two elements vector defining the date-range of the filter

  • POSIXct: selected should be a two elements vector defining the datetime range of the filter

  • character and factor: selected should be a vector of any length defining initial values selected to filter.
    MultiAssayExperiment filter should be specified in slightly different way. Since MultiAssayExperiment::MultiAssayExperiment() contains patient data (SummarizedExperiment::colData()) with list of experiments (MultiAssayExperiment::ExperimentList()), filter list should be named in the following name.

list(
  <MAE dataname> = list(
    subjects = list(<column in colData> = ..., <column in colData> = ...),
    <experiment name> = list(
      subset = list(<column in rowData of experiment> = ...,
                    <column in rowData of experiment> = ...),
      select = list(<column in colData of experiment> = ...,
                    <column in colData of experiment> = ...)
    )
  )
)

filter is ignored if the app is restored from a bookmarked state.

Value

  • set, remove and clear returns NULL

  • get returns named list of the same structure as described in filter argument.

Examples

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

datasets <- init_filtered_data(
  x = list(
    iris = list(dataset = iris),
    mae = list(dataset = 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))
    )
  )
)

# set initial filter state
set_filter_state(datasets, filter = fs)

# get filter state
get_filter_state(datasets)
#> $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
#> 
#> 
#> 
#> 
#> 

# modify filter state
set_filter_state(
  datasets,
  filter = list(iris = list(Species = list(selected = "setosa", keep_na = TRUE)))
)

# remove specific filters
remove_filter_state(datasets,
  filter = list(
    iris = "Species",
    mae = list(
      subjects = c("years_to_birth", "vital_status")
    )
  )
)

# remove all states
clear_filter_states(datasets)