Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify package #498

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ S3method(as.list,teal_slices)
S3method(c,teal_slices)
S3method(format,teal_slice)
S3method(format,teal_slices)
S3method(get_filter_call,default)
S3method(get_filter_overview,default)
S3method(get_slice_variable,default)
S3method(get_supported_filter_varnames,MultiAssayExperiment)
S3method(get_supported_filter_varnames,array)
S3method(get_supported_filter_varnames,default)
S3method(get_supported_filter_varnames,matrix)
S3method(init_filter_state,Date)
S3method(init_filter_state,POSIXct)
S3method(init_filter_state,POSIXlt)
Expand All @@ -17,16 +20,12 @@ S3method(init_filter_state,default)
S3method(init_filter_state,factor)
S3method(init_filter_state,logical)
S3method(init_filter_state,numeric)
S3method(init_filter_states,MultiAssayExperiment)
S3method(init_filter_states,SummarizedExperiment)
S3method(init_filter_states,data.frame)
S3method(init_filter_states,matrix)
S3method(init_filtered_dataset,MultiAssayExperiment)
S3method(init_filtered_dataset,data.frame)
S3method(init_filtered_dataset,default)
S3method(print,teal_slice)
S3method(print,teal_slices)
S3method(variable_types,DFrame)
S3method(srv_add,default)
S3method(ui_active,default)
S3method(ui_add,default)
S3method(variable_types,DataFrame)
S3method(variable_types,DataTable)
S3method(variable_types,data.frame)
S3method(variable_types,default)
Expand All @@ -35,17 +34,22 @@ export(FilterPanelAPI)
export(as.teal_slice)
export(as.teal_slices)
export(clear_filter_states)
export(get_filter_call)
export(get_filter_expr)
export(get_filter_state)
export(init_filter_states)
export(init_filtered_data)
export(init_filtered_dataset)
export(is.teal_slice)
export(is.teal_slices)
export(remove_filter_state)
export(set_filter_state)
export(srv_active)
export(srv_add)
export(srv_filter_panel)
export(teal_slice)
export(teal_slices)
export(ui_active)
export(ui_add)
export(ui_filter_panel)
import(R6)
import(shiny)
importFrom(methods,is)
12 changes: 7 additions & 5 deletions R/FilterPanelAPI.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ FilterPanelAPI <- R6::R6Class( # nolint
#' Gets all active filters in the form of a nested list.
#' The output list is a compatible input to `set_filter_state`.
#'
#' @return `list` with named elements corresponding to `FilteredDataset` objects with active filters.
#' @return `teal_slices` of active filters.
#'
get_filter_state = function() {
private$filtered_data$get_filter_state()
Expand All @@ -74,7 +74,7 @@ FilterPanelAPI <- R6::R6Class( # nolint
},

#' @description
#' Remove one or more `FilterState` of a `FilteredDataset` in the `FilteredData` object.
#' Remove one or more `FilterState` from the `FilteredData` object.
#'
#' @param filter (`teal_slices`)\cr
#' specifying `FilterState` objects to remove;
Expand All @@ -96,9 +96,11 @@ FilterPanelAPI <- R6::R6Class( # nolint
#' @return `NULL` invisibly
#'
clear_filter_states = function(datanames) {
datanames_to_remove <- if (missing(datanames)) private$filtered_data$datanames() else datanames
private$filtered_data$clear_filter_states(datanames = datanames_to_remove)
invisible(NULL)
isolate({
datanames_to_remove <- if (missing(datanames)) private$filtered_data$datanames() else datanames
private$filtered_data$clear_filter_states(datanames = datanames_to_remove)
invisible(NULL)
})
}
),
## __Private Methods ====
Expand Down
66 changes: 18 additions & 48 deletions R/FilterState-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
#' dataset are not shown.
#' @param slice (`teal_slice`)\cr
#' object created using [teal_slice()].
#' @param extract_type (`character(0)`, `character(1)`)\cr
#' specifying whether condition calls should be prefixed by `dataname`. Possible values:
#' \itemize{
#' \item{`character(0)` (default)}{ `varname` in the condition call will not be prefixed}
#' \item{`"list"`}{ `varname` in the condition call will be returned as `<dataname>$<varname>`}
#' \item{`"matrix"`}{ `varname` in the condition call will be returned as `<dataname>[, <varname>]`}
#' }
#' @param ... additional arguments to be saved as a list in `private$extras` field
#'
#' @keywords internal
Expand All @@ -28,8 +21,7 @@
#' slice = teal_slice(
#' varname = "x",
#' dataname = "dataname"
#' ),
#' extract_type = "matrix"
#' )
#' )
#'
#' shiny::isolate(filter_state$get_call())
Expand All @@ -52,21 +44,15 @@
#' @return `FilterState` object
init_filter_state <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
checkmate::assert_class(x_reactive, "reactive")
checkmate::assert_character(extract_type, max.len = 1, any.missing = FALSE)
checkmate::assert_class(slice, "teal_slice")
if (length(extract_type) == 1) {
checkmate::assert_choice(extract_type, choices = c("list", "matrix"))
}

if (all(is.na(x))) {
EmptyFilterState$new(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)
} else {
UseMethod("init_filter_state")
Expand All @@ -77,12 +63,10 @@ init_filter_state <- function(x,
#' @export
init_filter_state.default <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
args <- list(
x = x,
x_reactive = x_reactive,
extract_type = extract_type,
slice
)

Expand All @@ -93,27 +77,23 @@ init_filter_state.default <- function(x,
#' @export
init_filter_state.logical <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
LogicalFilterState$new(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)
}

#' @keywords internal
#' @export
init_filter_state.numeric <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
args <- list(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)

if (length(unique(x[!is.na(x)])) < getOption("teal.threshold_slider_vs_checkboxgroup")) {
Expand All @@ -127,41 +107,35 @@ init_filter_state.numeric <- function(x,
#' @export
init_filter_state.factor <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
ChoicesFilterState$new(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)
}

#' @keywords internal
#' @export
init_filter_state.character <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
ChoicesFilterState$new(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)
}

#' @keywords internal
#' @export
init_filter_state.Date <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
args <- list(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)

if (length(unique(x[!is.na(x)])) < getOption("teal.threshold_slider_vs_checkboxgroup")) {
Expand All @@ -175,13 +149,11 @@ init_filter_state.Date <- function(x,
#' @export
init_filter_state.POSIXct <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
args <- list(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)

if (length(unique(x[!is.na(x)])) < getOption("teal.threshold_slider_vs_checkboxgroup")) {
Expand All @@ -195,13 +167,11 @@ init_filter_state.POSIXct <- function(x,
#' @export
init_filter_state.POSIXlt <- function(x,
x_reactive = reactive(NULL),
slice,
extract_type = character(0)) {
slice) {
args <- list(
x = x,
x_reactive = x_reactive,
slice = slice,
extract_type = extract_type
slice = slice
)

if (length(unique(x[!is.na(x)])) < getOption("teal.threshold_slider_vs_checkboxgroup")) {
Expand Down
Loading
Loading