diff --git a/R/data_extract_module.R b/R/data_extract_module.R index 4431ba8e..3c80b0ea 100644 --- a/R/data_extract_module.R +++ b/R/data_extract_module.R @@ -72,9 +72,9 @@ cond_data_extract_single_ui <- function(ns, single_data_extract_spec) { #' #' The output can be analyzed using `data_extract_srv(...)`. #' -#' @section UI examples: -#' \describe{ -#' \preformatted{ +#' @examples +#' library(shiny) +#' #' adtte_filters <- filter_spec( #' vars = c("PARAMCD", "CNSR"), #' sep = "-", @@ -89,29 +89,23 @@ cond_data_extract_single_ui <- function(ns, single_data_extract_spec) { #' filter = adtte_filters, #' select = select_spec( #' choices = c("AVAL", "BMRKR1", "AGE"), -#' selected = c("AVAL", "BMRKR1"), -#' multiple = TRUE, -#' fixed = FALSE, -#' label = "Column" -#' ) +#' selected = c("AVAL", "BMRKR1"), +#' multiple = TRUE, +#' fixed = FALSE, +#' label = "Column" +#' ) #' ) #' # Call to use inside your teal module UI function #' teal.widgets::standard_layout( +#' output = tableOutput("table"), #' encoding = div( -#' data_extract_ui(id = "regressor", label = "Regressor Variable", data_extract_spec = response_spec) +#' data_extract_ui( +#' id = "regressor", +#' label = "Regressor Variable", +#' data_extract_spec = response_spec +#' ) #' ) #' ) -#' } -#' \if{html}{ -#' \figure{data_extract_spec_13.png}{options: alt="Dataset with multiple filters and column selection"} -#' } -#' \if{html}{ -#' \figure{data_extract_spec_12.png}{options: alt="Dataset with multiple filters and column selection"} -#' } -#' \if{html}{ -#' \figure{data_extract_spec_11.png}{options: alt="Dataset with multiple filters and column selection"} -#' } -#' } #' #' @export data_extract_ui <- function(id, label, data_extract_spec, is_single_dataset = FALSE) { diff --git a/R/data_extract_spec.R b/R/data_extract_spec.R index 3226bcd3..7c66f4a0 100644 --- a/R/data_extract_spec.R +++ b/R/data_extract_spec.R @@ -30,18 +30,14 @@ #' whether reshape long to wide. Note that it will be used only in case of long dataset with multiple #' keys selected in filter part. #' -#' @section Examples: -#' \describe{ -#' \enumerate{ -#' \item{`TealDataset` with multiple filters and column selection}{ -#' \preformatted{ +#' @examples #' adtte_filters <- filter_spec( -#' vars = c("PARAMCD", "CNSR"), -#' sep = "-", -#' choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), -#' selected = "OS-1", -#' multiple = FALSE, -#' label = "Choose endpoint and Censor" +#' vars = c("PARAMCD", "CNSR"), +#' sep = "-", +#' choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), +#' selected = "OS-1", +#' multiple = FALSE, +#' label = "Choose endpoint and Censor" #' ) #' #' data_extract_spec( @@ -49,68 +45,38 @@ #' filter = adtte_filters, #' select = select_spec( #' choices = c("AVAL", "BMRKR1", "AGE"), -#' selected = c("AVAL", "BMRKR1"), -#' multiple = TRUE, -#' fixed = FALSE, -#' label = "Column" -#' ) +#' selected = c("AVAL", "BMRKR1"), +#' multiple = TRUE, +#' fixed = FALSE, +#' label = "Column" +#' ) #' ) -#' } -#' \if{html}{ -#' \figure{data_extract_spec_1.png}{options: alt="TealDataset with multiple filters and column selection"} -#' } -#' \if{html}{ -#' \figure{data_extract_spec_12.png}{options: alt="TealDataset with multiple filters and column selection"} -#' } -#' \if{html}{ -#' \figure{data_extract_spec_11.png}{options: alt="TealDataset with multiple filters and column selection"} -#' } -#' } -#' \item{Data extract without filtering}{ -#' \preformatted{ #' #' data_extract_spec( #' dataname = "ADSL", #' filter = NULL, #' select = select_spec( #' choices = c("AGE", "SEX", "USUBJID"), -#' selected = c("SEX"), -#' multiple = FALSE, -#' fixed = FALSE -#' ) +#' selected = c("SEX"), +#' multiple = FALSE, +#' fixed = FALSE +#' ) #' ) -#' } -#' } -#' \if{html}{ -#' \figure{data_extract_spec_2.png}{options: alt="Data extract without filtering"} -#' } -#' -#' \item{Data extract with a single filter}{ -#' \preformatted{ -#' data_extract_spec( -#' dataname = "ADSL", -#' filter = filter_spec( -#' vars = variable_choices("ADSL", subset = c("AGE")) -#' ) -#' ) -#' } -#' } -#' -#' \item{Data extract with a filter that also selects columns due to no select_spec}{ -#' \preformatted{ -#' -#' dynamic_filter <- filter_spec( -#' vars = choices_selected(variable_choices(ADSL), "COUNTRY"), -#' multiple = TRUE +#' data_extract_spec( +#' dataname = "ADSL", +#' filter = filter_spec( +#' vars = variable_choices("ADSL", subset = c("AGE")) #' ) -#' data_extract_spec( -#' dataname = "ADSL", -#' filter = dynamic_filter -#' ) -#' } -#' } -#' } -#' } +#' ) +#' +#' dynamic_filter <- filter_spec( +#' vars = choices_selected(variable_choices("ADSL"), "COUNTRY"), +#' multiple = TRUE +#' ) +#' data_extract_spec( +#' dataname = "ADSL", +#' filter = dynamic_filter +#' ) #' #' @references [select_spec] [filter_spec] data_extract_spec <- function(dataname, select = NULL, filter = NULL, reshape = FALSE) { diff --git a/R/filter_spec.R b/R/filter_spec.R index b180c116..86057e5b 100644 --- a/R/filter_spec.R +++ b/R/filter_spec.R @@ -46,142 +46,72 @@ #' #' @return \code{filter_spec}-S3-class object or \code{delayed_filter_spec}-S3-class object. #' -#' @examples -#' filter_spec( -#' vars = c("PARAMCD", "AVISIT"), -#' sep = " - ", -#' choices = c("CRP - BASELINE", "CRP - SCREENING", "ALT - BASELINE"), -#' selected = c("CRP - BASELINE"), -#' multiple = TRUE -#' ) -#' -#' filter_spec( -#' vars = c("PARAMCD"), -#' sep = " - ", -#' choices = c("CRP", "ALT"), -#' selected = c("CRP"), -#' multiple = TRUE -#' ) #' @details #' #' The \code{filter_spec} is used inside \code{teal} apps to allow filtering datasets #' for their key variables. Imagine having an adverse events table. It has #' the columns \code{PARAMCD} and \code{CNSR}. \code{PARAMCD} contains the levels #' \code{"OS"}, \code{"PFS"}, \code{"EFS"}. \code{CNSR} contains the levels \code{"0"} and \code{"1"}. -#' The following examples should show how a \code{filter_spec} setup will influence -#' the drop-down menu the app user will see: -#' -#' \enumerate{ -#' \item{Filtering two variables }{ -#' \preformatted{ -#' filter_spec( -#' vars = c("PARAMCD", "CNSR"), -#' sep = "-", -#' choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), -#' selected = "OS-1", -#' multiple = FALSE, -#' label = "Choose endpoint and Censor" -#' ) -#' } +#' The first example should show how a \code{filter_spec} setup will influence +#' the drop-down menu the app user will see. #' -#' \if{html}{ -#' \figure{filter_spec_1.png}{options: alt="Filtering two variables"} -#' } -#' \if{html}{ -#' \figure{filter_spec_11.png}{options: alt="Filtering two variables"} -#' } -#' } #' -#' \item{Filtering a single variable }{ -#' \preformatted{ -#' filter_spec( -#' vars = c("PARAMCD"), -#' sep = "-", -#' choices = c("OS", "PFS", "EFS"), -#' selected = "OS", -#' multiple = FALSE, -#' label = "Choose endpoint" -#' ) -#' } -#' -#' \if{html}{ -#' \figure{filter_spec_2.png}{options: alt="Filtering two variables"} -#' } -#' \if{html}{ -#' \figure{filter_spec_21.png}{options: alt="Filtering two variables"} -#' } -#' } +#' @examples +#' # for Adverse Events table +#' filter_spec( +#' vars = c("PARAMCD", "CNSR"), +#' sep = "-", +#' choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), +#' selected = "OS-1", +#' multiple = FALSE, +#' label = "Choose endpoint and Censor" +#' ) #' -#' \item{Filtering a single variable by multiple levels of the variable}{ -#' \preformatted{ -#' filter_spec( -#' vars = c("PARAMCD"), -#' sep = "-", -#' choices = c("OS", "PFS", "EFS"), -#' selected = c("OS", "PFS"), -#' multiple = TRUE, -#' label = "Choose endpoint" -#' ) -#' } +#' # filtering a single variable +#' filter_spec( +#' vars = c("PARAMCD"), +#' sep = "-", +#' choices = c("OS", "PFS", "EFS"), +#' selected = "OS", +#' multiple = FALSE, +#' label = "Choose endpoint" +#' ) #' -#' \if{html}{ -#' \figure{filter_spec_3.png}{options: alt="Filtering two variables"} -#' } -#' \if{html}{ -#' \figure{filter_spec_31.png}{options: alt="Filtering two variables"} -#' } -#' } -#' \item{Delayed version}{ -#' \preformatted{ -#' adsl_filter <- filter_spec( -#' vars = variable_choices("ADSL", "SEX"), -#' sep = "-", -#' choices = value_choices("ADSL", "SEX", "SEX"), -#' selected = "F", -#' multiple = FALSE, -#' label = "Choose endpoint and Censor" -#' ) -#' } -#' } -#' \item{Using \code{choices_selected} -#' \preformatted{ -#' adsl_filter <- filter_spec( -#' vars = choices_selected(variable_choices("ADSL", subset = c("SEX", "AGE")), "SEX", fixed = FALSE), -#' multiple = TRUE -#' ) +#' # filtering a single variable by multiple levels of the variable +#' filter_spec( +#' vars = c("PARAMCD"), +#' sep = "-", +#' choices = c("OS", "PFS", "EFS"), +#' selected = c("OS", "PFS"), +#' multiple = TRUE, +#' label = "Choose endpoint" +#' ) #' -#' adsl_filter2 <- filter_spec( -#' vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = TRUE), -#' multiple = TRUE -#' ) -#' } -#' } -#' \item{Choose all choices -#' \preformatted{ -#' adsl_filter <- filter_spec( -#' vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = FALSE), -#' choices = value_choices("ADSL", "SEX"), -#' selected = all_choices() -#' ) -#' } -#' } -#' } +#' # delayed version +#' filter_spec( +#' vars = variable_choices("ADSL", "SEX"), +#' sep = "-", +#' choices = value_choices("ADSL", "SEX", "SEX"), +#' selected = "F", +#' multiple = FALSE, +#' label = "Choose endpoint and Censor" +#' ) +#' # using `choices_selected()` +#' filter_spec( +#' vars = choices_selected(variable_choices("ADSL", subset = c("SEX", "AGE")), "SEX", fixed = FALSE), +#' multiple = TRUE +#' ) #' -#' @examples #' filter_spec( -#' vars = variable_choices("ADSL", "ARMCD"), -#' choices = value_choices("ADSL", -#' var_choices = "ARMCD", var_label = "ARM", -#' subset = function(data) { -#' levels(data$ARMCD)[1:2] -#' } -#' ), -#' selected = value_choices("ADSL", -#' var_choices = "ARMCD", var_label = "ARM", -#' subset = function(data) { -#' levels(data$ARMCD)[1] -#' } -#' ) +#' vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = TRUE), +#' multiple = TRUE +#' ) +#' +#' # choose all choices +#' adsl_filter <- filter_spec( +#' vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = FALSE), +#' choices = value_choices("ADSL", "SEX"), +#' selected = all_choices() #' ) filter_spec <- function(vars, choices = NULL, diff --git a/R/get_merge_call.R b/R/get_merge_call.R index 526d5f5f..24cce2b9 100644 --- a/R/get_merge_call.R +++ b/R/get_merge_call.R @@ -301,7 +301,8 @@ parse_merge_key_i <- function(selector_list, #' Names of filtered-out filters dropped from selection #' -#' @details Names of filtered-out filters dropped from automatic selection (key vars are automatically included in select). +#' @details Names of filtered-out filters dropped from automatic selection +#' (key vars are automatically included in select). #' Dropped filter is filter which became not unique for all observations. #' This means that if variable is filtered to just one level, #' it's not a key anymore. Other variables used in filter should also be dropped from automatic diff --git a/R/select_spec.R b/R/select_spec.R index 9e104e99..f559d90f 100644 --- a/R/select_spec.R +++ b/R/select_spec.R @@ -35,99 +35,53 @@ #' It contains all input values. #' If \code{select_spec}, then the function double checks the \code{choices} and \code{selected} inputs. #' -#' @details #' -#' To give you some more insights into this function there are several examples. These all -#' start by a data set containing the columns \code{"AGE"}, \code{"AVAL"} and \code{"BMRKR1"}. +#' @rdname select_spec +#' +#' @export #' -#' \enumerate{ -#' \item{Selection with just one column allowed }{ -#' \preformatted{ -#' select = select_spec( +#' @examples +#' # Selection with just one column allowed +#' select_spec( #' choices = c("AVAL", "BMRKR1", "AGE"), #' selected = c("AVAL"), #' multiple = FALSE, #' fixed = FALSE, #' label = "Column" #' ) -#' } -#' \if{html}{ -#' \figure{select_spec_1.png}{options: alt="Selection with just one column allowed"} -#' } -#' \if{html}{ -#' \figure{select_spec_11.png}{options: alt="Selection with just one column allowed"} -#' } -#' } -#' \item{Selection with just multiple columns allowed }{ -#' \preformatted{ -#' select = select_spec( +#' +#' # Selection with just multiple columns allowed +#' select_spec( #' choices = c("AVAL", "BMRKR1", "AGE"), #' selected = c("AVAL", "BMRKR1"), #' multiple = TRUE, #' fixed = FALSE, #' label = "Columns" #' ) -#' } -#' \if{html}{ -#' \figure{select_spec_2.png}{options: alt="Selection with just multiple columns allowed"} -#' } -#' \if{html}{ -#' \figure{select_spec_21.png}{options: alt="Selection with just multiple columns allowed"} -#' } -#' } -#' \item{Selection without user access }{ -#' \preformatted{ -#' select = select_spec( +#' +#' # Selection without user access +#' select_spec( #' choices = c("AVAL", "BMRKR1"), #' selected = c("AVAL", "BMRKR1"), #' multiple = TRUE, #' fixed = TRUE, #' label = "Columns" #' ) -#' } -#' \if{html}{ -#' \figure{select_spec_3.png}{options: alt="Selection without user access"} -#' } -#' } -#' \item{Delayed version}{ -#' \preformatted{ -#' adsl_select <- select_spec( -#' label = "Select variable:", -#' choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), -#' selected = "BMRKR1", -#' multiple = FALSE, -#' fixed = FALSE -#' ) -#' } -#' } -#' \item{all_choices passed to selected}{ -#' \preformatted{ -#' adsl_select <- select_spec( -#' label = "Select variable:", -#' choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), -#' selected = all_choices() -#' ) -#' } -#' } -#' } -#' -#' @rdname select_spec #' -#' @export +#' # Delayed version +#' select_spec( +#' label = "Select variable:", +#' choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), +#' selected = "BMRKR1", +#' multiple = FALSE, +#' fixed = FALSE +#' ) #' -#' @examples -#' # functional form (subsetting for factor variables only) of select_spec with delayed data loading +#' # all_choices passed to selected #' select_spec( -#' choices = variable_choices("ADSL", subset = function(data) { -#' idx <- vapply(data, is.factor, logical(1)) -#' return(names(data)[idx]) -#' }), -#' # setting first factor variable as default -#' selected = variable_choices("ADSL", subset = function(data) { -#' idx <- vapply(data, is.factor, logical(1)) -#' return(names(data)[idx][1]) -#' }), -#' multiple = TRUE +#' label = "Select variable:", +#' choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), +#' selected = all_choices() #' ) #' #' # Both below objects are semantically the same @@ -158,7 +112,7 @@ select_spec <- function(choices, #' @rdname select_spec #' @export -select_spec.delayed_data <- function(choices, +select_spec.delayed_data <- function(choices, # nolint selected = NULL, multiple = length(selected) > 1, fixed = FALSE, @@ -184,7 +138,7 @@ select_spec.delayed_data <- function(choices, #' @rdname select_spec #' @export -select_spec.default <- function(choices, +select_spec.default <- function(choices, # nolint selected = choices[1], multiple = length(selected) > 1, fixed = FALSE, diff --git a/man/data_extract_spec.Rd b/man/data_extract_spec.Rd index c48b7295..22fb034e 100644 --- a/man/data_extract_spec.Rd +++ b/man/data_extract_spec.Rd @@ -40,19 +40,14 @@ Note that no checks based on columns can be done because the data is only referr } } -\section{Examples}{ - -\describe{ -\enumerate{ -\item{\code{TealDataset} with multiple filters and column selection}{ -\preformatted{ +\examples{ adtte_filters <- filter_spec( -vars = c("PARAMCD", "CNSR"), -sep = "-", -choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), -selected = "OS-1", -multiple = FALSE, -label = "Choose endpoint and Censor" + vars = c("PARAMCD", "CNSR"), + sep = "-", + choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), + selected = "OS-1", + multiple = FALSE, + label = "Choose endpoint and Censor" ) data_extract_spec( @@ -60,70 +55,40 @@ data_extract_spec( filter = adtte_filters, select = select_spec( choices = c("AVAL", "BMRKR1", "AGE"), - selected = c("AVAL", "BMRKR1"), - multiple = TRUE, - fixed = FALSE, - label = "Column" - ) + selected = c("AVAL", "BMRKR1"), + multiple = TRUE, + fixed = FALSE, + label = "Column" + ) ) - } -\if{html}{ - \figure{data_extract_spec_1.png}{options: alt="TealDataset with multiple filters and column selection"} - } -\if{html}{ - \figure{data_extract_spec_12.png}{options: alt="TealDataset with multiple filters and column selection"} - } -\if{html}{ - \figure{data_extract_spec_11.png}{options: alt="TealDataset with multiple filters and column selection"} - } -} -\item{Data extract without filtering}{ -\preformatted{ data_extract_spec( dataname = "ADSL", filter = NULL, select = select_spec( choices = c("AGE", "SEX", "USUBJID"), - selected = c("SEX"), - multiple = FALSE, - fixed = FALSE - ) + selected = c("SEX"), + multiple = FALSE, + fixed = FALSE + ) +) +data_extract_spec( + dataname = "ADSL", + filter = filter_spec( + vars = variable_choices("ADSL", subset = c("AGE")) + ) ) - } -} -\if{html}{ - \figure{data_extract_spec_2.png}{options: alt="Data extract without filtering"} - } - -\item{Data extract with a single filter}{ -\preformatted{ - data_extract_spec( - dataname = "ADSL", - filter = filter_spec( - vars = variable_choices("ADSL", subset = c("AGE")) - ) - ) - } -} -\item{Data extract with a filter that also selects columns due to no select_spec}{ -\preformatted{ +dynamic_filter <- filter_spec( + vars = choices_selected(variable_choices("ADSL"), "COUNTRY"), + multiple = TRUE +) +data_extract_spec( + dataname = "ADSL", + filter = dynamic_filter +) - dynamic_filter <- filter_spec( - vars = choices_selected(variable_choices(ADSL), "COUNTRY"), - multiple = TRUE - ) - data_extract_spec( - dataname = "ADSL", - filter = dynamic_filter - ) - } -} -} } -} - \references{ \link{select_spec} \link{filter_spec} } diff --git a/man/data_extract_ui.Rd b/man/data_extract_ui.Rd index fcf8df7d..7d1fb26f 100644 --- a/man/data_extract_ui.Rd +++ b/man/data_extract_ui.Rd @@ -46,10 +46,9 @@ to teal module variables being filtered data from \code{CDISC} datasets. You can \href{https://shiny.rstudio.com/articles/modules.html}{shiny module} UI. The corresponding server module can be found in \code{\link[=data_extract_srv]{data_extract_srv()}}. } -\section{UI examples}{ +\examples{ +library(shiny) -\describe{ -\preformatted{ adtte_filters <- filter_spec( vars = c("PARAMCD", "CNSR"), sep = "-", @@ -64,28 +63,22 @@ response_spec <- data_extract_spec( filter = adtte_filters, select = select_spec( choices = c("AVAL", "BMRKR1", "AGE"), - selected = c("AVAL", "BMRKR1"), - multiple = TRUE, - fixed = FALSE, - label = "Column" - ) + selected = c("AVAL", "BMRKR1"), + multiple = TRUE, + fixed = FALSE, + label = "Column" + ) ) # Call to use inside your teal module UI function teal.widgets::standard_layout( + output = tableOutput("table"), encoding = div( - data_extract_ui(id = "regressor", label = "Regressor Variable", data_extract_spec = response_spec) + data_extract_ui( + id = "regressor", + label = "Regressor Variable", + data_extract_spec = response_spec + ) ) ) - } -\if{html}{ - \figure{data_extract_spec_13.png}{options: alt="Dataset with multiple filters and column selection"} - } -\if{html}{ - \figure{data_extract_spec_12.png}{options: alt="Dataset with multiple filters and column selection"} - } -\if{html}{ - \figure{data_extract_spec_11.png}{options: alt="Dataset with multiple filters and column selection"} - } -} -} +} diff --git a/man/filter_spec.Rd b/man/filter_spec.Rd index 47084202..7b5765b4 100644 --- a/man/filter_spec.Rd +++ b/man/filter_spec.Rd @@ -69,134 +69,64 @@ The \code{filter_spec} is used inside \code{teal} apps to allow filtering datase for their key variables. Imagine having an adverse events table. It has the columns \code{PARAMCD} and \code{CNSR}. \code{PARAMCD} contains the levels \code{"OS"}, \code{"PFS"}, \code{"EFS"}. \code{CNSR} contains the levels \code{"0"} and \code{"1"}. -The following examples should show how a \code{filter_spec} setup will influence -the drop-down menu the app user will see: - -\enumerate{ -\item{Filtering two variables }{ -\preformatted{ - filter_spec( - vars = c("PARAMCD", "CNSR"), - sep = "-", - choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), - selected = "OS-1", - multiple = FALSE, - label = "Choose endpoint and Censor" - ) - } - -\if{html}{ - \figure{filter_spec_1.png}{options: alt="Filtering two variables"} - } -\if{html}{ - \figure{filter_spec_11.png}{options: alt="Filtering two variables"} - } -} - -\item{Filtering a single variable }{ -\preformatted{ - filter_spec( - vars = c("PARAMCD"), - sep = "-", - choices = c("OS", "PFS", "EFS"), - selected = "OS", - multiple = FALSE, - label = "Choose endpoint" - ) - } - -\if{html}{ - \figure{filter_spec_2.png}{options: alt="Filtering two variables"} - } -\if{html}{ - \figure{filter_spec_21.png}{options: alt="Filtering two variables"} - } +The first example should show how a \code{filter_spec} setup will influence +the drop-down menu the app user will see. } +\examples{ +# for Adverse Events table +filter_spec( + vars = c("PARAMCD", "CNSR"), + sep = "-", + choices = c("OS-1" = "OS-1", "OS-0" = "OS-0", "PFS-1" = "PFS-1"), + selected = "OS-1", + multiple = FALSE, + label = "Choose endpoint and Censor" +) -\item{Filtering a single variable by multiple levels of the variable}{ -\preformatted{ - filter_spec( - vars = c("PARAMCD"), - sep = "-", - choices = c("OS", "PFS", "EFS"), - selected = c("OS", "PFS"), - multiple = TRUE, - label = "Choose endpoint" - ) - } +# filtering a single variable +filter_spec( + vars = c("PARAMCD"), + sep = "-", + choices = c("OS", "PFS", "EFS"), + selected = "OS", + multiple = FALSE, + label = "Choose endpoint" +) -\if{html}{ - \figure{filter_spec_3.png}{options: alt="Filtering two variables"} - } -\if{html}{ - \figure{filter_spec_31.png}{options: alt="Filtering two variables"} - } -} -\item{Delayed version}{ -\preformatted{ - adsl_filter <- filter_spec( - vars = variable_choices("ADSL", "SEX"), - sep = "-", - choices = value_choices("ADSL", "SEX", "SEX"), - selected = "F", - multiple = FALSE, - label = "Choose endpoint and Censor" - ) - } -} -\item{Using \code{choices_selected} -\preformatted{ - adsl_filter <- filter_spec( - vars = choices_selected(variable_choices("ADSL", subset = c("SEX", "AGE")), "SEX", fixed = FALSE), - multiple = TRUE - ) +# filtering a single variable by multiple levels of the variable +filter_spec( + vars = c("PARAMCD"), + sep = "-", + choices = c("OS", "PFS", "EFS"), + selected = c("OS", "PFS"), + multiple = TRUE, + label = "Choose endpoint" +) - adsl_filter2 <- filter_spec( - vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = TRUE), - multiple = TRUE - ) - } -} -\item{Choose all choices -\preformatted{ - adsl_filter <- filter_spec( - vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = FALSE), - choices = value_choices("ADSL", "SEX"), - selected = all_choices() - ) - } -} -} -} -\examples{ +# delayed version +filter_spec( + vars = variable_choices("ADSL", "SEX"), + sep = "-", + choices = value_choices("ADSL", "SEX", "SEX"), + selected = "F", + multiple = FALSE, + label = "Choose endpoint and Censor" +) +# using `choices_selected()` filter_spec( - vars = c("PARAMCD", "AVISIT"), - sep = " - ", - choices = c("CRP - BASELINE", "CRP - SCREENING", "ALT - BASELINE"), - selected = c("CRP - BASELINE"), + vars = choices_selected(variable_choices("ADSL", subset = c("SEX", "AGE")), "SEX", fixed = FALSE), multiple = TRUE ) filter_spec( - vars = c("PARAMCD"), - sep = " - ", - choices = c("CRP", "ALT"), - selected = c("CRP"), + vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = TRUE), multiple = TRUE ) -filter_spec( - vars = variable_choices("ADSL", "ARMCD"), - choices = value_choices("ADSL", - var_choices = "ARMCD", var_label = "ARM", - subset = function(data) { - levels(data$ARMCD)[1:2] - } - ), - selected = value_choices("ADSL", - var_choices = "ARMCD", var_label = "ARM", - subset = function(data) { - levels(data$ARMCD)[1] - } - ) + +# choose all choices +adsl_filter <- filter_spec( + vars = choices_selected(variable_choices("ADSL"), "SEX", fixed = FALSE), + choices = value_choices("ADSL", "SEX"), + selected = all_choices() ) } diff --git a/man/get_dropped_filters.Rd b/man/get_dropped_filters.Rd index 88c532f7..cd8e084c 100644 --- a/man/get_dropped_filters.Rd +++ b/man/get_dropped_filters.Rd @@ -16,7 +16,8 @@ names \code{character} of the filters which should be dropped from select call Names of filtered-out filters dropped from selection } \details{ -Names of filtered-out filters dropped from automatic selection (key vars are automatically included in select). +Names of filtered-out filters dropped from automatic selection +(key vars are automatically included in select). Dropped filter is filter which became not unique for all observations. This means that if variable is filtered to just one level, it's not a key anymore. Other variables used in filter should also be dropped from automatic diff --git a/man/select_spec.Rd b/man/select_spec.Rd index ffcc56b8..55a83d0f 100644 --- a/man/select_spec.Rd +++ b/man/select_spec.Rd @@ -74,94 +74,48 @@ If \code{select_spec}, then the function double checks the \code{choices} and \c \code{select_spec} is used inside teal to create a \code{\link[shiny]{selectInput}} that will select columns from a dataset. } -\details{ -To give you some more insights into this function there are several examples. These all -start by a data set containing the columns \code{"AGE"}, \code{"AVAL"} and \code{"BMRKR1"}. - -\enumerate{ -\item{Selection with just one column allowed }{ -\preformatted{ -select = select_spec( +\examples{ +# Selection with just one column allowed +select_spec( choices = c("AVAL", "BMRKR1", "AGE"), selected = c("AVAL"), multiple = FALSE, fixed = FALSE, label = "Column" ) - } -\if{html}{ - \figure{select_spec_1.png}{options: alt="Selection with just one column allowed"} - } -\if{html}{ - \figure{select_spec_11.png}{options: alt="Selection with just one column allowed"} - } -} -\item{Selection with just multiple columns allowed }{ -\preformatted{ -select = select_spec( + +# Selection with just multiple columns allowed +select_spec( choices = c("AVAL", "BMRKR1", "AGE"), selected = c("AVAL", "BMRKR1"), multiple = TRUE, fixed = FALSE, label = "Columns" ) - } -\if{html}{ - \figure{select_spec_2.png}{options: alt="Selection with just multiple columns allowed"} - } -\if{html}{ - \figure{select_spec_21.png}{options: alt="Selection with just multiple columns allowed"} - } -} -\item{Selection without user access }{ -\preformatted{ -select = select_spec( + +# Selection without user access +select_spec( choices = c("AVAL", "BMRKR1"), selected = c("AVAL", "BMRKR1"), multiple = TRUE, fixed = TRUE, label = "Columns" ) - } -\if{html}{ - \figure{select_spec_3.png}{options: alt="Selection without user access"} - } -} -\item{Delayed version}{ -\preformatted{ - adsl_select <- select_spec( - label = "Select variable:", - choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), - selected = "BMRKR1", - multiple = FALSE, - fixed = FALSE - ) - } -} -\item{all_choices passed to selected}{ -\preformatted{ - adsl_select <- select_spec( - label = "Select variable:", - choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), - selected = all_choices() - ) - } -} -} -} -\examples{ -# functional form (subsetting for factor variables only) of select_spec with delayed data loading + +# Delayed version +select_spec( + label = "Select variable:", + choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), + selected = "BMRKR1", + multiple = FALSE, + fixed = FALSE +) + +# all_choices passed to selected select_spec( - choices = variable_choices("ADSL", subset = function(data) { - idx <- vapply(data, is.factor, logical(1)) - return(names(data)[idx]) - }), - # setting first factor variable as default - selected = variable_choices("ADSL", subset = function(data) { - idx <- vapply(data, is.factor, logical(1)) - return(names(data)[idx][1]) - }), - multiple = TRUE + label = "Select variable:", + choices = variable_choices("ADSL", c("BMRKR1", "BMRKR2")), + selected = all_choices() ) # Both below objects are semantically the same