diff --git a/R/FilterState.R b/R/FilterState.R index 224385cf4..fafd2a15a 100644 --- a/R/FilterState.R +++ b/R/FilterState.R @@ -354,6 +354,25 @@ FilterState <- R6::R6Class( # nolint return(invisible(NULL)) }, + #' @description + #' Returns a formatted string representing this `FilterState`. + #' + #' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. + #' Default: 0 + #' @return `character(1)` the formatted string + #' + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + sprintf( + "%sFiltering on: %s\n%1$s Selected values: %s\n%1$s Include missing values: %s", + format("", width = indent), + self$get_varname(deparse = TRUE), + paste0(format(self$get_selected(), nsmall = 3), collapse = " "), + format(self$get_keep_na()) + ) + }, + #' @description #' Returns reproducible condition call for current selection relevant #' for selected variable type. @@ -370,7 +389,7 @@ FilterState <- R6::R6Class( # nolint #' @return (`name` or `character(1)`) get_dataname = function(deparse = TRUE) { if (isTRUE(deparse)) { - deparse(private$input_dataname) + deparse1(private$input_dataname) } else { private$input_dataname } @@ -397,7 +416,7 @@ FilterState <- R6::R6Class( # nolint #' @return (`name` or `character(1)`) get_varname = function(deparse = FALSE) { if (isTRUE(deparse)) { - deparse(private$varname) + deparse1(private$varname) } else { private$varname } @@ -424,6 +443,14 @@ FilterState <- R6::R6Class( # nolint ) }, + #' @description + #' Prints this `FilterState` object + #' + #' @param ... additional arguments to this method + print = function(...) { + cat(shiny::isolate(self$format()), "\n") + }, + #' @description #' Set if `NA` should be kept #' @param value (`logical(1)`)\cr @@ -1271,6 +1298,26 @@ RangeFilterState <- R6::R6Class( # nolint return(invisible(self)) }, + #' @description + #' Returns a formatted string representing this `LogicalFilterState`. + #' + #' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. + #' Default: 0 + #' @return `character(1)` the formatted string + #' + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + sprintf( + "%sFiltering on: %s\n%1$s Selected range: %s - %s\n%1$s Include missing values: %s", + format("", width = indent), + self$get_varname(deparse = TRUE), + format(self$get_selected(), nsmall = 3)[1], + format(self$get_selected(), nsmall = 3)[2], + format(self$get_keep_na()) + ) + }, + #' @description #' Answers the question of whether the current settings and values selected actually filters out any values. #' @return logical scalar @@ -2048,6 +2095,26 @@ DateFilterState <- R6::R6Class( # nolint return(invisible(self)) }, + #' @description + #' Returns a formatted string representing this `DateFilterState`. + #' + #' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. + #' Default: 0 + #' @return `character(1)` the formatted string + #' + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + sprintf( + "%sFiltering on: %s\n%1$s Selected range: %s - %s\n%1$s Include missing values: %s", + format("", width = indent), + self$get_varname(deparse = TRUE), + format(self$get_selected()[1], nsmall = 3), + format(self$get_selected()[2], nsmall = 3), + format(self$get_keep_na()) + ) + }, + #' @description #' Answers the question of whether the current settings and values selected actually filters out any values. #' @return logical scalar @@ -2346,6 +2413,26 @@ DatetimeFilterState <- R6::R6Class( # nolint return(invisible(self)) }, + #' @description + #' Returns a formatted string representing this `DatetimeFilterState`. + #' + #' @param indent (`numeric(1)`) the number of spaces before after each new line character of the formatted string. + #' Default: 0 + #' @return `character(1)` the formatted string + #' + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + sprintf( + "%sFiltering on: %s\n%1$s Selected range: %s - %s\n%1$s Include missing values: %s", + format("", width = indent), + self$get_varname(deparse = TRUE), + format(self$get_selected(), nsmall = 3)[1], + format(self$get_selected(), nsmall = 3)[2], + format(self$get_keep_na()) + ) + }, + #' @description #' Answers the question of whether the current settings and values selected actually filters out any values. #' @return logical scalar diff --git a/R/FilterStates.R b/R/FilterStates.R index bc112bcff..0d2fd9167 100644 --- a/R/FilterStates.R +++ b/R/FilterStates.R @@ -205,6 +205,24 @@ FilterStates <- R6::R6Class( # nolint logger::log_trace("Instantiated { class(self)[1] }, dataname: { deparse1(private$input_dataname) }") invisible(self) }, + + #' @description + #' Returns the label of the dataset + #' @return (`character(1)`) the label + get_datalabel = function() { + private$datalabel + }, + + #' @description + #' Returns the formatted string representing this `FilterStates` object. + #' + #' @param indent (`numeric(1)`) the number of spaces before each line of the representation + #' @return `character(1)` the formatted string + #' + format = function(indent) { + stop("Pure virtual method") + }, + #' @description #' Filter call #' @@ -276,6 +294,14 @@ FilterStates <- R6::R6Class( # nolint } }, + #' @description + #' Prints this `FilterStates` object + #' + #' @param ... additional arguments to this method + print = function(...) { + cat(shiny::isolate(self$format()), "\n") + }, + #' @description #' Gets the name of the function used to filter the data in this `FilterStates`. #' @@ -647,14 +673,15 @@ FilterStates <- R6::R6Class( # nolint ) ) -#' Specialization of `FilterStates` for a base `data.frame`. +#' @title `DFFFilterStates` +#' @description Specialization of `FilterStates` for a base `data.frame`. #' #' @keywords internal DFFilterStates <- R6::R6Class( # nolint classname = "DFFilterStates", inherit = FilterStates, public = list( - #' Initializes `DFFilterStates` object + #' @description Initializes `DFFilterStates` object #' #' Initializes `DFFilterStates` object by setting `input_dataname`, #' `output_dataname` and initializing `ReactiveQueue`. This class contains a @@ -689,6 +716,22 @@ DFFilterStates <- R6::R6Class( # nolint ) }, + #' @description + #' Returns the formatted string representing this `FilterStates` object. + #' + #' @param indent (`numeric(1)`) the number of spaces before each line of the representation + #' @return `character(1)` the formatted string + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + formatted_states <- vapply( + self$queue_get(1L), function(state) state$format(indent = indent), + USE.NAMES = FALSE, FUN.VALUE = character(1) + ) + paste(formatted_states, collapse = "\n") + }, + + #' @description #' Get function name #' #' Get function name used to create filter call. @@ -1041,13 +1084,14 @@ DFFilterStates <- R6::R6Class( # nolint ) -#' Specialization of `FilterStates` for `MultiAssayExperiment`. +#' @title `MAEFilterStates` +#' @description Specialization of `FilterStates` for `MultiAssayExperiment`. #' @keywords internal MAEFilterStates <- R6::R6Class( # nolint classname = "MAEFilterStates", inherit = FilterStates, public = list( - #' Initialize `MAEFilterStates` object + #' @description Initializes `MAEFilterStates` object #' #' Initialize `MAEFilterStates` object #' @@ -1082,11 +1126,24 @@ MAEFilterStates <- R6::R6Class( # nolint return(invisible(self)) }, - #' Get function name + #' @description + #' Returns the formatted string representing this `MAEFilterStates` object. #' - #' Get function name used to create filter call. - #' For `MAEFilterStates` - #' `MultiAssayExperiment::subsetByColData` is used. + #' @param indent (`numeric(1)`) the number of spaces before each line of the representation + #' @return `character(1)` the formatted string + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + if (length(self$queue_get(1L)) > 0) { + formatted_states <- sprintf("%sSubject filters:", format("", width = indent)) + for (state in self$queue_get(1L)) formatted_states <- c(formatted_states, state$format(indent = indent + 2)) + paste(formatted_states, collapse = "\n") + } + }, + + #' @description + #' Returns function name used to create filter call. + #' For `MAEFilterStates` `MultiAssayExperiment::subsetByColData` is used. #' @return `character(1)` get_fun = function() { return("MultiAssayExperiment::subsetByColData") @@ -1195,7 +1252,8 @@ MAEFilterStates <- R6::R6Class( # nolint NULL }, - #' @description Remove a variable from the `ReactiveQueue` and its corresponding UI element. + #' @description + #' Removes a variable from the `ReactiveQueue` and its corresponding UI element. #' #' @param element_id (`character(1)`)\cr name of `ReactiveQueue` element. #' @@ -1403,13 +1461,14 @@ MAEFilterStates <- R6::R6Class( # nolint ) ) -#' Specialization of `FilterStates` for `SummaryExperiment`. +#' @title `SEFilterStates` +#' @description Specialization of `FilterStates` for `SummaryExperiment`. #' @keywords internal SEFilterStates <- R6::R6Class( # nolint classname = "SEFilterStates", inherit = FilterStates, public = list( - #' Initialize `SEFilterStates` object + #' @description Initialize `SEFilterStates` object #' #' Initialize `SEFilterStates` object #' @@ -1435,6 +1494,36 @@ SEFilterStates <- R6::R6Class( # nolint ) }, + #' @description + #' Returns the formatted string representing this `MAEFilterStates` object. + #' + #' @param indent (`numeric(1)`) the number of spaces before each line of the representation + #' @return `character(1)` the formatted string + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + whitespace_indent <- format("", width = indent) + formatted_states <- c() + if (!is.null(self$queue_get(queue_index = "subset"))) { + formatted_states <- c(formatted_states, paste0(whitespace_indent, " Subsetting:")) + for (state in self$queue_get(queue_index = "subset")) { + formatted_states <- c(formatted_states, state$format(indent = indent + 4)) + } + } + + if (!is.null(self$queue_get(queue_index = "select"))) { + formatted_states <- c(formatted_states, paste0(whitespace_indent, " Selecting:")) + for (state in self$queue_get(queue_index = "select")) { + formatted_states <- c(formatted_states, state$format(indent = indent + 4)) + } + } + + if (length(formatted_states) > 0) { + formatted_states <- c(paste0(whitespace_indent, "Assay ", self$get_datalabel(), " filters:"), formatted_states) + paste(formatted_states, collapse = "\n") + } + }, + #' @description #' Server module #' @param id (`character(1)`)\cr @@ -1942,13 +2031,14 @@ SEFilterStates <- R6::R6Class( # nolint ) ) -#' Specialization of `FilterStates` for a base matrix. +#' @title `MatrixFilterStates` +#' @description Specialization of `FilterStates` for a base matrix. #' @keywords internal MatrixFilterStates <- R6::R6Class( # nolint classname = "MatrixFilterStates", inherit = FilterStates, public = list( - #' Initialize `MatrixFilterStates` object + #' @description Initialize `MatrixFilterStates` object #' #' Initialize `MatrixFilterStates` object #' @@ -1970,6 +2060,21 @@ MatrixFilterStates <- R6::R6Class( # nolint ) }, + #' @description + #' Returns the formatted string representing this `MatrixFilterStates` object. + #' + #' @param indent (`numeric(1)`) the number of spaces before each line of the representation + #' @return `character(1)` the formatted string + format = function(indent = 0) { + checkmate::assert_number(indent, finite = TRUE, lower = 0) + + formatted_states <- c() + for (state in self$queue_get(queue_index = "subset")) { + formatted_states <- c(formatted_states, state$format(indent = indent + 2)) + } + paste(formatted_states, collapse = "\n") + }, + #' @description #' Server module #' @param id (`character(1)`)\cr diff --git a/R/FilteredData.R b/R/FilteredData.R index 0988c27df..44f9f55fe 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -82,7 +82,6 @@ FilteredData <- R6::R6Class( # nolint names(private$filtered_datasets) }, - #' Gets data label for the dataset #' #' Useful to display in `Show R Code`. @@ -315,7 +314,6 @@ FilteredData <- R6::R6Class( # nolint intersect(self$datanames(), datanames) }, - #' @description #' Adds a `TealDataset` object to this `FilteredData` #' @@ -377,6 +375,40 @@ FilteredData <- R6::R6Class( # nolint Filter(function(x) length(x) > 0, states) }, + #' @description + #' Returns the filter state formatted for printing to an `IO` device. + #' + #' @return `character` the pre-formatted filter state + #' @examples + #' datasets <- teal.slice:::FilteredData$new() + #' datasets$set_dataset(teal.data::dataset("iris", iris)) + #' utils::data(miniACC, package = "MultiAssayExperiment") + #' datasets$set_dataset(teal.data::dataset("mae", 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())) + #' + get_formatted_filter_state = function() { + out <- c() + for (filtered_dataset in self$get_filtered_dataset()) out <- c(out, filtered_dataset$get_formatted_filter_state()) + paste(out, collapse = "\n") + }, + #' @description #' Sets active filter states. #' @param state (`named list`)\cr diff --git a/R/FilteredDataset.R b/R/FilteredDataset.R index 55cdaa29b..99c39a98c 100644 --- a/R/FilteredDataset.R +++ b/R/FilteredDataset.R @@ -166,6 +166,18 @@ FilteredDataset <- R6::R6Class( # nolint invisible(self) }, + + #' @description + #' Returns a string representation of the filter state in this `FilteredDataset`. + #' + #' @return `character(1)` the formatted string representing the filter state + #' + get_formatted_filter_state = function() { + out <- paste0("Filters for dataset: ", self$get_dataname()) + for (states in self$get_filter_states()) out <- c(out, states$format(indent = 2)) + paste(out, collapse = "\n") + }, + #' @description #' Adds objects to the filter call evaluation environment #' @param name (`character`) object name @@ -554,7 +566,6 @@ DefaultFilteredDataset <- R6::R6Class( # nolint #' @param dataset (`TealDataset`)\cr #' single dataset for which filters are rendered initialize = function(dataset) { - stopifnot(is(dataset, "TealDataset")) super$initialize(dataset) dataname <- dataset$get_dataname() @@ -591,6 +602,7 @@ DefaultFilteredDataset <- R6::R6Class( # nolint ) }, + #' @description #' Gets the reactive values from the active `FilterState` objects. #' #' Get all active filters from this dataset in form of the nested list. diff --git a/man/CDISCFilteredData.Rd b/man/CDISCFilteredData.Rd index d7c8dd97a..c6c35aaa0 100644 --- a/man/CDISCFilteredData.Rd +++ b/man/CDISCFilteredData.Rd @@ -124,6 +124,7 @@ isolate(datasets$get_call("ADTTE")) \item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_filter_overview}{\code{teal.slice::FilteredData$get_filter_overview()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_filter_state}{\code{teal.slice::FilteredData$get_filter_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_filtered_dataset}{\code{teal.slice::FilteredData$get_filtered_dataset()}}\out{} +\item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_formatted_filter_state}{\code{teal.slice::FilteredData$get_formatted_filter_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_join_keys}{\code{teal.slice::FilteredData$get_join_keys()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_keys}{\code{teal.slice::FilteredData$get_keys()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredData.html#method-get_metadata}{\code{teal.slice::FilteredData$get_metadata()}}\out{} diff --git a/man/CDISCFilteredDataset.Rd b/man/CDISCFilteredDataset.Rd index 0a9265d20..24062f66b 100644 --- a/man/CDISCFilteredDataset.Rd +++ b/man/CDISCFilteredDataset.Rd @@ -31,6 +31,7 @@ \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filter_states}{\code{teal.slice::FilteredDataset$get_filter_states()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filterable_varnames}{\code{teal.slice::FilteredDataset$get_filterable_varnames()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filtered_dataname}{\code{teal.slice::FilteredDataset$get_filtered_dataname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_formatted_filter_state}{\code{teal.slice::FilteredDataset$get_formatted_filter_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_hash}{\code{teal.slice::FilteredDataset$get_hash()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_join_keys}{\code{teal.slice::FilteredDataset$get_join_keys()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_keys}{\code{teal.slice::FilteredDataset$get_keys()}}\out{} diff --git a/man/ChoicesFilterState.Rd b/man/ChoicesFilterState.Rd index 6015d3066..d31b5747d 100644 --- a/man/ChoicesFilterState.Rd +++ b/man/ChoicesFilterState.Rd @@ -54,12 +54,14 @@ filter$set_selected(c("c", "a")) \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterState.html#method-destroy_observers}{\code{teal.slice::FilterState$destroy_observers()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-format}{\code{teal.slice::FilterState$format()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_dataname}{\code{teal.slice::FilterState$get_dataname()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_keep_na}{\code{teal.slice::FilterState$get_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_selected}{\code{teal.slice::FilterState$get_selected()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_state}{\code{teal.slice::FilterState$get_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varlabel}{\code{teal.slice::FilterState$get_varlabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varname}{\code{teal.slice::FilterState$get_varname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-print}{\code{teal.slice::FilterState$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na}{\code{teal.slice::FilterState$set_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na_reactive}{\code{teal.slice::FilterState$set_keep_na_reactive()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_na_rm}{\code{teal.slice::FilterState$set_na_rm()}}\out{} diff --git a/man/DFFilterStates.Rd b/man/DFFilterStates.Rd index a98679e4d..a96e246e5 100644 --- a/man/DFFilterStates.Rd +++ b/man/DFFilterStates.Rd @@ -2,10 +2,8 @@ % Please edit documentation in R/FilterStates.R \name{DFFilterStates} \alias{DFFilterStates} -\title{Specialization of \code{FilterStates} for a base \code{data.frame}.} +\title{\code{DFFFilterStates}} \description{ -Specialization of \code{FilterStates} for a base \code{data.frame}. - Specialization of \code{FilterStates} for a base \code{data.frame}. } \examples{ @@ -29,46 +27,7 @@ dffs$set_filter_state(state = fs, data = iris) shiny::isolate(dffs$get_filter_state()) } -\keyword{(`...`).} -\keyword{(`dplyr::filter`),} -\keyword{Initializes} -\keyword{This} -\keyword{`DFFilterStates`} -\keyword{`ReactiveQueue`} -\keyword{`ReactiveQueue`.} -\keyword{`input_dataname`,} -\keyword{`output_dataname`} -\keyword{a} -\keyword{and} -\keyword{are} -\keyword{arguments} -\keyword{associated} -\keyword{by} -\keyword{calling} -\keyword{class} -\keyword{conditions} -\keyword{contains} -\keyword{function} -\keyword{initializing} \keyword{internal} -\keyword{list} -\keyword{means} -\keyword{name} -\keyword{no} -\keyword{object} -\keyword{of} -\keyword{passed} -\keyword{setting} -\keyword{single} -\keyword{specified} -\keyword{that} -\keyword{the} -\keyword{this} -\keyword{to} -\keyword{unnamed} -\keyword{when} -\keyword{which} -\keyword{with} \section{Super class}{ \code{\link[teal.slice:FilterStates]{teal.slice::FilterStates}} -> \code{DFFilterStates} } @@ -76,6 +35,7 @@ shiny::isolate(dffs$get_filter_state()) \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{DFFilterStates$new()}} +\item \href{#method-format}{\code{DFFilterStates$format()}} \item \href{#method-get_fun}{\code{DFFilterStates$get_fun()}} \item \href{#method-server}{\code{DFFilterStates$server()}} \item \href{#method-get_filter_state}{\code{DFFilterStates$get_filter_state()}} @@ -90,6 +50,8 @@ shiny::isolate(dffs$get_filter_state()) \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_call}{\code{teal.slice::FilterStates$get_call()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_datalabel}{\code{teal.slice::FilterStates$get_datalabel()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-print}{\code{teal.slice::FilterStates$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_empty}{\code{teal.slice::FilterStates$queue_empty()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_get}{\code{teal.slice::FilterStates$queue_get()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_initialize}{\code{teal.slice::FilterStates$queue_initialize()}}\out{} @@ -103,6 +65,13 @@ shiny::isolate(dffs$get_filter_state()) \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-new}{}}} \subsection{Method \code{new()}}{ +Initializes \code{DFFilterStates} object + +Initializes \code{DFFilterStates} object by setting \code{input_dataname}, +\code{output_dataname} and initializing \code{ReactiveQueue}. This class contains a +single \code{ReactiveQueue} with no specified name which means that +when calling the function associated to this class (\code{dplyr::filter}), a list of +conditions are passed to unnamed arguments (\code{...}). \subsection{Usage}{ \if{html}{\out{
}}\preformatted{DFFilterStates$new(input_dataname, output_dataname, datalabel, varlabels, keys)}\if{html}{\out{
}} } @@ -124,19 +93,39 @@ text label value.} labels of the variables used in this object} \item{\code{keys}}{(\code{character})\cr -key columns names -Get function name +key columns names} +} +\if{html}{\out{}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns the formatted string representing this \code{FilterStates} object. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DFFilterStates$format(indent = 0)}\if{html}{\out{
}} +} -Get function name used to create filter call. -For \code{DFFilterStates} \code{dplyr::filter} is used} +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before each line of the representation} } \if{html}{\out{
}} } +\subsection{Returns}{ +\code{character(1)} the formatted string +} } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-get_fun}{}}} \subsection{Method \code{get_fun()}}{ +Get function name + +Get function name used to create filter call. +For \code{DFFilterStates} \code{dplyr::filter} is used \subsection{Usage}{ \if{html}{\out{
}}\preformatted{DFFilterStates$get_fun()}\if{html}{\out{
}} } diff --git a/man/DateFilterState.Rd b/man/DateFilterState.Rd index 503778783..3482f11c2 100644 --- a/man/DateFilterState.Rd +++ b/man/DateFilterState.Rd @@ -45,6 +45,7 @@ filter$set_selected(c(date + 1, date + 2)) \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{DateFilterState$new()}} +\item \href{#method-format}{\code{DateFilterState$format()}} \item \href{#method-is_any_filtered}{\code{DateFilterState$is_any_filtered()}} \item \href{#method-get_call}{\code{DateFilterState$get_call()}} \item \href{#method-ui}{\code{DateFilterState$ui()}} @@ -63,6 +64,7 @@ filter$set_selected(c(date + 1, date + 2)) \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_state}{\code{teal.slice::FilterState$get_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varlabel}{\code{teal.slice::FilterState$get_varlabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varname}{\code{teal.slice::FilterState$get_varname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-print}{\code{teal.slice::FilterState$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na}{\code{teal.slice::FilterState$set_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na_reactive}{\code{teal.slice::FilterState$set_keep_na_reactive()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_na_rm}{\code{teal.slice::FilterState$set_na_rm()}}\out{} @@ -114,6 +116,27 @@ whether condition calls should be prefixed by dataname. Possible values: } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns a formatted string representing this \code{DateFilterState}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DateFilterState$format(indent = 0)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before after each new line character of the formatted string. +Default: 0} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-is_any_filtered}{}}} \subsection{Method \code{is_any_filtered()}}{ diff --git a/man/DatetimeFilterState.Rd b/man/DatetimeFilterState.Rd index 90d55fd39..feaf0c80e 100644 --- a/man/DatetimeFilterState.Rd +++ b/man/DatetimeFilterState.Rd @@ -45,6 +45,7 @@ filter$set_selected(c(date + 1, date + 2)) \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{DatetimeFilterState$new()}} +\item \href{#method-format}{\code{DatetimeFilterState$format()}} \item \href{#method-is_any_filtered}{\code{DatetimeFilterState$is_any_filtered()}} \item \href{#method-get_call}{\code{DatetimeFilterState$get_call()}} \item \href{#method-ui}{\code{DatetimeFilterState$ui()}} @@ -63,6 +64,7 @@ filter$set_selected(c(date + 1, date + 2)) \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_state}{\code{teal.slice::FilterState$get_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varlabel}{\code{teal.slice::FilterState$get_varlabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varname}{\code{teal.slice::FilterState$get_varname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-print}{\code{teal.slice::FilterState$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na}{\code{teal.slice::FilterState$set_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na_reactive}{\code{teal.slice::FilterState$set_keep_na_reactive()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_na_rm}{\code{teal.slice::FilterState$set_na_rm()}}\out{} @@ -118,6 +120,27 @@ whether condition calls should be prefixed by dataname. Possible values: } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns a formatted string representing this \code{DatetimeFilterState}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DatetimeFilterState$format(indent = 0)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before after each new line character of the formatted string. +Default: 0} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-is_any_filtered}{}}} \subsection{Method \code{is_any_filtered()}}{ diff --git a/man/DefaultFilteredDataset.Rd b/man/DefaultFilteredDataset.Rd index 338c4023d..2c6f9f030 100644 --- a/man/DefaultFilteredDataset.Rd +++ b/man/DefaultFilteredDataset.Rd @@ -66,6 +66,7 @@ shiny::isolate(dataset$get_filter_state()) \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filter_states}{\code{teal.slice::FilteredDataset$get_filter_states()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filterable_varnames}{\code{teal.slice::FilteredDataset$get_filterable_varnames()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filtered_dataname}{\code{teal.slice::FilteredDataset$get_filtered_dataname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_formatted_filter_state}{\code{teal.slice::FilteredDataset$get_formatted_filter_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_hash}{\code{teal.slice::FilteredDataset$get_hash()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_join_keys}{\code{teal.slice::FilteredDataset$get_join_keys()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_keys}{\code{teal.slice::FilteredDataset$get_keys()}}\out{} @@ -114,16 +115,16 @@ applies to one argument (\code{...}) in \code{dplyr::filter} call. \subsection{Returns}{ filter \code{call} or \code{list} of filter calls -Gets the reactive values from the active \code{FilterState} objects. - -Get all active filters from this dataset in form of the nested list. -The output list is a compatible input to \code{self$set_filter_state}. } } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-get_filter_state}{}}} \subsection{Method \code{get_filter_state()}}{ +Gets the reactive values from the active \code{FilterState} objects. + +Get all active filters from this dataset in form of the nested list. +The output list is a compatible input to \code{self$set_filter_state}. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{DefaultFilteredDataset$get_filter_state()}\if{html}{\out{
}} } diff --git a/man/EmptyFilterState.Rd b/man/EmptyFilterState.Rd index f980b1a74..a0ba1fa13 100644 --- a/man/EmptyFilterState.Rd +++ b/man/EmptyFilterState.Rd @@ -42,11 +42,13 @@ isolate(filter_state$get_call()) \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterState.html#method-destroy_observers}{\code{teal.slice::FilterState$destroy_observers()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-format}{\code{teal.slice::FilterState$format()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_dataname}{\code{teal.slice::FilterState$get_dataname()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_keep_na}{\code{teal.slice::FilterState$get_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_selected}{\code{teal.slice::FilterState$get_selected()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varlabel}{\code{teal.slice::FilterState$get_varlabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varname}{\code{teal.slice::FilterState$get_varname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-print}{\code{teal.slice::FilterState$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na}{\code{teal.slice::FilterState$set_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na_reactive}{\code{teal.slice::FilterState$set_keep_na_reactive()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_na_rm}{\code{teal.slice::FilterState$set_na_rm()}}\out{} diff --git a/man/FilterState.Rd b/man/FilterState.Rd index 06659864b..889213bbe 100644 --- a/man/FilterState.Rd +++ b/man/FilterState.Rd @@ -57,6 +57,7 @@ or using \code{set_selected}, \code{set_keep_na} or \code{set_keep_inf} \itemize{ \item \href{#method-new}{\code{FilterState$new()}} \item \href{#method-destroy_observers}{\code{FilterState$destroy_observers()}} +\item \href{#method-format}{\code{FilterState$format()}} \item \href{#method-get_call}{\code{FilterState$get_call()}} \item \href{#method-get_dataname}{\code{FilterState$get_dataname()}} \item \href{#method-get_keep_na}{\code{FilterState$get_keep_na()}} @@ -64,6 +65,7 @@ or using \code{set_selected}, \code{set_keep_na} or \code{set_keep_inf} \item \href{#method-get_varname}{\code{FilterState$get_varname()}} \item \href{#method-get_selected}{\code{FilterState$get_selected()}} \item \href{#method-get_state}{\code{FilterState$get_state()}} +\item \href{#method-print}{\code{FilterState$print()}} \item \href{#method-set_keep_na}{\code{FilterState$set_keep_na()}} \item \href{#method-set_keep_na_reactive}{\code{FilterState$set_keep_na_reactive()}} \item \href{#method-set_na_rm}{\code{FilterState$set_na_rm()}} @@ -127,6 +129,27 @@ Destroy observers stored in \code{private$observers}. \if{html}{\out{
}}\preformatted{FilterState$destroy_observers()}\if{html}{\out{
}} } +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns a formatted string representing this \code{FilterState}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilterState$format(indent = 0)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before after each new line character of the formatted string. +Default: 0} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} } \if{html}{\out{
}} \if{html}{\out{}} @@ -240,6 +263,23 @@ Returns the filtering state. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-print}{}}} +\subsection{Method \code{print()}}{ +Prints this \code{FilterState} object +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilterState$print(...)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{...}}{additional arguments to this method} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-set_keep_na}{}}} \subsection{Method \code{set_keep_na()}}{ diff --git a/man/FilterStates.Rd b/man/FilterStates.Rd index ea303ed6d..3924005e4 100644 --- a/man/FilterStates.Rd +++ b/man/FilterStates.Rd @@ -45,7 +45,10 @@ isolate(filter_states$get_call()) \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{FilterStates$new()}} +\item \href{#method-get_datalabel}{\code{FilterStates$get_datalabel()}} +\item \href{#method-format}{\code{FilterStates$format()}} \item \href{#method-get_call}{\code{FilterStates$get_call()}} +\item \href{#method-print}{\code{FilterStates$print()}} \item \href{#method-get_fun}{\code{FilterStates$get_fun()}} \item \href{#method-queue_empty}{\code{FilterStates$queue_empty()}} \item \href{#method-queue_get}{\code{FilterStates$queue_get()}} @@ -87,6 +90,39 @@ text label value.} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-get_datalabel}{}}} +\subsection{Method \code{get_datalabel()}}{ +Returns the label of the dataset +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilterStates$get_datalabel()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +(\code{character(1)}) the label +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns the formatted string representing this \code{FilterStates} object. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilterStates$format(indent)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before each line of the representation} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-get_call}{}}} \subsection{Method \code{get_call()}}{ @@ -108,6 +144,23 @@ no-op call such as \code{x <- x}. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-print}{}}} +\subsection{Method \code{print()}}{ +Prints this \code{FilterStates} object +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilterStates$print(...)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{...}}{additional arguments to this method} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-get_fun}{}}} \subsection{Method \code{get_fun()}}{ diff --git a/man/FilteredData.Rd b/man/FilteredData.Rd index 1c190df3f..509f03d93 100644 --- a/man/FilteredData.Rd +++ b/man/FilteredData.Rd @@ -72,6 +72,34 @@ isolate(datasets$get_filter_overview("mtcars")) isolate(datasets$get_call("iris")) isolate(datasets$get_call("mtcars")) +## ------------------------------------------------ +## Method `FilteredData$get_formatted_filter_state` +## ------------------------------------------------ + +datasets <- teal.slice:::FilteredData$new() +datasets$set_dataset(teal.data::dataset("iris", iris)) +utils::data(miniACC, package = "MultiAssayExperiment") +datasets$set_dataset(teal.data::dataset("mae", 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())) + + ## ------------------------------------------------ ## Method `FilteredData$set_filter_state` ## ------------------------------------------------ @@ -125,6 +153,7 @@ shiny::isolate(datasets$get_filter_state()) \item \href{#method-set_check}{\code{FilteredData$set_check()}} \item \href{#method-set_code}{\code{FilteredData$set_code()}} \item \href{#method-get_filter_state}{\code{FilteredData$get_filter_state()}} +\item \href{#method-get_formatted_filter_state}{\code{FilteredData$get_formatted_filter_state()}} \item \href{#method-set_filter_state}{\code{FilteredData$set_filter_state()}} \item \href{#method-remove_filter_state}{\code{FilteredData$remove_filter_state()}} \item \href{#method-remove_all_filter_states}{\code{FilteredData$remove_all_filter_states()}} @@ -599,6 +628,49 @@ The output list is a compatible input to \code{self$set_filter_state}. \code{list} with named elements corresponding to \code{FilteredDataset} objects with active filters. } +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-get_formatted_filter_state}{}}} +\subsection{Method \code{get_formatted_filter_state()}}{ +Returns the filter state formatted for printing to an \code{IO} device. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilteredData$get_formatted_filter_state()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +\code{character} the pre-formatted filter state +} +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{datasets <- teal.slice:::FilteredData$new() +datasets$set_dataset(teal.data::dataset("iris", iris)) +utils::data(miniACC, package = "MultiAssayExperiment") +datasets$set_dataset(teal.data::dataset("mae", 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())) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/FilteredDataset.Rd b/man/FilteredDataset.Rd index ac0316f98..f1dd33abe 100644 --- a/man/FilteredDataset.Rd +++ b/man/FilteredDataset.Rd @@ -15,6 +15,7 @@ components of the \code{TealDataset}. \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{FilteredDataset$new()}} +\item \href{#method-get_formatted_filter_state}{\code{FilteredDataset$get_formatted_filter_state()}} \item \href{#method-add_to_eval_env}{\code{FilteredDataset$add_to_eval_env()}} \item \href{#method-queues_empty}{\code{FilteredDataset$queues_empty()}} \item \href{#method-get_call}{\code{FilteredDataset$get_call()}} @@ -59,6 +60,19 @@ single dataset for which filters are rendered} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-get_formatted_filter_state}{}}} +\subsection{Method \code{get_formatted_filter_state()}}{ +Returns a string representation of the filter state in this \code{FilteredDataset}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{FilteredDataset$get_formatted_filter_state()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +\code{character(1)} the formatted string representing the filter state +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-add_to_eval_env}{}}} \subsection{Method \code{add_to_eval_env()}}{ diff --git a/man/LogicalFilterState.Rd b/man/LogicalFilterState.Rd index a2687d15f..a8fbb364b 100644 --- a/man/LogicalFilterState.Rd +++ b/man/LogicalFilterState.Rd @@ -56,12 +56,14 @@ filter$set_selected(TRUE) \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterState.html#method-destroy_observers}{\code{teal.slice::FilterState$destroy_observers()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-format}{\code{teal.slice::FilterState$format()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_dataname}{\code{teal.slice::FilterState$get_dataname()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_keep_na}{\code{teal.slice::FilterState$get_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_selected}{\code{teal.slice::FilterState$get_selected()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_state}{\code{teal.slice::FilterState$get_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varlabel}{\code{teal.slice::FilterState$get_varlabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varname}{\code{teal.slice::FilterState$get_varname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-print}{\code{teal.slice::FilterState$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na}{\code{teal.slice::FilterState$set_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na_reactive}{\code{teal.slice::FilterState$set_keep_na_reactive()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_na_rm}{\code{teal.slice::FilterState$set_na_rm()}}\out{} diff --git a/man/MAEFilterStates.Rd b/man/MAEFilterStates.Rd index 94d117602..c5c333c0a 100644 --- a/man/MAEFilterStates.Rd +++ b/man/MAEFilterStates.Rd @@ -2,16 +2,11 @@ % Please edit documentation in R/FilterStates.R \name{MAEFilterStates} \alias{MAEFilterStates} -\title{Specialization of \code{FilterStates} for \code{MultiAssayExperiment}.} +\title{\code{MAEFilterStates}} \description{ -Specialization of \code{FilterStates} for \code{MultiAssayExperiment}. - Specialization of \code{FilterStates} for \code{MultiAssayExperiment}. } -\keyword{Initialize} -\keyword{`MAEFilterStates`} \keyword{internal} -\keyword{object} \section{Super class}{ \code{\link[teal.slice:FilterStates]{teal.slice::FilterStates}} -> \code{MAEFilterStates} } @@ -19,6 +14,7 @@ Specialization of \code{FilterStates} for \code{MultiAssayExperiment}. \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{MAEFilterStates$new()}} +\item \href{#method-format}{\code{MAEFilterStates$format()}} \item \href{#method-get_fun}{\code{MAEFilterStates$get_fun()}} \item \href{#method-server}{\code{MAEFilterStates$server()}} \item \href{#method-get_filter_state}{\code{MAEFilterStates$get_filter_state()}} @@ -33,6 +29,8 @@ Specialization of \code{FilterStates} for \code{MultiAssayExperiment}. \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_call}{\code{teal.slice::FilterStates$get_call()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_datalabel}{\code{teal.slice::FilterStates$get_datalabel()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-print}{\code{teal.slice::FilterStates$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_empty}{\code{teal.slice::FilterStates$queue_empty()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_get}{\code{teal.slice::FilterStates$queue_get()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_initialize}{\code{teal.slice::FilterStates$queue_initialize()}}\out{} @@ -46,6 +44,9 @@ Specialization of \code{FilterStates} for \code{MultiAssayExperiment}. \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-new}{}}} \subsection{Method \code{new()}}{ +Initializes \code{MAEFilterStates} object + +Initialize \code{MAEFilterStates} object \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MAEFilterStates$new( input_dataname, @@ -73,20 +74,37 @@ text label value.} labels of the variables used in this object} \item{\code{keys}}{(\code{character})\cr -key columns names -Get function name +key columns names} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns the formatted string representing this \code{MAEFilterStates} object. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{MAEFilterStates$format(indent = 0)}\if{html}{\out{
}} +} -Get function name used to create filter call. -For \code{MAEFilterStates} -\code{MultiAssayExperiment::subsetByColData} is used.} +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before each line of the representation} } \if{html}{\out{
}} } +\subsection{Returns}{ +\code{character(1)} the formatted string +} } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-get_fun}{}}} \subsection{Method \code{get_fun()}}{ +Returns function name used to create filter call. +For \code{MAEFilterStates} \code{MultiAssayExperiment::subsetByColData} is used. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MAEFilterStates$get_fun()}\if{html}{\out{
}} } @@ -164,7 +182,7 @@ column in \code{colData(data)}.} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-remove_filter_state}{}}} \subsection{Method \code{remove_filter_state()}}{ -Remove a variable from the \code{ReactiveQueue} and its corresponding UI element. +Removes a variable from the \code{ReactiveQueue} and its corresponding UI element. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MAEFilterStates$remove_filter_state(element_id)}\if{html}{\out{
}} } diff --git a/man/MAEFilteredDataset.Rd b/man/MAEFilteredDataset.Rd index fd5cc43a1..53471ce4f 100644 --- a/man/MAEFilteredDataset.Rd +++ b/man/MAEFilteredDataset.Rd @@ -60,6 +60,7 @@ shiny::isolate(dataset$get_filter_state()) \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filter_state}{\code{teal.slice::FilteredDataset$get_filter_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filter_states}{\code{teal.slice::FilteredDataset$get_filter_states()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_filtered_dataname}{\code{teal.slice::FilteredDataset$get_filtered_dataname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_formatted_filter_state}{\code{teal.slice::FilteredDataset$get_formatted_filter_state()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_hash}{\code{teal.slice::FilteredDataset$get_hash()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_join_keys}{\code{teal.slice::FilteredDataset$get_join_keys()}}\out{} \item \out{}\href{../../teal.slice/html/FilteredDataset.html#method-get_keys}{\code{teal.slice::FilteredDataset$get_keys()}}\out{} diff --git a/man/MatrixFilterStates.Rd b/man/MatrixFilterStates.Rd index 6504872ae..200cd79ba 100644 --- a/man/MatrixFilterStates.Rd +++ b/man/MatrixFilterStates.Rd @@ -2,16 +2,11 @@ % Please edit documentation in R/FilterStates.R \name{MatrixFilterStates} \alias{MatrixFilterStates} -\title{Specialization of \code{FilterStates} for a base matrix.} +\title{\code{MatrixFilterStates}} \description{ -Specialization of \code{FilterStates} for a base matrix. - Specialization of \code{FilterStates} for a base matrix. } -\keyword{Initialize} -\keyword{`MatrixFilterStates`} \keyword{internal} -\keyword{object} \section{Super class}{ \code{\link[teal.slice:FilterStates]{teal.slice::FilterStates}} -> \code{MatrixFilterStates} } @@ -19,6 +14,7 @@ Specialization of \code{FilterStates} for a base matrix. \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{MatrixFilterStates$new()}} +\item \href{#method-format}{\code{MatrixFilterStates$format()}} \item \href{#method-server}{\code{MatrixFilterStates$server()}} \item \href{#method-get_filter_state}{\code{MatrixFilterStates$get_filter_state()}} \item \href{#method-set_filter_state}{\code{MatrixFilterStates$set_filter_state()}} @@ -32,7 +28,9 @@ Specialization of \code{FilterStates} for a base matrix. \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_call}{\code{teal.slice::FilterStates$get_call()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_datalabel}{\code{teal.slice::FilterStates$get_datalabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_fun}{\code{teal.slice::FilterStates$get_fun()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-print}{\code{teal.slice::FilterStates$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_empty}{\code{teal.slice::FilterStates$queue_empty()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_get}{\code{teal.slice::FilterStates$queue_get()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_initialize}{\code{teal.slice::FilterStates$queue_initialize()}}\out{} @@ -46,6 +44,9 @@ Specialization of \code{FilterStates} for a base matrix. \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-new}{}}} \subsection{Method \code{new()}}{ +Initialize \code{MatrixFilterStates} object + +Initialize \code{MatrixFilterStates} object \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MatrixFilterStates$new(input_dataname, output_dataname, datalabel)}\if{html}{\out{
}} } @@ -67,6 +68,26 @@ text label value.} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns the formatted string representing this \code{MatrixFilterStates} object. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{MatrixFilterStates$format(indent = 0)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before each line of the representation} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-server}{}}} \subsection{Method \code{server()}}{ diff --git a/man/RangeFilterState.Rd b/man/RangeFilterState.Rd index 010c8ad03..eb48df770 100644 --- a/man/RangeFilterState.Rd +++ b/man/RangeFilterState.Rd @@ -45,6 +45,7 @@ filter$set_selected(c(2, 3)) \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{RangeFilterState$new()}} +\item \href{#method-format}{\code{RangeFilterState$format()}} \item \href{#method-is_any_filtered}{\code{RangeFilterState$is_any_filtered()}} \item \href{#method-get_call}{\code{RangeFilterState$get_call()}} \item \href{#method-get_keep_inf}{\code{RangeFilterState$get_keep_inf()}} @@ -68,6 +69,7 @@ filter$set_selected(c(2, 3)) \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_selected}{\code{teal.slice::FilterState$get_selected()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varlabel}{\code{teal.slice::FilterState$get_varlabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-get_varname}{\code{teal.slice::FilterState$get_varname()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterState.html#method-print}{\code{teal.slice::FilterState$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na}{\code{teal.slice::FilterState$set_keep_na()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_keep_na_reactive}{\code{teal.slice::FilterState$set_keep_na_reactive()}}\out{} \item \out{}\href{../../teal.slice/html/FilterState.html#method-set_na_rm}{\code{teal.slice::FilterState$set_na_rm()}}\out{} @@ -117,6 +119,27 @@ whether condition calls should be prefixed by dataname. Possible values: } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns a formatted string representing this \code{LogicalFilterState}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{RangeFilterState$format(indent = 0)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before after each new line character of the formatted string. +Default: 0} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-is_any_filtered}{}}} \subsection{Method \code{is_any_filtered()}}{ diff --git a/man/SEFilterStates.Rd b/man/SEFilterStates.Rd index c970579ab..89550d7f2 100644 --- a/man/SEFilterStates.Rd +++ b/man/SEFilterStates.Rd @@ -2,16 +2,11 @@ % Please edit documentation in R/FilterStates.R \name{SEFilterStates} \alias{SEFilterStates} -\title{Specialization of \code{FilterStates} for \code{SummaryExperiment}.} +\title{\code{SEFilterStates}} \description{ -Specialization of \code{FilterStates} for \code{SummaryExperiment}. - Specialization of \code{FilterStates} for \code{SummaryExperiment}. } -\keyword{Initialize} -\keyword{`SEFilterStates`} \keyword{internal} -\keyword{object} \section{Super class}{ \code{\link[teal.slice:FilterStates]{teal.slice::FilterStates}} -> \code{SEFilterStates} } @@ -19,6 +14,7 @@ Specialization of \code{FilterStates} for \code{SummaryExperiment}. \subsection{Public methods}{ \itemize{ \item \href{#method-new}{\code{SEFilterStates$new()}} +\item \href{#method-format}{\code{SEFilterStates$format()}} \item \href{#method-server}{\code{SEFilterStates$server()}} \item \href{#method-get_filter_state}{\code{SEFilterStates$get_filter_state()}} \item \href{#method-set_filter_state}{\code{SEFilterStates$set_filter_state()}} @@ -32,7 +28,9 @@ Specialization of \code{FilterStates} for \code{SummaryExperiment}. \out{
Inherited methods} \itemize{ \item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_call}{\code{teal.slice::FilterStates$get_call()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_datalabel}{\code{teal.slice::FilterStates$get_datalabel()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-get_fun}{\code{teal.slice::FilterStates$get_fun()}}\out{} +\item \out{}\href{../../teal.slice/html/FilterStates.html#method-print}{\code{teal.slice::FilterStates$print()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_empty}{\code{teal.slice::FilterStates$queue_empty()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_get}{\code{teal.slice::FilterStates$queue_get()}}\out{} \item \out{}\href{../../teal.slice/html/FilterStates.html#method-queue_initialize}{\code{teal.slice::FilterStates$queue_initialize()}}\out{} @@ -46,6 +44,9 @@ Specialization of \code{FilterStates} for \code{SummaryExperiment}. \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-new}{}}} \subsection{Method \code{new()}}{ +Initialize \code{SEFilterStates} object + +Initialize \code{SEFilterStates} object \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SEFilterStates$new(input_dataname, output_dataname, datalabel)}\if{html}{\out{
}} } @@ -67,6 +68,26 @@ text label value.} } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-format}{}}} +\subsection{Method \code{format()}}{ +Returns the formatted string representing this \code{MAEFilterStates} object. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{SEFilterStates$format(indent = 0)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{indent}}{(\code{numeric(1)}) the number of spaces before each line of the representation} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +\code{character(1)} the formatted string +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-server}{}}} \subsection{Method \code{server()}}{ diff --git a/tests/testthat/test-DFFilterStates.R b/tests/testthat/test-DFFilterStates.R index ea4e0e5b5..4c98cb8a1 100644 --- a/tests/testthat/test-DFFilterStates.R +++ b/tests/testthat/test-DFFilterStates.R @@ -255,3 +255,49 @@ testthat::test_that( testthat::expect_identical(dffs$ui_add_filter_state("id", data.frame(A = numeric(0))), div("no samples available")) } ) + +# Format +testthat::test_that("$format() is a method of DFFilterStates", { + testthat::expect_error(DFFilterStates$new( + input_dataname = "test", + output_dataname = "test", + datalabel = character(0), + varlabels = "test", + keys = "test" + )$format(), NA) +}) + +testthat::test_that("$format() asserts the indent argument is a number", { + testthat::expect_error( + DFFilterStates$new( + input_dataname = "test", + output_dataname = "test", + datalabel = character(0), + varlabels = "test", + keys = "test" + )$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() concatenates its FilterState elements using \\n without additional indent", { + dffs <- DFFilterStates$new( + input_dataname = "iris", + output_dataname = "iris_filtered", + datalabel = character(0), + varlabels = character(0), + keys = character(0) + ) + fs <- list( + Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = TRUE), + Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE) + ) + dffs$set_filter_state(state = fs, data = iris) + + sepal_filter <- dffs$queue_get(1L)[[1]] + species_filter <- dffs$queue_get(1L)[[2]] + shiny::isolate(testthat::expect_equal( + dffs$format(), + paste(sepal_filter$format(indent = 0), species_filter$format(indent = 0), sep = "\n") + )) +}) diff --git a/tests/testthat/test-DateFilterState.R b/tests/testthat/test-DateFilterState.R index 3a36b5735..33dad5208 100644 --- a/tests/testthat/test-DateFilterState.R +++ b/tests/testthat/test-DateFilterState.R @@ -199,3 +199,50 @@ testthat::test_that( ) } ) + +# Format +testthat::test_that("$format() is a FilterStates's method that accepts indent", { + test_date <- as.Date("13/07/2013", format = "%d/%m/%y") + filter_state <- DateFilterState$new(test_date, varname = "test_date") + testthat::expect_error(shiny::isolate(filter_state$format(indent = 0)), regexp = NA) +}) + +testthat::test_that("$format() asserts that indent is numeric", { + test_date <- as.Date("13/07/2013", format = "%d/%m/%y") + filter_state <- DateFilterState$new(test_date, varname = "test_date") + testthat::expect_error( + filter_state$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() returns a string representation the FilterState object", { + test_date <- as.Date("13/07/2013", format = "%d/%m/%y") + filter_state <- DateFilterState$new(test_date, varname = "test") + filter_state$set_state(list(selected = c(test_date, test_date))) + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = 0)), + paste( + "Filtering on: test", + " Selected range: 2020-07-13 - 2020-07-13", + " Include missing values: FALSE", + sep = "\n" + ) + ) +}) + +testthat::test_that("$format() prepends spaces to every line of the returned string", { + test_date <- as.Date("13/07/2013", format = "%d/%m/%y") + filter_state <- DateFilterState$new(test_date, varname = "test") + filter_state$set_state(list(selected = c(test_date, test_date))) + for (i in 1:3) { + whitespace_indent <- paste0(rep(" ", i), collapse = "") + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = !!(i))), + sprintf( + "%sFiltering on: test\n%1$s Selected range: 2020-07-13 - 2020-07-13\n%1$s Include missing values: FALSE", + format("", width = i) + ) + ) + } +}) diff --git a/tests/testthat/test-DatetimeFilterState.R b/tests/testthat/test-DatetimeFilterState.R index a5d1f690b..dec4cacdf 100644 --- a/tests/testthat/test-DatetimeFilterState.R +++ b/tests/testthat/test-DatetimeFilterState.R @@ -211,3 +211,55 @@ testthat::test_that( ) } ) + +# Format +testthat::test_that("$format() is a FilterStates's method that accepts indent", { + object <- as.POSIXct(8, origin = "1900/01/01", tz = "GMT") + filter_state <- DatetimeFilterState$new(object, varname = "test") + testthat::expect_error(shiny::isolate(filter_state$format(indent = 0)), regexp = NA) +}) + +testthat::test_that("$format() asserts that indent is numeric", { + object <- as.POSIXct(8, origin = "1900/01/01", tz = "GMT") + filter_state <- DatetimeFilterState$new(object, varname = "test") + testthat::expect_error( + filter_state$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() returns a string representation the FilterState object", { + object <- as.POSIXct(8, origin = "1900/01/01", tz = "GMT") + filter_state <- DatetimeFilterState$new(object, varname = "test") + filter_state$set_state(list(selected = c(object, object))) + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = 0)), + paste( + "Filtering on: test", + " Selected range: 1900-01-01 00:00:08 - 1900-01-01 00:00:08", + " Include missing values: FALSE", + sep = "\n" + ) + ) +}) + +testthat::test_that("$format() prepends spaces to every line of the returned string", { + object <- as.POSIXct(8, origin = "1900/01/01", tz = "GMT") + filter_state <- DatetimeFilterState$new(object, varname = "test") + filter_state$set_state(list(selected = c(object, object))) + for (i in 1:3) { + whitespace_indent <- paste0(rep(" ", i), collapse = "") + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = !!(i))), + sprintf( + paste( + "%sFiltering on: test", + "%1$s Selected range: 1900-01-01 00:00:08 - 1900-01-01 00:00:08", + "%1$s Include missing values: FALSE", + sep = "\n" + ), + format("", width = i) + ) + ) + } +}) diff --git a/tests/testthat/test-FilterState.R b/tests/testthat/test-FilterState.R index 853914d71..958e3da8e 100644 --- a/tests/testthat/test-FilterState.R +++ b/tests/testthat/test-FilterState.R @@ -199,3 +199,44 @@ testthat::test_that( ) } ) + +# Format +testthat::test_that("$format() is a FilterStates's method that accepts indent", { + testthat::expect_error(shiny::isolate(FilterState$new(c(7), varname = "test")$format(indent = 0)), regexp = NA) +}) + +testthat::test_that("$format() asserts that indent is numeric", { + testthat::expect_error( + FilterState$new(c(7), varname = "test")$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() returns a string representation the FilterState object", { + filter_state <- FilterState$new(c(7), varname = "test") + filter_state$set_state(list(selected = c(7, 7))) + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = 0)), + paste( + "Filtering on: test", + " Selected values: 7.000 7.000", + " Include missing values: FALSE", + sep = "\n" + ) + ) +}) + +testthat::test_that("$format() prepends spaces to every line of the returned string", { + filter_state <- FilterState$new(c(7), varname = "test") + filter_state$set_state(list(selected = c(7, 7))) + for (i in 1:3) { + whitespace_indent <- paste0(rep(" ", i), collapse = "") + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = !!(i))), + sprintf( + "%sFiltering on: test\n%1$s Selected values: 7.000 7.000\n%1$s Include missing values: FALSE", + format("", width = i) + ) + ) + } +}) diff --git a/tests/testthat/test-FilteredDataset.R b/tests/testthat/test-FilteredDataset.R index 6a456a87a..f5374ee26 100644 --- a/tests/testthat/test-FilteredDataset.R +++ b/tests/testthat/test-FilteredDataset.R @@ -140,3 +140,19 @@ testthat::test_that("get_metadata returns the metadata of the data passed to the ) testthat::expect_null(filtered_dataset$get_metadata()) }) + +# Format +testthat::test_that("$get_formatted_filter_state returns a string representation of filters", { + dataset <- DefaultFilteredDataset$new(teal.data::dataset("iris", iris)) + fs <- list( + Sepal.Length = list(selected = c(5.1, 6.4), keep_na = TRUE, keep_inf = TRUE), + Species = list(selected = c("setosa", "versicolor"), keep_na = FALSE) + ) + dataset$set_filter_state(state = fs) + states <- dataset$get_filter_states()[[1]] + + testthat::expect_equal( + shiny::isolate(dataset$get_formatted_filter_state()), + paste("Filters for dataset: iris", shiny::isolate(states$format(indent = 2)), sep = "\n") + ) +}) diff --git a/tests/testthat/test-MAEFilterStates.R b/tests/testthat/test-MAEFilterStates.R index d4452acc5..64b81a5e2 100644 --- a/tests/testthat/test-MAEFilterStates.R +++ b/tests/testthat/test-MAEFilterStates.R @@ -283,3 +283,58 @@ testthat::test_that( ) } ) + +# Format +testthat::test_that("$format() is a method of DFFilterStates", { + testthat::expect_error(MAEFilterStates$new( + input_dataname = "iris", + output_dataname = "iris_filtered", + datalabel = character(0), + varlabels = character(0), + keys = character(0) + )$format(), NA) +}) + +testthat::test_that("$format() asserts the indent argument is a number", { + testthat::expect_error( + MAEFilterStates$new( + input_dataname = "iris", + output_dataname = "iris_filtered", + datalabel = character(0), + varlabels = character(0), + keys = character(0) + )$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() concatenates its FilterState elements using \\n and indents the FilterState objects", { + utils::data(miniACC, package = "MultiAssayExperiment") + maefs <- MAEFilterStates$new( + input_dataname = "test", + output_dataname = "test_filtered", + datalabel = character(0), + varlabels = character(0), + keys = character(0) + ) + + maefs$set_filter_state( + state = list( + years_to_birth = c(30, 50), + vital_status = 1 + ), + data = miniACC + ) + + years_to_birth_filter <- maefs$queue_get(1L)[[1]] + vital_status_filter <- maefs$queue_get(1L)[[2]] + shiny::isolate(testthat::expect_equal( + maefs$format(), + paste( + "Subject filters:", + years_to_birth_filter$format(indent = 2), + vital_status_filter$format(indent = 2), + sep = "\n" + ) + )) +}) diff --git a/tests/testthat/test-RangeFilterState.R b/tests/testthat/test-RangeFilterState.R index 70e20e538..3d748a394 100644 --- a/tests/testthat/test-RangeFilterState.R +++ b/tests/testthat/test-RangeFilterState.R @@ -255,3 +255,45 @@ testthat::test_that( ) } ) + + +# Format +testthat::test_that("$format() is a FilterStates's method that accepts indent", { + filter_state <- RangeFilterState$new(7, varname = "test") + testthat::expect_error(shiny::isolate(filter_state$format(indent = 0)), regexp = NA) +}) + +testthat::test_that("$format() asserts that indent is numeric", { + testthat::expect_error( + RangeFilterState$new(c(7), varname = "test")$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() returns a string representation the FilterState object", { + filter_state <- RangeFilterState$new(c(7), varname = "test") + filter_state$set_state(list(selected = c(7, 7))) + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = 0)), + paste( + "Filtering on: test", + " Selected range: 7.000 - 7.000", + " Include missing values: FALSE", + sep = "\n" + ) + ) +}) + +testthat::test_that("$format() prepends spaces to every line of the returned string", { + filter_state <- RangeFilterState$new(c(7), varname = "test") + filter_state$set_state(list(selected = c(7, 7))) + for (i in 1:3) { + testthat::expect_equal( + shiny::isolate(filter_state$format(indent = !!(i))), + sprintf( + "%sFiltering on: test\n%1$s Selected range: 7.000 - 7.000\n%1$s Include missing values: FALSE", + format("", width = i) + ) + ) + } +}) diff --git a/tests/testthat/test-SEFilterStates.R b/tests/testthat/test-SEFilterStates.R index c79352a6d..b1fce8bc6 100644 --- a/tests/testthat/test-SEFilterStates.R +++ b/tests/testthat/test-SEFilterStates.R @@ -412,3 +412,55 @@ testthat::test_that( ) } ) + +# Format +testthat::test_that("$format() is a method of SEFilterStates", { + testthat::expect_error( + SEFilterStates$new( + input_dataname = "test", + output_dataname = "test_filtered", + datalabel = character(0) + )$format(), + NA + ) +}) + +testthat::test_that("$format() asserts the indent argument is a number", { + testthat::expect_error( + SEFilterStates$new( + input_dataname = "test", + output_dataname = "test_filtered", + datalabel = character(0) + )$format(indent = "wrong type"), + regexp = "Assertion on 'indent' failed: Must be of type 'number'" + ) +}) + +testthat::test_that("$format() concatenates its FilterState elements using \\n and indents the FilterState strings", { + test <- get_test_data() + sefs <- SEFilterStates$new( + input_dataname = "test", + output_dataname = "test_filtered", + datalabel = "Label" + ) + + fs <- list( + select = list(Treatment = "ChIP"), + subset = list(feature_id = c("ID001", "ID002")) + ) + sefs$set_filter_state(state = fs, data = test) + + treatment_filter <- sefs$queue_get("select")[[1]] + feature_filter <- sefs$queue_get("subset")[[1]] + shiny::isolate(testthat::expect_equal( + sefs$format(), + paste( + "Assay Label filters:", + " Subsetting:", + feature_filter$format(indent = 4), + " Selecting:", + treatment_filter$format(indent = 4), + sep = "\n" + ) + )) +}) diff --git a/tests/testthat/test-init_filter_state.R b/tests/testthat/test-init_filter_state.R index 8fd907fbc..253f94e0c 100644 --- a/tests/testthat/test-init_filter_state.R +++ b/tests/testthat/test-init_filter_state.R @@ -19,8 +19,6 @@ test_that("'extract_type' must be specified with 'input_dataname'", { ) }) - - testthat::test_that("init_filter_state accepts, name or call as input_dataname", { testthat::expect_error( init_filter_state(7, varname = "test", input_dataname = NULL), @@ -98,3 +96,8 @@ testthat::test_that("init_filter_state return a LogicalFilterState, if passed a testthat::expect_error(fs <- init_filter_state(c(TRUE), varname = "test"), NA) testthat::expect_true(is(fs, "LogicalFilterState")) }) + +testthat::test_that("init_filter_state default accepts a list", { + fs <- init_filter_state(list(1, 2, 3), varname = "test") + testthat::expect_true(inherits(fs, "FilterState")) +})