diff --git a/DESCRIPTION b/DESCRIPTION index bd98e648..454f93db 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,15 +32,14 @@ Imports: shinyjs, shinyvalidate, stats, - teal.data (>= 0.3.0.9010), + teal.data (>= 0.3.0.9017), teal.logger (>= 0.1.1), - teal.slice (>= 0.4.0.9023), teal.widgets (>= 0.4.0), tidyr (>= 0.8.3), tidyselect Suggests: knitr (>= 1.42), - shinytest (>= 1.5.1), + rmarkdown (>= 2.19), teal.code (>= 0.4.0), testthat (>= 3.1.5) VignetteBuilder: @@ -49,10 +48,10 @@ RdMacros: lifecycle Config/Needs/verdepcheck: tidyverse/magrittr, mllg/checkmate, tidyverse/dplyr, r-lib/lifecycle, daroczig/logger, r-lib/rlang, - rstudio/shiny, daattali/shinyjs, rstudio/shinyvalidate, + rstudio/rmarkdown, rstudio/shiny, daattali/shinyjs, rstudio/shinyvalidate, insightsengineering/teal.data, insightsengineering/teal.logger, - insightsengineering/teal.slice, insightsengineering/teal.widgets, - tidyverse/tidyr, r-lib/tidyselect, yihui/knitr, rstudio/shinytest, + insightsengineering/teal.widgets, + tidyverse/tidyr, r-lib/tidyselect, yihui/knitr, insightsengineering/teal.code, r-lib/testthat Config/Needs/website: insightsengineering/nesttemplate Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 8aedd686..49700e8d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,10 +2,15 @@ S3method(data_extract_multiple_srv,FilteredData) S3method(data_extract_multiple_srv,list) +S3method(data_extract_multiple_srv,reactive) S3method(data_extract_srv,FilteredData) S3method(data_extract_srv,list) S3method(filter_spec_internal,default) S3method(filter_spec_internal,delayed_data) +S3method(merge_expression_module,list) +S3method(merge_expression_module,reactive) +S3method(merge_expression_srv,list) +S3method(merge_expression_srv,reactive) S3method(print,choices_labeled) S3method(print,delayed_choices_selected) S3method(print,delayed_data_extract_spec) @@ -24,12 +29,8 @@ S3method(resolve,delayed_variable_choices) S3method(resolve,list) S3method(resolve_delayed,FilteredData) S3method(resolve_delayed,list) -S3method(value_choices,TealDataset) -S3method(value_choices,TealDatasetConnector) S3method(value_choices,character) S3method(value_choices,data.frame) -S3method(variable_choices,TealDataset) -S3method(variable_choices,TealDatasetConnector) S3method(variable_choices,character) S3method(variable_choices,data.frame) export(add_no_selected_choices) @@ -42,8 +43,6 @@ export(data_extract_multiple_srv) export(data_extract_spec) export(data_extract_srv) export(data_extract_ui) -export(data_merge_module) -export(data_merge_srv) export(datanames_input) export(filter_spec) export(format_data_extract) diff --git a/R/Queue.R b/R/Queue.R index bceaf0b2..4709a267 100644 --- a/R/Queue.R +++ b/R/Queue.R @@ -105,6 +105,5 @@ Queue <- R6::R6Class( # nolint private = list( array = c() ), - lock_class = TRUE ) diff --git a/R/check_selector.R b/R/check_selector.R index cd3617e4..53de6540 100644 --- a/R/check_selector.R +++ b/R/check_selector.R @@ -21,9 +21,10 @@ check_selector_filters <- function(filters) { is.list(x) && all(c("columns", "selected") %in% names(x)) && checkmate::test_character(x$columns, null.ok = TRUE, min.len = 1, any.missing = FALSE) && - (is.null(x$selected) || - all(vapply(x$selected, is.character, logical(1))) || - all(vapply(x$selected, is.numeric, logical(1))) + ( + is.null(x$selected) || + all(vapply(x$selected, is.character, logical(1))) || + all(vapply(x$selected, is.numeric, logical(1))) ) } stopifnot(is.null(filters) || all(vapply(filters, check_selector_filter, logical(1)))) diff --git a/R/choices_labeled.R b/R/choices_labeled.R index 93fcc2c7..bf44ddaa 100644 --- a/R/choices_labeled.R +++ b/R/choices_labeled.R @@ -117,10 +117,9 @@ choices_labeled <- function(choices, labels, subset = NULL, types = NULL) { #' #' @description `r lifecycle::badge("stable")` #' -#' @param data (`data.frame`, `character`, `TealDataset`, `TealDatasetConnector`) +#' @param data (`data.frame`, `character`) #' If `data.frame`, then data to extract labels from #' If `character`, then name of the dataset to extract data from once available -#' If `TealDataset` or `TealDatasetConnector`, then raw data to extract labels from. #' @param subset (`character` or `function`) #' If `character`, then a vector of column names. #' If `function`, then this function is used to determine the possible columns (e.g. all factor columns). @@ -144,22 +143,15 @@ choices_labeled <- function(choices, labels, subset = NULL, types = NULL) { #' variable_choices(ADRS) #' variable_choices(ADRS, subset = c("PARAM", "PARAMCD")) #' variable_choices(ADRS, subset = c("", "PARAM", "PARAMCD")) -#' variable_choices(ADRS, subset = c("", "PARAM", "PARAMCD"), key = teal.data::get_cdisc_keys("ADRS")) +#' variable_choices( +#' ADRS, +#' subset = c("", "PARAM", "PARAMCD"), +#' key = teal.data::default_cdisc_join_keys["ADRS", "ADRS"] +#' ) #' #' # delayed version #' variable_choices("ADRS", subset = c("USUBJID", "STUDYID")) #' -#' # also works with [teal.data::TealDataset] and [teal.data::TealDatasetConnector] -#' ADRS_dataset <- teal.data::dataset("ADRS", ADRS, key = teal.data::get_cdisc_keys("ADRS")) -#' variable_choices(ADRS_dataset) -#' -#' ADRS_conn <- teal.data::dataset_connector( -#' "ADRS", -#' pull_callable = teal.data::callable_code("radrs(cached = TRUE)"), -#' key = teal.data::get_cdisc_keys("ADRS") -#' ) -#' variable_choices(ADRS_conn) -#' #' # functional subset (with delayed data) - return only factor variables #' variable_choices("ADRS", subset = function(data) { #' idx <- vapply(data, is.factor, logical(1)) @@ -205,7 +197,8 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key = key <- intersect(subset, key) - var_types <- stats::setNames(teal.slice:::variable_types(data = data), names(data)) + var_types <- vapply(data, function(x) class(x)[[1]], character(1)) + if (length(key) != 0) { var_types[key] <- "primary_key" } @@ -237,49 +230,13 @@ variable_choices.data.frame <- function(data, subset = NULL, fill = TRUE, key = return(res) } -#' @rdname variable_choices -#' @export -variable_choices.TealDataset <- function(data, subset = NULL, fill = FALSE, key = teal.data::get_keys(data)) { - variable_choices( - data = teal.data::get_raw_data(data), - subset = subset, - fill = fill, - key = key - ) -} - -#' @rdname variable_choices -#' @export -variable_choices.TealDatasetConnector <- function(data, # nolint - subset = NULL, - fill = FALSE, - key = teal.data::get_keys(data)) { - if (teal.data::is_pulled(data)) { - variable_choices( - data = teal.data::get_raw_data(data), - subset = subset, - fill = fill, - key = key - ) - } else { - variable_choices( - data = teal.data::get_dataname(data), - subset = subset, - fill = fill, - key = key - ) - } -} - - #' Wrapper on [choices_labeled] to label variable values basing on other variable values #' #' @description `r lifecycle::badge("stable")` #' -#' @param data (`data.frame`, `character`, `TealDataset`, `TealDatasetConnector`) -#' If `data.frame`, then data to extract labels from -#' If `character`, then name of the dataset to extract data from once available -#' If `TealDataset` or `TealDatasetConnector`, then raw data to extract labels from. +#' @param data (`data.frame`, `character`) +#' If `data.frame`, then data to extract labels from. +#' If `character`, then name of the dataset to extract data from once available. #' @param var_choices (`character` or `NULL`) vector with choices column names #' @param var_label (`character`) vector with labels column names #' @param subset (`character` or `function`) @@ -407,47 +364,6 @@ value_choices.data.frame <- function(data, # nolint return(res) } -#' @rdname value_choices -#' @export -value_choices.TealDataset <- function(data, - var_choices, - var_label = NULL, - subset = NULL, - sep = " - ") { - value_choices( - data = teal.data::get_raw_data(data), - var_choices = var_choices, - var_label = var_label, - subset = subset, - sep = sep - ) -} - -#' @rdname value_choices -#' @export -value_choices.TealDatasetConnector <- function(data, # nolint - var_choices, - var_label = NULL, - subset = NULL, - sep = " - ") { - if (teal.data::is_pulled(data)) { - value_choices( - data = teal.data::get_raw_data(data), - var_choices = var_choices, - var_label = var_label, - subset = subset, - sep = sep - ) - } else { - value_choices( - data = teal.data::get_dataname(data), - var_choices = var_choices, - var_label = var_label, - subset = subset, - sep = sep - ) - } -} #' Print choices_labeled object #' @description `r lifecycle::badge("stable")` #' @rdname choices_labeled diff --git a/R/choices_selected.R b/R/choices_selected.R index dd94e199..5c182015 100644 --- a/R/choices_selected.R +++ b/R/choices_selected.R @@ -148,16 +148,7 @@ choices_selected <- function(choices, # remove duplicates choices <- vector_remove_dups(choices) selected <- vector_remove_dups(selected) - - if (!all(selected %in% choices)) { - stop(paste( - paste( - selected[which(!selected %in% choices)], - collapse = ", " - ), - "'selected' but not in 'choices'" - )) - } + checkmate::assert_subset(selected, choices) if (!keep_order && length(choices) > 0) { choices_in_selected <- which(choices %in% selected) diff --git a/R/data_extract_datanames.R b/R/data_extract_datanames.R index fd5a7099..0d2d156b 100644 --- a/R/data_extract_datanames.R +++ b/R/data_extract_datanames.R @@ -37,9 +37,7 @@ get_extract_datanames <- function(data_extracts) { stopifnot(length(data_extracts) > 0) stopifnot( checkmate::test_list(data_extracts, types = "data_extract_spec") || - all( - vapply(data_extracts, function(x) checkmate::test_list(x, types = "data_extract_spec"), logical(1)) - ) + all(vapply(data_extracts, function(x) checkmate::test_list(x, types = "data_extract_spec"), logical(1))) ) datanames <- lapply(data_extracts, function(x) { diff --git a/R/data_extract_filter_module.R b/R/data_extract_filter_module.R index e37dee0b..21dc2b73 100644 --- a/R/data_extract_filter_module.R +++ b/R/data_extract_filter_module.R @@ -18,9 +18,9 @@ data_extract_filter_ui <- function(filter, id = "filter") { html_col <- teal.widgets::optionalSelectInput( inputId = ns("col"), - label = filter$vars_label, - choices = filter$vars_choices, - selected = filter$vars_selected, + label = `if`(inherits(filter, "delayed_filter_spec"), NULL, filter$vars_label), + choices = `if`(inherits(filter, "delayed_filter_spec"), NULL, filter$vars_choices), + selected = `if`(inherits(filter, "delayed_filter_spec"), NULL, filter$vars_selected), multiple = filter$vars_multiple, fixed = filter$vars_fixed ) @@ -28,8 +28,8 @@ data_extract_filter_ui <- function(filter, id = "filter") { html_vals <- teal.widgets::optionalSelectInput( inputId = ns("vals"), label = filter$label, - choices = filter$choices, - selected = filter$selected, + choices = `if`(inherits(filter, "delayed_filter_spec"), NULL, filter$choices), + selected = `if`(inherits(filter, "delayed_filter_spec"), NULL, filter$selected), multiple = filter$multiple, fixed = filter$fixed ) @@ -60,19 +60,31 @@ data_extract_filter_srv <- function(id, datasets, filter) { # We force the evaluation of filter, otherwise the observers are set up with the last element # of the list in data_extract_single_srv and not all of them (due to R lazy evaluation) force(filter) - logger::log_trace( - "data_extract_filter_srv initialized with: { filter$dataname } dataset." - ) + logger::log_trace("data_extract_filter_srv initialized with: { filter$dataname } dataset.") + + isolate({ + # when the filter is initialized with a delayed spec, the choices and selected are NULL + # here delayed are resolved and the values are set up + teal.widgets::updateOptionalSelectInput( + session = session, + inputId = "col", + choices = filter$vars_choices, + selected = filter$vars_selected + ) + teal.widgets::updateOptionalSelectInput( + session = session, + inputId = "vals", + choices = filter$choices, + selected = filter$selected + ) + }) - observeEvent(input$col, + observeEvent( + input$col, + ignoreInit = TRUE, # When observeEvent is initialized input$col is still NULL as it is set few lines above + ignoreNULL = FALSE, # columns could be NULL, then vals should be set to NULL also handlerExpr = { - if (!filter$initialized) { - initial_inputs <- get_initial_filter_values(filter, datasets) - choices <- initial_inputs$choices - selected <- initial_inputs$selected - filter$initialized <- TRUE - filter <<- filter - } else if (!rlang::is_empty(input$col)) { + if (!rlang::is_empty(input$col)) { choices <- value_choices( datasets[[filter$dataname]](), input$col, @@ -108,9 +120,7 @@ data_extract_filter_srv <- function(id, datasets, filter) { choices = choices, selected = selected ) - }, - ignoreInit = FALSE, - ignoreNULL = FALSE + } ) } ) diff --git a/R/data_extract_module.R b/R/data_extract_module.R index 87f2646a..9921ef00 100644 --- a/R/data_extract_module.R +++ b/R/data_extract_module.R @@ -250,7 +250,7 @@ check_data_extract_spec_react <- function(datasets, data_extract) { #' #' @inheritParams shiny::moduleServer #' @param datasets (`FilteredData` or `list` of `reactive` or non-`reactive` `data.frame`)\cr -#' object containing data either in the form of [teal.slice::FilteredData] or as a list of `data.frame`. +#' object containing data either in the form of `FilteredData` or as a list of `data.frame`. #' When passing a list of non-reactive `data.frame` objects, they are converted to reactive `data.frame`s internally. #' When passing a list of reactive or non-reactive `data.frame` objects, the argument `join_keys` is required also. #' @param data_extract_spec (`data_extract_spec` or a list of `data_extract_spec`)\cr @@ -349,13 +349,6 @@ check_data_extract_spec_react <- function(datasets, data_extract) { #' shinyApp(app$ui, app$server) #' } #' -#' # Using FilteredData - Note this method will be deprecated -#' datasets <- teal.slice::init_filtered_data( -#' list(ADSL = list(dataset = ADSL)), -#' join_keys = teal.data::join_keys( -#' teal.data::join_key("ADSL", "ADSL", c("USUBJID", "STUDYID")) -#' ) -#' ) #' #' app <- shinyApp( #' ui = fluidPage( @@ -551,7 +544,6 @@ data_extract_srv.list <- function(id, datasets, data_extract_spec, join_keys = N #' @description `r lifecycle::badge("experimental")` #' `data_extract_multiple_srv` loops over the list of `data_extract` given and #' runs `data_extract_srv` for each one returning a list of reactive objects. -#' This was suitable as input for (deprecated) [data_merge_srv()]. #' #' @inheritParams data_extract_srv #' @param data_extract (named `list` of `data_extract_spec` objects) the list `data_extract_spec` objects. @@ -655,15 +647,23 @@ data_extract_srv.list <- function(id, datasets, data_extract_spec, join_keys = N #' } data_extract_multiple_srv <- function(data_extract, datasets, ...) { checkmate::assert_list(data_extract, names = "named") + checkmate::assert_multi_class(datasets, c("reactive", "FilteredData", "list")) lapply(data_extract, function(x) { if (is.list(x) && !inherits(x, "data_extract_spec")) { checkmate::assert_list(x, "data_extract_spec") } }) - checkmate::assert_multi_class(datasets, classes = c("FilteredData", "list")) UseMethod("data_extract_multiple_srv", datasets) } +#' @rdname data_extract_multiple_srv +#' @export +data_extract_multiple_srv.reactive <- function(data_extract, datasets, ...) { + # convert reactive containing teal_data to list of reactives with one dataset each + datasets_new <- convert_teal_data(datasets) + data_extract_multiple_srv.list(data_extract, datasets_new, ...) +} + #' @rdname data_extract_multiple_srv #' @export data_extract_multiple_srv.FilteredData <- function(data_extract, datasets, ...) { diff --git a/R/data_extract_read_module.R b/R/data_extract_read_module.R index 8425c284..15eeaa8f 100644 --- a/R/data_extract_read_module.R +++ b/R/data_extract_read_module.R @@ -30,9 +30,11 @@ data_extract_read_srv <- function(id, datasets, single_data_extract_spec, iv, se } for (col in input_col) { # replace NA with NA_character_ for class consistency - if (any(vapply(input_vals, identical, logical(1), "NA")) && - anyNA(datasets[[x$dataname]]()[col]) && - !any(vapply(unique(datasets[[x$dataname]]()[col]), identical, logical(1), "NA"))) { + if ( + any(vapply(input_vals, identical, logical(1), "NA")) && + anyNA(datasets[[x$dataname]]()[col]) && + !any(vapply(unique(datasets[[x$dataname]]()[col]), identical, logical(1), "NA")) + ) { input_vals[vapply(input_vals, identical, logical(1), "NA")] <- NA_character_ } } diff --git a/R/data_extract_select_module.R b/R/data_extract_select_module.R index f8c15fec..79d84ef4 100644 --- a/R/data_extract_select_module.R +++ b/R/data_extract_select_module.R @@ -20,8 +20,8 @@ data_extract_select_ui <- function(select, id = "select") { teal.widgets::optionalSelectInput( inputId = id, label = select$label, - choices = select$choices, - selected = select$selected, + choices = `if`(inherits(select, "delayed_select_spec"), NULL, select$choices), + selected = `if`(inherits(select, "delayed_select_spec"), NULL, select$selected), multiple = select$multiple, fixed = select$fixed ) diff --git a/R/data_extract_single_module.R b/R/data_extract_single_module.R index de75f7bf..8616b0e8 100644 --- a/R/data_extract_single_module.R +++ b/R/data_extract_single_module.R @@ -73,11 +73,22 @@ data_extract_single_srv <- function(id, datasets, single_data_extract_spec) { moduleServer( id, function(input, output, session) { - logger::log_trace( - "data_extract_single_srv initialized with dataset: { single_data_extract_spec$dataname }." - ) - for (idx in seq_along(single_data_extract_spec$filter)) { - x <- single_data_extract_spec$filter[[idx]] + logger::log_trace("data_extract_single_srv initialized with dataset: { single_data_extract_spec$dataname }.") + + # ui could be initialized with a delayed select spec so the choices and selected are NULL + # here delayed are resolved + isolate({ + resolved <- resolve_delayed(single_data_extract_spec, datasets) + teal.widgets::updateOptionalSelectInput( + session = session, + inputId = "select", + choices = resolved$select$choices, + selected = resolved$select$selected + ) + }) + + for (idx in seq_along(resolved$filter)) { + x <- resolved$filter[[idx]] if (inherits(x, "filter_spec")) { data_extract_filter_srv( id = paste0("filter", idx), diff --git a/R/data_extract_spec.R b/R/data_extract_spec.R index 7c66f4a0..8bcdb78b 100644 --- a/R/data_extract_spec.R +++ b/R/data_extract_spec.R @@ -107,8 +107,10 @@ data_extract_spec <- function(dataname, select = NULL, filter = NULL, reshape = for (idx in seq_along(filter)) filter[[idx]]$dataname <- dataname - if (inherits(select, "delayed_select_spec") || - any(vapply(filter, inherits, logical(1), "delayed_filter_spec"))) { + if ( + inherits(select, "delayed_select_spec") || + any(vapply(filter, inherits, logical(1), "delayed_filter_spec")) + ) { structure( list(dataname = dataname, select = select, filter = filter, reshape = reshape), class = c("delayed_data_extract_spec", "delayed_data", "data_extract_spec") diff --git a/R/data_merge_module.R b/R/data_merge_module.R deleted file mode 100644 index 781f32db..00000000 --- a/R/data_merge_module.R +++ /dev/null @@ -1,61 +0,0 @@ -#' Data merge module -#' -#' @description `r lifecycle::badge("deprecated")` -#' @details This function was a convenient wrapper to combine `data_extract_multiple_srv()` and -#' `data_merge_srv()` when no additional processing is required. -#' -#' @inheritParams shiny::moduleServer -#' @param datasets (`FilteredData`)\cr -#' object containing data, see [teal.slice::FilteredData] for more. -#' @param data_extract (named `list` of `data_extract_spec`)\cr -#' @param merge_function (`character(1)`)\cr -#' A character string of a function that -#' accepts the arguments `x`, `y` and `by` to perform the merging of datasets. -#' @param anl_name (`character(1)`)\cr -#' Name of the analysis dataset. -#' -#' @return reactive expression with output from [data_merge_srv()]. -#' -#' @seealso [data_merge_srv()] -#' -#' @export -data_merge_module <- function(datasets, - data_extract, - merge_function = "dplyr::full_join", - anl_name = "ANL", - id = "merge_id") { - lifecycle::deprecate_stop("0.3.1", "data_merge_module()") -} - - -#' Data merge module server -#' -#' @description `r lifecycle::badge("deprecated")` -#' @details When additional processing of the `data_extract` list input was required, `data_merge_srv()` could be -#' combined with `data_extract_multiple_srv()` or `data_extract_srv()` to influence the `selector_list` input. -#' -#' @inheritParams shiny::moduleServer -#' @param selector_list (`reactive`)\cr -#' output from [data_extract_multiple_srv()] or a reactive named list of outputs from [data_extract_srv()]. -#' When using a reactive named list, the names must be identical to the shiny ids of the -#' respective [data_extract_ui()]. -#' @param datasets (`FilteredData`)\cr -#' object containing data (see `teal.slice::FilteredData`). -#' @param merge_function (`character(1)` or `reactive`)\cr -#' A character string of a function that accepts the arguments -#' `x`, `y` and `by` to perform the merging of datasets. -#' @param anl_name (`character(1)`)\cr -#' Name of the analysis dataset. -#' -#' @return reactive expression with output from [merge_datasets]. -#' -#' @seealso [data_extract_srv()] -#' -#' @export -data_merge_srv <- function(id = "merge_id", - selector_list, - datasets, - merge_function = "dplyr::full_join", - anl_name = "ANL") { - lifecycle::deprecate_stop("0.3.1", "data_merge_srv()") -} diff --git a/R/filter_spec.R b/R/filter_spec.R index 4ea59354..a54afacf 100644 --- a/R/filter_spec.R +++ b/R/filter_spec.R @@ -258,10 +258,12 @@ filter_spec_internal <- function(vars_choices, checkmate::assert_string(sep) checkmate::assert_flag(drop_keys) - if (inherits(vars_choices, "delayed_data") || - inherits(vars_selected, "delayed_data") || - inherits(choices, "delayed_data") || - inherits(selected, "delayed_data")) { + if ( + inherits(vars_choices, "delayed_data") || + inherits(vars_selected, "delayed_data") || + inherits(choices, "delayed_data") || + inherits(selected, "delayed_data") + ) { filter_spec_internal.delayed_data( vars_choices = vars_choices, vars_selected = vars_selected, @@ -380,7 +382,7 @@ filter_spec_internal.default <- function(vars_choices, checkmate::check_numeric(vars_choices, min.len = 1, any.missing = FALSE), checkmate::check_logical(vars_choices, min.len = 1, any.missing = FALSE) ) - stopifnot(all(!duplicated(vars_choices))) + checkmate::assert_vector(vars_choices, unique = TRUE) if (!is.null(vars_selected)) { stopifnot(vars_multiple || length(vars_selected) == 1) @@ -389,12 +391,12 @@ filter_spec_internal.default <- function(vars_choices, checkmate::check_numeric(vars_selected, min.len = 1, any.missing = FALSE), checkmate::check_logical(vars_selected, min.len = 1, any.missing = FALSE) ) - stopifnot(all(!duplicated(vars_selected))) - stopifnot(all(vars_selected %in% vars_choices)) + checkmate::assert_vector(vars_selected, unique = TRUE) + checkmate::assert_subset(vars_selected, vars_choices) } if (!is.null(choices)) { - stopifnot(all(!duplicated(choices))) + checkmate::assert_vector(choices, unique = TRUE) split_choices <- split_by_sep(choices, sep) stopifnot(all(vapply(split_choices, length, integer(1)) == length(vars_selected))) } @@ -406,8 +408,8 @@ filter_spec_internal.default <- function(vars_choices, checkmate::check_numeric(selected, min.len = 1, any.missing = FALSE), checkmate::check_logical(selected, min.len = 1, any.missing = FALSE) ) - stopifnot(all(!duplicated(selected))) - stopifnot(all(selected %in% choices)) + checkmate::assert_vector(selected, unique = TRUE) + checkmate::assert_subset(selected, choices) } res <- list( diff --git a/R/format_data_extract.R b/R/format_data_extract.R index e516f798..4f378e1a 100644 --- a/R/format_data_extract.R +++ b/R/format_data_extract.R @@ -13,12 +13,6 @@ #' select = select_spec(choices = c("Petal.Length", "Species")) #' ) #' -#' sample_filtered_data <- { -#' teal.slice::init_filtered_data( -#' list(iris = list(dataset = iris)) -#' ) -#' } -#' #' if (interactive()) { #' shiny::shinyApp( #' ui = shiny::fluidPage( @@ -33,7 +27,7 @@ #' server = function(input, output, session) { #' extracted_input <- data_extract_srv( #' id = "extract", -#' datasets = sample_filtered_data, +#' datasets = list(iris = iris), #' data_extract_spec = simple_des #' ) #' output$formatted_extract <- shiny::renderPrint({ diff --git a/R/get_dplyr_call.R b/R/get_dplyr_call.R index e74a37b9..a50fcd06 100644 --- a/R/get_dplyr_call.R +++ b/R/get_dplyr_call.R @@ -135,7 +135,7 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys( #' dataname = "ADSL", #' filters = NULL, #' select = character(0), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test1" #' )) @@ -145,7 +145,7 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys( #' dataname = "ADSL", #' filters = list(list(columns = "SEX", selected = list("F", "M"))), #' select = character(0), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test1" #' )) @@ -155,7 +155,7 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys( #' dataname = "ADSL", #' filters = list(list(columns = "SEX", selected = list("F", "M"))), #' select = c("AVAL"), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test1" #' )) @@ -168,7 +168,7 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys( #' dataname = "ADSL", #' filters = NULL, #' select = c("COL_1", "COL_2"), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test1" #' ), @@ -176,7 +176,7 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys( #' dataname = "ADSL", #' filters = NULL, #' select = c("COL_2", "COL_3"), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test2" #' ) @@ -193,7 +193,7 @@ get_dplyr_call_data <- function(selector_list, join_keys = teal.data::join_keys( #' selected = list(c("ALBCV", "SCREENING"), c("ALBCV", "BASELINE")) #' )), #' select = c("AVAL"), -#' keys = teal.data::get_cdisc_keys("ADLB"), +#' keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), #' reshape = TRUE, #' internal_id = "test1" #' )) @@ -414,7 +414,7 @@ rename_duplicated_cols <- function(x, internal_id, selected_cols, all_cols) { #' dataname = "ADSL", #' filters = NULL, #' select = utils::head(letters, 3), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test1" #' ), @@ -422,7 +422,7 @@ rename_duplicated_cols <- function(x, internal_id, selected_cols, all_cols) { #' dataname = "ADSL", #' filters = NULL, #' select = letters, -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test2" #' ), @@ -430,7 +430,7 @@ rename_duplicated_cols <- function(x, internal_id, selected_cols, all_cols) { #' dataname = "ADSL", #' filters = NULL, #' select = utils::tail(letters, 3), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test3" #' ), @@ -438,7 +438,7 @@ rename_duplicated_cols <- function(x, internal_id, selected_cols, all_cols) { #' dataname = "ADSL", #' filters = NULL, #' select = c("aa", "bb"), -#' keys = teal.data::get_cdisc_keys("ADSL"), +#' keys = c("STUDYID", "USUBJID"), #' reshape = FALSE, #' internal_id = "test4" #' ) @@ -499,7 +499,7 @@ get_rename_call <- function(selector_list = list(), #' multiple = FALSE #' )), #' select = "AVAL", -#' keys = teal.data::get_cdisc_keys("ADLB"), +#' keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), #' reshape = TRUE, #' internal_id = "test" #' ) diff --git a/R/merge_expression_module.R b/R/merge_expression_module.R index 9fb186ea..6696671d 100644 --- a/R/merge_expression_module.R +++ b/R/merge_expression_module.R @@ -139,8 +139,37 @@ merge_expression_module <- function(datasets, merge_function = "dplyr::full_join", anl_name = "ANL", id = "merge_id") { + UseMethod("merge_expression_module", datasets) +} + +#' @rdname merge_expression_module +#' @export +merge_expression_module.reactive <- function(datasets, + join_keys = NULL, + data_extract, + merge_function = "dplyr::full_join", + anl_name = "ANL", + id = "merge_id") { + checkmate::assert_class(isolate(datasets()), "teal_data") + datasets_new <- convert_teal_data(datasets) + if (is.reactive(datasets) && inherits(isolate(datasets()), "teal_data")) { + join_keys <- isolate(teal.data::join_keys(datasets())) + } + merge_expression_module(datasets_new, join_keys, data_extract, merge_function, anl_name, id) +} + +#' @rdname merge_expression_module +#' @export +merge_expression_module.list <- function(datasets, + join_keys = NULL, + data_extract, + merge_function = "dplyr::full_join", + anl_name = "ANL", + id = "merge_id") { logger::log_trace("merge_expression_module called with: { paste(names(datasets), collapse = ', ') } datasets.") + checkmate::assert_list(datasets, names = "named") checkmate::assert_list(data_extract, names = "named", types = c("list", "data_extract_spec", "NULL")) + checkmate::assert_class(join_keys, "join_keys") lapply(data_extract, function(x) { if (is.list(x) && !inherits(x, "data_extract_spec")) { checkmate::assert_list(x, "data_extract_spec") @@ -311,10 +340,37 @@ merge_expression_srv <- function(id = "merge_id", join_keys, merge_function = "dplyr::full_join", anl_name = "ANL") { + UseMethod("merge_expression_srv", datasets) +} + +#' @rdname merge_expression_srv +#' @export +merge_expression_srv.reactive <- function(id = "merge_id", + selector_list, + datasets, + join_keys, + merge_function = "dplyr::full_join", + anl_name = "ANL") { + checkmate::assert_class(isolate(datasets()), "teal_data") + datasets_new <- convert_teal_data(datasets) + if (is.reactive(datasets) && inherits(isolate(datasets()), "teal_data")) { + join_keys <- isolate(teal.data::join_keys(datasets())) + } + merge_expression_srv(id, selector_list, datasets_new, join_keys, merge_function, anl_name) +} + +#' @rdname merge_expression_srv +#' @export +merge_expression_srv.list <- function(id = "merge_id", + selector_list, + datasets, + join_keys, + merge_function = "dplyr::full_join", + anl_name = "ANL") { + checkmate::assert_list(datasets, names = "named") checkmate::assert_string(anl_name) stopifnot(make.names(anl_name) == anl_name) checkmate::assert_class(selector_list, "reactive") - checkmate::assert_list(datasets, types = c("reactive", "data.frame"), names = "named") checkmate::assert_class(join_keys, "join_keys") moduleServer( @@ -324,11 +380,6 @@ merge_expression_srv <- function(id = "merge_id", "merge_expression_srv initialized with: { paste(names(datasets), collapse = ', ') } datasets." ) - # convert to list of reactives - datasets <- sapply(X = datasets, simplify = FALSE, FUN = function(x) { - if (is.reactive(x)) x else reactive(x) - }) - reactive({ checkmate::assert_list(selector_list(), names = "named", types = "reactive") merge_fun_name <- if (inherits(merge_function, "reactive")) merge_function() else merge_function diff --git a/R/resolve.R b/R/resolve.R index afd4607e..b3986d76 100644 --- a/R/resolve.R +++ b/R/resolve.R @@ -11,7 +11,7 @@ #' #' @examples #' ADSL <- teal.transform::rADSL -#' attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") +#' attr(ADSL, "keys") <- c("STUDYID", "USUBJID") #' data_list <- list(ADSL = shiny::reactive(ADSL)) #' keys <- list(ADSL = attr(ADSL, "keys")) #' shiny::isolate({ @@ -175,7 +175,7 @@ resolve.default <- function(x, datasets, keys) { #' #' @param x (`function`) Function that is applied on dataset. #' It must take only a single argument "data" and return character vector with columns / values. -#' @param ds (`data.frame`) `TealDataset` on which the function is applied to. +#' @param ds (`data.frame`) Dataset. #' @param is_value_choices (`logical`) Determines which check of the returned value will be applied. #' #' @return Character vector - result of calling function `x` on dataset `ds`. diff --git a/R/resolve_delayed.R b/R/resolve_delayed.R index 74f361f4..0ae03fba 100644 --- a/R/resolve_delayed.R +++ b/R/resolve_delayed.R @@ -14,19 +14,17 @@ #' @examples #' ADSL <- teal.transform::rADSL #' shiny::isolate({ -#' ds <- teal.slice::init_filtered_data( -#' list(ADSL = list(dataset = ADSL)) -#' ) +#' data_list <- list(ADSL = shiny::reactive(ADSL)) #' #' # value_choices example #' v1 <- value_choices("ADSL", "SEX", "SEX") #' v1 -#' resolve_delayed(v1, ds) +#' resolve_delayed(v1, data_list) #' #' # variable_choices example #' v2 <- variable_choices("ADSL", c("BMRKR1", "BMRKR2")) #' v2 -#' resolve_delayed(v2, ds) +#' resolve_delayed(v2, data_list) #' #' # data_extract_spec example #' adsl_filter <- filter_spec( @@ -52,9 +50,9 @@ #' filter = adsl_filter #' ) #' -#' resolve_delayed(adsl_filter, ds) -#' resolve_delayed(adsl_select, ds) -#' resolve_delayed(adsl_de, ds) +#' resolve_delayed(adsl_filter, datasets = data_list) +#' resolve_delayed(adsl_select, datasets = data_list) +#' resolve_delayed(adsl_de, datasets = data_list) #' #' # nested list (arm_ref_comp) #' arm_ref_comp <- list( @@ -64,7 +62,7 @@ #' ) #' ) #' -#' resolve_delayed(arm_ref_comp, ds) +#' resolve_delayed(arm_ref_comp, datasets = data_list) #' }) resolve_delayed <- function(x, datasets, keys) { UseMethod("resolve_delayed", datasets) diff --git a/R/select_spec.R b/R/select_spec.R index f559d90f..6da0d183 100644 --- a/R/select_spec.R +++ b/R/select_spec.R @@ -156,7 +156,7 @@ select_spec.default <- function(choices, # nolint # Deal with selected if (length(selected) > 0) { stopifnot(is.atomic(selected)) - stopifnot(all(selected %in% choices)) + checkmate::assert_subset(selected, choices) stopifnot(multiple || length(selected) == 1) if (is.null(names(selected))) { names(selected) <- as.character(selected) diff --git a/R/utils.R b/R/utils.R index 67495a91..ca3d9189 100644 --- a/R/utils.R +++ b/R/utils.R @@ -156,3 +156,21 @@ compose_and_enable_validators <- function(iv, selector_list, validator_names = N iv$enable() iv } + +convert_teal_data <- function(datasets) { + if (is.list(datasets)) { + sapply(X = datasets, simplify = FALSE, FUN = function(x) { + if (is.reactive(x)) x else reactive(x) + }) + } else if (is.reactive(datasets) && inherits(isolate(datasets()), "teal_data")) { + sapply( + isolate(teal.data::datanames(datasets())), + function(dataname) { + reactive(datasets()[[dataname]]) + }, + simplify = FALSE + ) + } else { + stop("datasets must be a list of reactive dataframes or a teal_data object") + } +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 2fc44dca..d547d427 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -46,8 +46,6 @@ reference: - data_extract_multiple_srv - data_extract_ui - data_extract_srv - - data_merge_srv - - data_merge_module - datanames_input - merge_expression_module - merge_expression_srv diff --git a/man/data_extract_multiple_srv.Rd b/man/data_extract_multiple_srv.Rd index 0e7e679a..353c7b01 100644 --- a/man/data_extract_multiple_srv.Rd +++ b/man/data_extract_multiple_srv.Rd @@ -2,12 +2,15 @@ % Please edit documentation in R/data_extract_module.R \name{data_extract_multiple_srv} \alias{data_extract_multiple_srv} +\alias{data_extract_multiple_srv.reactive} \alias{data_extract_multiple_srv.FilteredData} \alias{data_extract_multiple_srv.list} \title{Creates a named list of \code{data_extract_srv} output} \usage{ data_extract_multiple_srv(data_extract, datasets, ...) +\method{data_extract_multiple_srv}{reactive}(data_extract, datasets, ...) + \method{data_extract_multiple_srv}{FilteredData}(data_extract, datasets, ...) \method{data_extract_multiple_srv}{list}( @@ -32,7 +35,7 @@ The names of the elements in the list need to correspond to the \code{ids} passe See example for details.} \item{datasets}{(\code{FilteredData} or \code{list} of \code{reactive} or non-\code{reactive} \code{data.frame})\cr -object containing data either in the form of \link[teal.slice:FilteredData]{teal.slice::FilteredData} or as a list of \code{data.frame}. +object containing data either in the form of \code{FilteredData} or as a list of \code{data.frame}. When passing a list of non-reactive \code{data.frame} objects, they are converted to reactive \code{data.frame}s internally. When passing a list of reactive or non-reactive \code{data.frame} objects, the argument \code{join_keys} is required also.} @@ -62,7 +65,6 @@ names are the same as \code{data_extract} input argument. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} \code{data_extract_multiple_srv} loops over the list of \code{data_extract} given and runs \code{data_extract_srv} for each one returning a list of reactive objects. -This was suitable as input for (deprecated) \code{\link[=data_merge_srv]{data_merge_srv()}}. } \examples{ library(shiny) diff --git a/man/data_extract_srv.Rd b/man/data_extract_srv.Rd index 75d228ee..9205291d 100644 --- a/man/data_extract_srv.Rd +++ b/man/data_extract_srv.Rd @@ -32,7 +32,7 @@ data_extract_srv(id, datasets, data_extract_spec, ...) UI function.} \item{datasets}{(\code{FilteredData} or \code{list} of \code{reactive} or non-\code{reactive} \code{data.frame})\cr -object containing data either in the form of \link[teal.slice:FilteredData]{teal.slice::FilteredData} or as a list of \code{data.frame}. +object containing data either in the form of \code{FilteredData} or as a list of \code{data.frame}. When passing a list of non-reactive \code{data.frame} objects, they are converted to reactive \code{data.frame}s internally. When passing a list of reactive or non-reactive \code{data.frame} objects, the argument \code{join_keys} is required also.} @@ -147,13 +147,6 @@ if (interactive()) { shinyApp(app$ui, app$server) } -# Using FilteredData - Note this method will be deprecated -datasets <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = ADSL)), - join_keys = teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", c("USUBJID", "STUDYID")) - ) -) app <- shinyApp( ui = fluidPage( diff --git a/man/data_merge_module.Rd b/man/data_merge_module.Rd deleted file mode 100644 index 2171f895..00000000 --- a/man/data_merge_module.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data_merge_module.R -\name{data_merge_module} -\alias{data_merge_module} -\title{Data merge module} -\usage{ -data_merge_module( - datasets, - data_extract, - merge_function = "dplyr::full_join", - anl_name = "ANL", - id = "merge_id" -) -} -\arguments{ -\item{datasets}{(\code{FilteredData})\cr -object containing data, see \link[teal.slice:FilteredData]{teal.slice::FilteredData} for more.} - -\item{data_extract}{(named \code{list} of \code{data_extract_spec})\cr} - -\item{merge_function}{(\code{character(1)})\cr -A character string of a function that -accepts the arguments \code{x}, \code{y} and \code{by} to perform the merging of datasets.} - -\item{anl_name}{(\code{character(1)})\cr -Name of the analysis dataset.} - -\item{id}{An ID string that corresponds with the ID used to call the module's -UI function.} -} -\value{ -reactive expression with output from \code{\link[=data_merge_srv]{data_merge_srv()}}. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -} -\details{ -This function was a convenient wrapper to combine \code{data_extract_multiple_srv()} and -\code{data_merge_srv()} when no additional processing is required. -} -\seealso{ -\code{\link[=data_merge_srv]{data_merge_srv()}} -} diff --git a/man/data_merge_srv.Rd b/man/data_merge_srv.Rd deleted file mode 100644 index 392660ae..00000000 --- a/man/data_merge_srv.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data_merge_module.R -\name{data_merge_srv} -\alias{data_merge_srv} -\title{Data merge module server} -\usage{ -data_merge_srv( - id = "merge_id", - selector_list, - datasets, - merge_function = "dplyr::full_join", - anl_name = "ANL" -) -} -\arguments{ -\item{id}{An ID string that corresponds with the ID used to call the module's -UI function.} - -\item{selector_list}{(\code{reactive})\cr -output from \code{\link[=data_extract_multiple_srv]{data_extract_multiple_srv()}} or a reactive named list of outputs from \code{\link[=data_extract_srv]{data_extract_srv()}}. -When using a reactive named list, the names must be identical to the shiny ids of the -respective \code{\link[=data_extract_ui]{data_extract_ui()}}.} - -\item{datasets}{(\code{FilteredData})\cr -object containing data (see \code{teal.slice::FilteredData}).} - -\item{merge_function}{(\code{character(1)} or \code{reactive})\cr -A character string of a function that accepts the arguments -\code{x}, \code{y} and \code{by} to perform the merging of datasets.} - -\item{anl_name}{(\code{character(1)})\cr -Name of the analysis dataset.} -} -\value{ -reactive expression with output from \link{merge_datasets}. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -} -\details{ -When additional processing of the \code{data_extract} list input was required, \code{data_merge_srv()} could be -combined with \code{data_extract_multiple_srv()} or \code{data_extract_srv()} to influence the \code{selector_list} input. -} -\seealso{ -\code{\link[=data_extract_srv]{data_extract_srv()}} -} diff --git a/man/format_data_extract.Rd b/man/format_data_extract.Rd index a73100c5..fb82af7f 100644 --- a/man/format_data_extract.Rd +++ b/man/format_data_extract.Rd @@ -25,12 +25,6 @@ simple_des <- data_extract_spec( select = select_spec(choices = c("Petal.Length", "Species")) ) -sample_filtered_data <- { - teal.slice::init_filtered_data( - list(iris = list(dataset = iris)) - ) -} - if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage( @@ -45,7 +39,7 @@ if (interactive()) { server = function(input, output, session) { extracted_input <- data_extract_srv( id = "extract", - datasets = sample_filtered_data, + datasets = list(iris = iris), data_extract_spec = simple_des ) output$formatted_extract <- shiny::renderPrint({ diff --git a/man/get_dplyr_call.Rd b/man/get_dplyr_call.Rd index ce688c49..9c228814 100644 --- a/man/get_dplyr_call.Rd +++ b/man/get_dplyr_call.Rd @@ -40,7 +40,7 @@ teal.transform:::get_dplyr_call( dataname = "ADSL", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )) @@ -50,7 +50,7 @@ teal.transform:::get_dplyr_call( dataname = "ADSL", filters = list(list(columns = "SEX", selected = list("F", "M"))), select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )) @@ -60,7 +60,7 @@ teal.transform:::get_dplyr_call( dataname = "ADSL", filters = list(list(columns = "SEX", selected = list("F", "M"))), select = c("AVAL"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )) @@ -73,7 +73,7 @@ teal.transform:::get_dplyr_call( dataname = "ADSL", filters = NULL, select = c("COL_1", "COL_2"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -81,7 +81,7 @@ teal.transform:::get_dplyr_call( dataname = "ADSL", filters = NULL, select = c("COL_2", "COL_3"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ) @@ -98,7 +98,7 @@ teal.transform:::get_dplyr_call( selected = list(c("ALBCV", "SCREENING"), c("ALBCV", "BASELINE")) )), select = c("AVAL"), - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test1" )) diff --git a/man/get_rename_call.Rd b/man/get_rename_call.Rd index 2e0c036f..0ee5db6a 100644 --- a/man/get_rename_call.Rd +++ b/man/get_rename_call.Rd @@ -36,7 +36,7 @@ x <- list( dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -44,7 +44,7 @@ x <- list( dataname = "ADSL", filters = NULL, select = letters, - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ), @@ -52,7 +52,7 @@ x <- list( dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test3" ), @@ -60,7 +60,7 @@ x <- list( dataname = "ADSL", filters = NULL, select = c("aa", "bb"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test4" ) diff --git a/man/get_reshape_call.Rd b/man/get_reshape_call.Rd index 3e447d66..24208368 100644 --- a/man/get_reshape_call.Rd +++ b/man/get_reshape_call.Rd @@ -47,7 +47,7 @@ x <- list( multiple = FALSE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test" ) diff --git a/man/merge_expression_module.Rd b/man/merge_expression_module.Rd index ae3cec30..e46090b7 100644 --- a/man/merge_expression_module.Rd +++ b/man/merge_expression_module.Rd @@ -2,6 +2,8 @@ % Please edit documentation in R/merge_expression_module.R \name{merge_expression_module} \alias{merge_expression_module} +\alias{merge_expression_module.reactive} +\alias{merge_expression_module.list} \title{Merge expression module} \usage{ merge_expression_module( @@ -12,6 +14,24 @@ merge_expression_module( anl_name = "ANL", id = "merge_id" ) + +\method{merge_expression_module}{reactive}( + datasets, + join_keys = NULL, + data_extract, + merge_function = "dplyr::full_join", + anl_name = "ANL", + id = "merge_id" +) + +\method{merge_expression_module}{list}( + datasets, + join_keys = NULL, + data_extract, + merge_function = "dplyr::full_join", + anl_name = "ANL", + id = "merge_id" +) } \arguments{ \item{datasets}{(named \code{list} of \code{reactive} or non-\code{reactive} \code{data.frame})\cr diff --git a/man/merge_expression_srv.Rd b/man/merge_expression_srv.Rd index b38870f9..58235caa 100644 --- a/man/merge_expression_srv.Rd +++ b/man/merge_expression_srv.Rd @@ -2,6 +2,8 @@ % Please edit documentation in R/merge_expression_module.R \name{merge_expression_srv} \alias{merge_expression_srv} +\alias{merge_expression_srv.reactive} +\alias{merge_expression_srv.list} \title{Data merge module server} \usage{ merge_expression_srv( @@ -12,6 +14,24 @@ merge_expression_srv( merge_function = "dplyr::full_join", anl_name = "ANL" ) + +\method{merge_expression_srv}{reactive}( + id = "merge_id", + selector_list, + datasets, + join_keys, + merge_function = "dplyr::full_join", + anl_name = "ANL" +) + +\method{merge_expression_srv}{list}( + id = "merge_id", + selector_list, + datasets, + join_keys, + merge_function = "dplyr::full_join", + anl_name = "ANL" +) } \arguments{ \item{id}{An ID string that corresponds with the ID used to call the module's diff --git a/man/resolve.Rd b/man/resolve.Rd index 7a8f6c1e..c5676855 100644 --- a/man/resolve.Rd +++ b/man/resolve.Rd @@ -22,7 +22,7 @@ Resolved object. } \examples{ ADSL <- teal.transform::rADSL -attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") +attr(ADSL, "keys") <- c("STUDYID", "USUBJID") data_list <- list(ADSL = shiny::reactive(ADSL)) keys <- list(ADSL = attr(ADSL, "keys")) shiny::isolate({ diff --git a/man/resolve_delayed.Rd b/man/resolve_delayed.Rd index a3ea4ecb..9cfb16e8 100644 --- a/man/resolve_delayed.Rd +++ b/man/resolve_delayed.Rd @@ -23,19 +23,17 @@ Resolved object. \examples{ ADSL <- teal.transform::rADSL shiny::isolate({ - ds <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = ADSL)) - ) + data_list <- list(ADSL = shiny::reactive(ADSL)) # value_choices example v1 <- value_choices("ADSL", "SEX", "SEX") v1 - resolve_delayed(v1, ds) + resolve_delayed(v1, data_list) # variable_choices example v2 <- variable_choices("ADSL", c("BMRKR1", "BMRKR2")) v2 - resolve_delayed(v2, ds) + resolve_delayed(v2, data_list) # data_extract_spec example adsl_filter <- filter_spec( @@ -61,9 +59,9 @@ shiny::isolate({ filter = adsl_filter ) - resolve_delayed(adsl_filter, ds) - resolve_delayed(adsl_select, ds) - resolve_delayed(adsl_de, ds) + resolve_delayed(adsl_filter, datasets = data_list) + resolve_delayed(adsl_select, datasets = data_list) + resolve_delayed(adsl_de, datasets = data_list) # nested list (arm_ref_comp) arm_ref_comp <- list( @@ -73,6 +71,6 @@ shiny::isolate({ ) ) - resolve_delayed(arm_ref_comp, ds) + resolve_delayed(arm_ref_comp, datasets = data_list) }) } diff --git a/man/resolve_delayed_expr.Rd b/man/resolve_delayed_expr.Rd index e14043aa..45b36a90 100644 --- a/man/resolve_delayed_expr.Rd +++ b/man/resolve_delayed_expr.Rd @@ -10,7 +10,7 @@ resolve_delayed_expr(x, ds, is_value_choices) \item{x}{(\code{function}) Function that is applied on dataset. It must take only a single argument "data" and return character vector with columns / values.} -\item{ds}{(\code{data.frame}) \code{TealDataset} on which the function is applied to.} +\item{ds}{(\code{data.frame}) Dataset.} \item{is_value_choices}{(\code{logical}) Determines which check of the returned value will be applied.} } diff --git a/man/value_choices.Rd b/man/value_choices.Rd index 0e892169..aa48f870 100644 --- a/man/value_choices.Rd +++ b/man/value_choices.Rd @@ -4,8 +4,6 @@ \alias{value_choices} \alias{value_choices.character} \alias{value_choices.data.frame} -\alias{value_choices.TealDataset} -\alias{value_choices.TealDatasetConnector} \title{Wrapper on \link{choices_labeled} to label variable values basing on other variable values} \usage{ value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ") @@ -13,16 +11,11 @@ value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ") \method{value_choices}{character}(data, var_choices, var_label = NULL, subset = NULL, sep = " - ") \method{value_choices}{data.frame}(data, var_choices, var_label = NULL, subset = NULL, sep = " - ") - -\method{value_choices}{TealDataset}(data, var_choices, var_label = NULL, subset = NULL, sep = " - ") - -\method{value_choices}{TealDatasetConnector}(data, var_choices, var_label = NULL, subset = NULL, sep = " - ") } \arguments{ -\item{data}{(\code{data.frame}, \code{character}, \code{TealDataset}, \code{TealDatasetConnector}) -If \code{data.frame}, then data to extract labels from -If \code{character}, then name of the dataset to extract data from once available -If \code{TealDataset} or \code{TealDatasetConnector}, then raw data to extract labels from.} +\item{data}{(\code{data.frame}, \code{character}) +If \code{data.frame}, then data to extract labels from. +If \code{character}, then name of the dataset to extract data from once available.} \item{var_choices}{(\code{character} or \code{NULL}) vector with choices column names} diff --git a/man/variable_choices.Rd b/man/variable_choices.Rd index d6b06447..fb738701 100644 --- a/man/variable_choices.Rd +++ b/man/variable_choices.Rd @@ -4,8 +4,6 @@ \alias{variable_choices} \alias{variable_choices.character} \alias{variable_choices.data.frame} -\alias{variable_choices.TealDataset} -\alias{variable_choices.TealDatasetConnector} \title{Wrapper on \link{choices_labeled} to label variables basing on existing labels in data} \usage{ variable_choices(data, subset = NULL, fill = FALSE, key = NULL) @@ -13,26 +11,11 @@ variable_choices(data, subset = NULL, fill = FALSE, key = NULL) \method{variable_choices}{character}(data, subset = NULL, fill = FALSE, key = NULL) \method{variable_choices}{data.frame}(data, subset = NULL, fill = TRUE, key = NULL) - -\method{variable_choices}{TealDataset}( - data, - subset = NULL, - fill = FALSE, - key = teal.data::get_keys(data) -) - -\method{variable_choices}{TealDatasetConnector}( - data, - subset = NULL, - fill = FALSE, - key = teal.data::get_keys(data) -) } \arguments{ -\item{data}{(\code{data.frame}, \code{character}, \code{TealDataset}, \code{TealDatasetConnector}) +\item{data}{(\code{data.frame}, \code{character}) If \code{data.frame}, then data to extract labels from -If \code{character}, then name of the dataset to extract data from once available -If \code{TealDataset} or \code{TealDatasetConnector}, then raw data to extract labels from.} +If \code{character}, then name of the dataset to extract data from once available} \item{subset}{(\code{character} or \code{function}) If \code{character}, then a vector of column names. @@ -59,22 +42,15 @@ ADRS <- teal.transform::rADRS variable_choices(ADRS) variable_choices(ADRS, subset = c("PARAM", "PARAMCD")) variable_choices(ADRS, subset = c("", "PARAM", "PARAMCD")) -variable_choices(ADRS, subset = c("", "PARAM", "PARAMCD"), key = teal.data::get_cdisc_keys("ADRS")) +variable_choices( + ADRS, + subset = c("", "PARAM", "PARAMCD"), + key = teal.data::default_cdisc_join_keys["ADRS", "ADRS"] +) # delayed version variable_choices("ADRS", subset = c("USUBJID", "STUDYID")) -# also works with [teal.data::TealDataset] and [teal.data::TealDatasetConnector] -ADRS_dataset <- teal.data::dataset("ADRS", ADRS, key = teal.data::get_cdisc_keys("ADRS")) -variable_choices(ADRS_dataset) - -ADRS_conn <- teal.data::dataset_connector( - "ADRS", - pull_callable = teal.data::callable_code("radrs(cached = TRUE)"), - key = teal.data::get_cdisc_keys("ADRS") -) -variable_choices(ADRS_conn) - # functional subset (with delayed data) - return only factor variables variable_choices("ADRS", subset = function(data) { idx <- vapply(data, is.factor, logical(1)) diff --git a/tests/testthat/shinytest/format_data_extract/app.R b/tests/testthat/shinytest/format_data_extract/app.R deleted file mode 100644 index c517f5da..00000000 --- a/tests/testthat/shinytest/format_data_extract/app.R +++ /dev/null @@ -1,24 +0,0 @@ -simple_des <- teal.transform::data_extract_spec( - dataname = "iris", - filter = teal.transform::filter_spec(vars = "Petal.Length", choices = c("1.4", "1.5")), - select = teal.transform::select_spec(choices = c("Petal.Length", "Species")) -) - -sample_filtered_data <- { - teal.slice::init_filtered_data( - list(iris = list(dataset = iris)) - ) -} - -ui <- shiny::fluidPage( - teal.transform::data_extract_ui(id = "des", label = "test des ui", data_extract_spec = simple_des), - shiny::verbatimTextOutput(outputId = "formatted_des"), -) -srv <- function(input, output, session) { - extracted_des <- teal.transform::data_extract_srv( - id = "des", datasets = sample_filtered_data, data_extract_spec = simple_des - ) - output$formatted_des <- shiny::renderPrint(cat(teal.transform::format_data_extract(extracted_des()))) -} - -shiny::shinyApp(ui, srv) diff --git a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/001.json b/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/001.json deleted file mode 100644 index 39a24bfd..00000000 --- a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/001.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "output": { - "formatted_des": "\nFilters:\n Columns: Petal.Length Selected: 1.4\nSelected columns:\n Petal.Length" - } -} diff --git a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/002.json b/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/002.json deleted file mode 100644 index 51452966..00000000 --- a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/002.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "output": { - "formatted_des": "\nFilters:\n Columns: Selected: \nSelected columns:\n Petal.Length" - } -} diff --git a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/003.json b/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/003.json deleted file mode 100644 index 4224e973..00000000 --- a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test-expected/003.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "output": { - "formatted_des": "\nFilters:\n Columns: Petal.Length Selected: 4.7\nSelected columns:\n Species" - } -} diff --git a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test.R b/tests/testthat/shinytest/format_data_extract/tests/shinytest/test.R deleted file mode 100644 index 163b83c3..00000000 --- a/tests/testthat/shinytest/format_data_extract/tests/shinytest/test.R +++ /dev/null @@ -1,10 +0,0 @@ -app <- ShinyDriver$new("../../") -app$snapshotInit("test") - -app$snapshot(list(output = "formatted_des")) -app$setInputs(`des-dataset_iris_singleextract-filter1-col` = character(0)) -app$snapshot(list(output = "formatted_des")) -app$setInputs(`des-dataset_iris_singleextract-filter1-col` = "Petal.Length") -app$setInputs(`des-dataset_iris_singleextract-filter1-vals` = "4.7") -app$setInputs(`des-dataset_iris_singleextract-select` = "Species") -app$snapshot(list(output = "formatted_des")) diff --git a/tests/testthat/test-choices_selected.R b/tests/testthat/test-choices_selected.R index 592c3e6a..e71bd18e 100644 --- a/tests/testthat/test-choices_selected.R +++ b/tests/testthat/test-choices_selected.R @@ -1,5 +1,5 @@ -adsl <- as.data.frame(as.list(setNames(nm = teal.data::get_cdisc_keys("ADSL")))) -adtte <- as.data.frame(as.list(setNames(nm = teal.data::get_cdisc_keys("ADTTE")))) +adsl <- as.data.frame(as.list(setNames(nm = c("STUDYID", "USUBJID")))) +adtte <- as.data.frame(as.list(setNames(nm = c("STUDYID", "USUBJID", "PARAMCD")))) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( @@ -37,12 +37,12 @@ testthat::test_that("delayed version of choices_selected", { ) data_list <- list(ADSL = reactive(adsl), ADTTE = reactive(adtte)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) exp_obj <- choices_selected( - variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(adsl, subset = c("STUDYID"), key = teal.data::get_cdisc_keys("ADSL")) + variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(adsl, subset = c("STUDYID"), key = c("STUDYID", "USUBJID")) ) testthat::expect_equal(res_obj, exp_obj, check.attributes = TRUE) @@ -61,14 +61,14 @@ testthat::test_that("delayed version of choices_selected", { }) testthat::test_that("choices_selected throws error when selected is not found in choices", { - testthat::expect_error(choices_selected(choices = c("a"), selected = "b"), "b 'selected' but not in 'choices'") + testthat::expect_error(choices_selected(choices = c("a"), selected = "b"), "Must be a subset of \\{'a'\\}") testthat::expect_error( choices_selected(choices = c("a"), selected = c("a", "b")), - "b 'selected' but not in 'choices'" + "Must be a subset of \\{'a'\\}" ) testthat::expect_error( choices_selected(choices = c("a"), selected = c("c", "b")), - "c, b 'selected' but not in 'choices'" + "Must be a subset of \\{'a'\\}" ) }) @@ -147,12 +147,10 @@ testthat::test_that("choices_selected remove duplicates", { ) }) - -# With resolve_delayed -data <- teal.data::cdisc_data(teal.data::cdisc_dataset("ADSL", adsl), teal.data::cdisc_dataset("ADTTE", adtte)) -ds <- teal.slice::init_filtered_data(data) - testthat::test_that("delayed version of choices_selected - resolve_delayed", { + data_list <- list(ADSL = reactive(adsl), ADTTE = reactive(adtte)) + key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) + # hard-coded choices and selected obj <- choices_selected(vc_hard, selected = vc_hard_short) testthat::expect_equal( @@ -163,10 +161,10 @@ testthat::test_that("delayed version of choices_selected - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = key_list)) exp_obj <- choices_selected( - variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(adsl, subset = c("STUDYID"), key = teal.data::get_cdisc_keys("ADSL")) + variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(adsl, subset = c("STUDYID"), key = c("STUDYID", "USUBJID")) ) testthat::expect_equal(res_obj, exp_obj, check.attributes = TRUE) @@ -180,6 +178,6 @@ testthat::test_that("delayed version of choices_selected - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = key_list)) testthat::expect_equal(res_obj, exp_obj) }) diff --git a/tests/testthat/test-data_extract_datanames.R b/tests/testthat/test-data_extract_datanames.R index 51f605a2..226f7f04 100644 --- a/tests/testthat/test-data_extract_datanames.R +++ b/tests/testthat/test-data_extract_datanames.R @@ -63,14 +63,16 @@ testthat::test_that( } ) -testthat::test_that("get_extract_datanames throws error when no data_extract_spec nor list (of lists) - of data_extract_spec is passed", { - testthat::expect_error(get_extract_datanames(1)) - testthat::expect_error(get_extract_datanames("A")) - testthat::expect_error(get_extract_datanames(TRUE)) - testthat::expect_error(get_extract_datanames(list(des, 1))) - testthat::expect_error(get_extract_datanames(list(des, "A"))) -}) +testthat::test_that( + "get_extract_datanames throws error when no data_extract_spec nor list (of lists) of data_extract_spec is passed", + { + testthat::expect_error(get_extract_datanames(1)) + testthat::expect_error(get_extract_datanames("A")) + testthat::expect_error(get_extract_datanames(TRUE)) + testthat::expect_error(get_extract_datanames(list(des, 1))) + testthat::expect_error(get_extract_datanames(list(des, "A"))) + } +) testthat::test_that("get_extract_datanames throws error with empty list", { testthat::expect_error(get_extract_datanames(list()), "length(data_extracts) > 0 is not TRUE", fixed = TRUE) diff --git a/tests/testthat/test-data_extract_module.R b/tests/testthat/test-data_extract_module.R index 65a85cb9..2a3bef53 100644 --- a/tests/testthat/test-data_extract_module.R +++ b/tests/testthat/test-data_extract_module.R @@ -31,7 +31,6 @@ testthat::test_that("Single filter", { # check also colummns selected }) - testthat::test_that("Multiple filters", { data_extract <- data_extract_spec( dataname = "ADLB", @@ -74,7 +73,6 @@ testthat::test_that("Multiple filters", { # number of column inputs }) - testthat::test_that("Multiple datasets", { data_extract_adtte <- data_extract_spec( dataname = "ADTTE", @@ -139,37 +137,3 @@ testthat::test_that("Multiple datasets", { ) ) }) - -testthat::test_that("get_initial_filters_values returns empty strings if vars_selected is NULL", { - filtered_data <- teal.slice::init_filtered_data(list(iris = list(dataset = utils::head(iris)))) - filter <- filter_spec(vars = "test") - filter$vars_selected <- NULL - testthat::expect_equal( - get_initial_filter_values(filter = filter, datasets = filtered_data), - list(choices = character(0), selected = character(0)) - ) -}) - -testthat::test_that("get_initial_filters_values returns all column values and the selected option if choices is NULL", { # nolint - data_list <- list(iris = reactive(utils::head(iris))) - - filter <- filter_spec(vars = colnames(iris)[1]) - filter$choices <- NULL - filter$dataname <- "iris" - filter$selected <- "test" - testthat::expect_equal( - isolate(get_initial_filter_values(filter = filter, datasets = data_list)), - list(choices = value_choices(utils::head(iris), colnames(iris)[1]), selected = "test") - ) -}) - -testthat::test_that("get_initial_filters_values returns the selected and choices if they are not null", { - filtered_data <- teal.slice::init_filtered_data(list(iris = list(dataset = utils::head(iris)))) - filter <- filter_spec(vars = colnames(iris)[length(colnames(iris))]) - filter$choices <- "setosa" - filter$selected <- "setosa" - testthat::expect_equal( - isolate(get_initial_filter_values(filter = filter, datasets = filtered_data)), - list(choices = "setosa", selected = "setosa") - ) -}) diff --git a/tests/testthat/test-data_extract_multiple_srv.R b/tests/testthat/test-data_extract_multiple_srv.R index 494f02d7..6db3efc1 100644 --- a/tests/testthat/test-data_extract_multiple_srv.R +++ b/tests/testthat/test-data_extract_multiple_srv.R @@ -1,39 +1,32 @@ -datasets <- teal.slice::init_filtered_data( - list(iris = list(dataset = iris)) -) - -data_list <- sapply(X = datasets$datanames(), simplify = FALSE, FUN = function(x) { - shiny::reactive(datasets$get_data(dataname = x, filtered = FALSE)) -}) - -nr_data_list <- sapply(X = datasets$datanames(), simplify = FALSE, FUN = function(x) { - shiny::isolate(datasets$get_data(dataname = x, filtered = FALSE)) -}) +ADSL <- teal.transform::rADSL # nolint +ADLB <- teal.transform::rADLB # nolint +ADTTE <- teal.transform::rADTTE # nolint -key_list <- datasets$get_join_keys() +data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE), ADLB = reactive(ADLB)) +join_keys <- teal.data::default_cdisc_join_keys[c("ADSL", "ADTTE", "ADLB")] testthat::test_that("data_extract_multiple_srv accepts a named list of `data_extract_spec`", { shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( + expr = testthat::expect_no_error( data_extract_multiple_srv( data_extract = list(test = data_extract_spec(dataname = "iris")), datasets = data_list, - join_keys = key_list - ), - NA + join_keys = teal.data::join_keys() + ) ) ) }) testthat::test_that("data_extract_multiple_srv returns a named reactive list with reactives", { + data_list <- list(iris = reactive(iris)) shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), expr = { selector_list <- data_extract_multiple_srv( list(test = data_extract_spec(dataname = "iris")), datasets = data_list, - join_keys = key_list + join_keys = teal.data::join_keys() ) testthat::expect_equal(names(isolate(selector_list())), "test") testthat::expect_true(inherits(selector_list, "reactive")) @@ -45,7 +38,7 @@ testthat::test_that("data_extract_multiple_srv returns a named reactive list wit testthat::test_that("data_extract_multiple_srv accepts an empty list", { shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), - expr = testthat::expect_error(data_extract_multiple_srv(list(), datasets = data_list, join_keys = key_list), NA) + expr = testthat::expect_no_error(data_extract_multiple_srv(list(), datasets = data_list, join_keys = join_keys)) ) }) @@ -53,52 +46,54 @@ testthat::test_that("data_extract_multiple_srv returns an empty list if passed a shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), expr = { - selector_list <- data_extract_multiple_srv(list(), datasets = data_list, join_keys = key_list) + selector_list <- data_extract_multiple_srv(list(), datasets = data_list, join_keys = join_keys) testthat::expect_equal(isolate(selector_list()), list()) } ) }) testthat::test_that("data_extract_multiple_srv prunes `NULL` from the passed list", { + data_list <- list(iris = reactive(iris)) shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), expr = testthat::expect_equal( length(data_extract_multiple_srv( list(test = data_extract_spec(dataname = "iris"), test2 = NULL), - datasets = data_list, - join_keys = key_list + datasets = data_list )), 1 ) ) }) -testthat::test_that("data_extract_multiple_srv accepts datasets as FilteredData or list of (reactive) data.frame", { - shiny::withReactiveDomain( - domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_multiple_srv(data_extract = list(test = NULL), datasets = datasets), - regexp = NA - ) +testthat::test_that("data_extract_multiple_srv accepts datasets as FilteredData", { + mock_datasets <- structure( + list( + datanames = function() names(data_list), + get_data = function(dataname, ...) data_list[[dataname]](), + get_join_keys = function(dataname, ...) join_keys + ), + class = "FilteredData" ) - shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_multiple_srv(data_extract = list(test = NULL), datasets = nr_data_list, join_keys = key_list), - regexp = NA + expr = testthat::expect_no_error( + data_extract_multiple_srv(data_extract = list(test = NULL), datasets = mock_datasets) ) ) +}) +testthat::test_that("data_extract_multiple_srv accepts datasets list of reactive data.frame", { shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_multiple_srv(data_extract = list(test = NULL), datasets = data_list, join_keys = key_list), - regexp = NA + expr = testthat::expect_no_error( + data_extract_multiple_srv(data_extract = list(test = NULL), datasets = data_list, join_keys = join_keys) ) ) +}) - mixed_data_list <- list(IRIS = reactive(iris), IRIS2 = iris) +testthat::test_that("data_extract_multiple_srv accepts datasets as list of data.frame", { + mixed_data_list <- list(IRIS = iris, IRIS2 = iris) mixed_join_keys_list <- teal.data::join_keys( teal.data::join_key("IRIS", "IRIS", "id"), teal.data::join_key("IRIS2", "IRIS2", "id"), @@ -107,13 +102,12 @@ testthat::test_that("data_extract_multiple_srv accepts datasets as FilteredData shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( + expr = testthat::expect_no_error( data_extract_multiple_srv( data_extract = list(test = NULL), datasets = mixed_data_list, join_keys = mixed_join_keys_list - ), - NA + ) ) ) }) @@ -135,7 +129,7 @@ testthat::test_that("data_extract_multiple_srv throws if data_extract is not a n shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), expr = testthat::expect_error( - data_extract_multiple_srv(list(1), datasets = teal.slice::init_filtered_data(list(iris = list(dataset = iris)))), + data_extract_multiple_srv(list(1), datasets = data_list), regexp = "Assertion on 'data_extract' failed: Must have names" ) ) diff --git a/tests/testthat/test-data_extract_spec.R b/tests/testthat/test-data_extract_spec.R index 4a735fb0..2903081f 100644 --- a/tests/testthat/test-data_extract_spec.R +++ b/tests/testthat/test-data_extract_spec.R @@ -1,9 +1,5 @@ -testthat::test_that("data_extract_spec argument checking", { - expect_error( - data_extract_spec("toyDataset", select = c("A", "B")), - "select, \"select_spec\"", - fixed = TRUE - ) +testthat::test_that("data_extract_spec throws when select is not select_spec or NULL", { + expect_error(data_extract_spec("toyDataset", select = c("A", "B"))) }) testthat::test_that("data_extract_spec works with valid input", { @@ -111,7 +107,7 @@ testthat::test_that("delayed data_extract_spec works", { BMRKR2 = sample(c("L", "M", "H"), 10, replace = TRUE), stringsAsFactors = FALSE ) - attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") # nolint + attr(ADSL, "keys") <- c("STUDYID", "USUBJID") # nolint filter_normal <- filter_spec( vars = variable_choices(ADSL, "SEX"), @@ -187,7 +183,7 @@ testthat::test_that("delayed data_extract_spec works", { testthat::expect_equal(names(expected_spec), names(mix3)) data_list <- list(ADSL = reactive(ADSL)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL")) + key_list <- list(ADSL = c("STUDYID", "USUBJID")) isolate({ testthat::expect_identical(expected_spec, resolve(delayed_spec, data_list, key_list)) @@ -206,7 +202,7 @@ testthat::test_that("delayed data_extract_spec works", { ADSL <- teal.transform::rADSL # nolint ADTTE <- teal.transform::rADTTE # nolint data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) -key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) +key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( @@ -248,11 +244,11 @@ testthat::test_that("delayed version of data_extract_spec", { res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) exp_obj <- data_extract_spec( "ADSL", - select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(ADSL, "STUDYID", key = teal.data::get_cdisc_keys("ADSL")) + select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(ADSL, "STUDYID", key = c("STUDYID", "USUBJID")) ), filter = filter_spec( - vars = variable_choices(ADSL, subset = "ARMCD", key = teal.data::get_cdisc_keys("ADSL")), + vars = variable_choices(ADSL, subset = "ARMCD", key = c("STUDYID", "USUBJID")), choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")), selected = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = "ARM A"), multiple = FALSE @@ -288,11 +284,11 @@ testthat::test_that("delayed version of data_extract_spec", { res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) exp_obj <- data_extract_spec( "ADSL", - select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(ADSL, "STUDYID", key = teal.data::get_cdisc_keys("ADSL")) + select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(ADSL, "STUDYID", key = c("STUDYID", "USUBJID")) ), filter = filter_spec( - vars = variable_choices(ADSL, subset = "ARMCD", key = teal.data::get_cdisc_keys("ADSL")), + vars = variable_choices(ADSL, subset = "ARMCD", key = c("STUDYID", "USUBJID")), choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")), selected = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = "ARM A"), multiple = FALSE @@ -339,7 +335,7 @@ testthat::test_that("delayed data_extract_spec works - resolve_delayed", { BMRKR2 = sample(c("L", "M", "H"), 10, replace = TRUE), stringsAsFactors = FALSE ) - attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") # nolint + attr(ADSL, "keys") <- c("STUDYID", "USUBJID") # nolint filter_normal <- filter_spec( vars = variable_choices(ADSL, "SEX"), @@ -416,14 +412,12 @@ testthat::test_that("delayed data_extract_spec works - resolve_delayed", { isolate({ - ds <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = ADSL)) - ) - testthat::expect_identical(expected_spec, resolve_delayed(delayed_spec, ds)) - testthat::expect_identical(expected_spec, resolve_delayed(mix1, ds)) - testthat::expect_identical(expected_spec, resolve_delayed(mix2, ds)) + data_list <- list(ADSL = reactive(ADSL)) + testthat::expect_identical(expected_spec, resolve_delayed(delayed_spec, data_list)) + testthat::expect_identical(expected_spec, resolve_delayed(mix1, data_list)) + testthat::expect_identical(expected_spec, resolve_delayed(mix2, data_list)) - mix3_res <- resolve_delayed(mix3, ds) + mix3_res <- resolve_delayed(mix3, data_list) }) testthat::expect_identical(expected_spec$filter[[1]], mix3_res$filter[[1]]) @@ -433,14 +427,10 @@ testthat::test_that("delayed data_extract_spec works - resolve_delayed", { testthat::expect_identical(expected_spec, mix3_res) }) -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL), - teal.data::cdisc_dataset("ADTTE", ADTTE) -) - -ds <- teal.slice::init_filtered_data(data) testthat::test_that("delayed version of data_extract_spec - resolve_delayed", { + data_list <- list(ADSL = reactive(ADSL)) + keys_list <- list(ADSL = c("STUDYID", "USUBJID")) # hard-coded subset obj <- data_extract_spec( "ADSL", @@ -453,14 +443,14 @@ testthat::test_that("delayed version of data_extract_spec - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = keys_list)) exp_obj <- data_extract_spec( "ADSL", - select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(ADSL, "STUDYID", key = teal.data::get_cdisc_keys("ADSL")) + select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(ADSL, "STUDYID", key = c("STUDYID", "USUBJID")) ), filter = filter_spec( - vars = variable_choices(ADSL, subset = "ARMCD", key = teal.data::get_cdisc_keys("ADSL")), + vars = variable_choices(ADSL, subset = "ARMCD", key = c("STUDYID", "USUBJID")), choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")), selected = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = "ARM A"), multiple = FALSE @@ -494,14 +484,14 @@ testthat::test_that("delayed version of data_extract_spec - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = keys_list)) exp_obj <- data_extract_spec( "ADSL", - select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(ADSL, "STUDYID", key = teal.data::get_cdisc_keys("ADSL")) + select = select_spec(variable_choices(ADSL, c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(ADSL, "STUDYID", key = c("STUDYID", "USUBJID")) ), filter = filter_spec( - vars = variable_choices(ADSL, subset = "ARMCD", key = teal.data::get_cdisc_keys("ADSL")), + vars = variable_choices(ADSL, subset = "ARMCD", key = c("STUDYID", "USUBJID")), choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")), selected = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = "ARM A"), multiple = FALSE diff --git a/tests/testthat/test-data_extract_srv.R b/tests/testthat/test-data_extract_srv.R index cb2336cb..0ef403f5 100644 --- a/tests/testthat/test-data_extract_srv.R +++ b/tests/testthat/test-data_extract_srv.R @@ -1,31 +1,15 @@ -adsl_df <- as.data.frame(as.list(stats::setNames(nm = teal.data::get_cdisc_keys("ADSL")))) -adlb_df <- as.data.frame(as.list(stats::setNames(nm = teal.data::get_cdisc_keys("ADLB")))) +ADSL <- teal.transform::rADSL # nolint +ADLB <- teal.transform::rADLB # nolint +ADTTE <- teal.transform::rADTTE # nolint -adsl <- teal.data::cdisc_dataset("ADSL", adsl_df) -adlb <- teal.data::cdisc_dataset("ADLB", adlb_df) - -datasets <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = adsl_df)), - join_keys = teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) - ) -) - -data_list <- sapply(X = datasets$datanames(), simplify = FALSE, FUN = function(x) { - reactive(datasets$get_data(dataname = x, filtered = FALSE)) -}) - -nr_data_list <- sapply(X = datasets$datanames(), simplify = FALSE, FUN = function(x) { - datasets$get_data(dataname = x, filtered = FALSE) -}) - -join_keys_list <- datasets$get_join_keys() +data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE), ADLB = reactive(ADLB)) +join_keys <- teal.data::default_cdisc_join_keys[c("ADSL", "ADTTE", "ADLB")] adsl_extract <- data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(adsl, teal.data::get_cdisc_keys("ADSL")), + choices = variable_choices("ADSL", c("STUDYID", "USUBJID")), selected = "STUDYID", multiple = TRUE, fixed = FALSE @@ -44,58 +28,64 @@ adlb_extract <- data_extract_spec( ) testthat::test_that( - desc = "data_extract_srv accepts a FilteredData object or a list of (reactive) data frames to datasets", + desc = "data_extract_srv datasets accepts list of (reactive) data frames", code = { shiny::withReactiveDomain( domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_srv(id = "x", data_extract_spec = adsl_extract, datasets = datasets), - NA + expr = testthat::expect_no_error( + data_extract_srv(id = "x", data_extract_spec = adsl_extract, datasets = data_list, join_keys = join_keys) ) ) + } +) - shiny::withReactiveDomain( - domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_srv(id = "x", data_extract_spec = adsl_extract, datasets = data_list, join_keys = join_keys_list), - NA - ) +testthat::test_that("data_extract_srv datasets accepts a FilteredData", { + mock_datasets <- structure( + list( + datanames = function() names(data_list), + get_data = function(dataname, ...) data_list[[dataname]](), + get_join_keys = function(dataname, ...) join_keys + ), + class = "FilteredData" + ) + shiny::withReactiveDomain( + domain = shiny::MockShinySession$new(), + expr = testthat::expect_no_error( + data_extract_srv(id = "x", data_extract_spec = adsl_extract, datasets = mock_datasets) ) + ) +}) - shiny::withReactiveDomain( - domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_srv( - id = "x", - data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list - ), - NA +testthat::test_that("data_extract_srv datasets accepts a list of data frames", { + data_list <- list(ADSL = ADSL, ADTTE = ADTTE, ADLB = ADLB) + shiny::withReactiveDomain( + domain = shiny::MockShinySession$new(), + expr = testthat::expect_no_error( + data_extract_srv( + id = "x", + data_extract_spec = adsl_extract, + datasets = data_list, + join_keys = join_keys ) ) + ) +}) - mixed_data_list <- list(ADSL = reactive(datasets$get_data(dataname = "ADSL", filtered = FALSE)), ADLB = adsl_df) - mixed_join_keys_list <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADLB", "ADLB", teal.data::get_cdisc_keys("ADLB")), - teal.data::join_key("ADSL", "ADLB", teal.data::get_cdisc_keys("ADSL")) - ) +testthat::test_that("data_extract_srv datasets accepts a mixed list of reactive and not reactive data frames", { + mixed_data_list <- list(ADSL = reactive(ADSL), ADLB = ADLB) - shiny::withReactiveDomain( - domain = shiny::MockShinySession$new(), - expr = testthat::expect_error( - data_extract_srv( - id = "x", - data_extract_spec = adsl_extract, - datasets = mixed_data_list, - join_keys = mixed_join_keys_list - ), - NA + shiny::withReactiveDomain( + domain = shiny::MockShinySession$new(), + expr = testthat::expect_no_error( + data_extract_srv( + id = "x", + data_extract_spec = adsl_extract, + datasets = mixed_data_list, + join_keys = join_keys ) ) - } -) + ) +}) testthat::test_that( desc = "data_extract_srv works with join_keys = NULL (default)", @@ -126,7 +116,7 @@ testthat::test_that( testthat::test_that("data_extract_srv returns a list of elements", { shiny::testServer( data_extract_srv, - args = list(id = "x", data_extract_spec = adsl_extract, datasets = nr_data_list, join_keys = join_keys_list), + args = list(id = "x", data_extract_spec = adsl_extract, datasets = data_list, join_keys = join_keys), expr = { testthat::expect_is(session$returned(), "list") testthat::expect_setequal( @@ -137,11 +127,11 @@ testthat::test_that("data_extract_srv returns a list of elements", { ) }) -testthat::test_that("data_extract_srv throws error with missing arguments", { +testthat::test_that("data_extract_srv throws error when data_extract_spec is missing", { testthat::expect_error( shiny::testServer( data_extract_srv, - args = list(id = "x", datasets = nr_data_list, join_keys = join_keys_list), + args = list(id = "x", datasets = data_list, join_keys = join_keys), expr = NULL ), "argument \"data_extract_spec\" is missing, with no default" @@ -157,11 +147,11 @@ testthat::test_that("data_extract_srv throws error with missing arguments", { ) }) -testthat::test_that("data_extract_srv throws error with wrong argument input type", { +testthat::test_that("data_extract_srv throws when data_extract_spec don't get data_extract_spec object", { testthat::expect_error( shiny::testServer( data_extract_srv, - args = list(id = "x", data_extract_spec = c("data_extract"), datasets = nr_data_list, join_keys = join_keys_list), + args = list(id = "x", data_extract_spec = c("data_extract"), datasets = data_list, join_keys = join_keys), expr = NULL ), regexp = "has class 'character'" @@ -170,16 +160,7 @@ testthat::test_that("data_extract_srv throws error with wrong argument input typ testthat::expect_error( shiny::testServer( data_extract_srv, - args = list(id = "x", data_extract_spec = TRUE, datasets = nr_data_list, join_keys = join_keys_list), - expr = NULL - ), - regexp = "has class 'logical'" - ) - - testthat::expect_error( - shiny::testServer( - data_extract_srv, - args = list(id = "x", data_extract_spec = adsl_extract, datasets = adsl, join_keys = join_keys_list), + args = list(id = "x", data_extract_spec = adsl_extract, datasets = ADSL, join_keys = join_keys), expr = NULL ), regexp = "Assertion on 'datasets' failed:" @@ -191,8 +172,8 @@ testthat::test_that("data_extract_srv throws error with wrong argument input typ args = list( id = "adsl_extract", data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list, + datasets = data_list, + join_keys = join_keys, select_validation_rule = "string" ), expr = NULL @@ -206,8 +187,8 @@ testthat::test_that("data_extract_srv throws error with wrong argument input typ args = list( id = "adsl_extract", data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list, + datasets = data_list, + join_keys = join_keys, filter_validation_rule = "string" ), expr = NULL @@ -221,8 +202,8 @@ testthat::test_that("data_extract_srv throws error with wrong argument input typ args = list( id = "adsl_extract", data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list, + datasets = data_list, + join_keys = join_keys, dataset_validation_rule = "string" ), expr = NULL @@ -236,8 +217,8 @@ testthat::test_that("data_extract_srv throws error with wrong argument input typ args = list( id = "adsl_extract", data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list, + datasets = data_list, + join_keys = join_keys, select_validation_rule = TRUE ), expr = NULL @@ -251,8 +232,8 @@ testthat::test_that("data_extract_srv throws error with wrong argument input typ args = list( id = "adsl_extract", data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list, + datasets = data_list, + join_keys = join_keys, select_validation_rule = 1 ), expr = NULL @@ -267,8 +248,8 @@ testthat::test_that("data_extract_srv uses the current session id when id is mis args = list( id = "adsl_extract", data_extract_spec = adsl_extract, - datasets = nr_data_list, - join_keys = join_keys_list + datasets = data_list, + join_keys = join_keys ), expr = { testthat::expect_is(session$returned(), "list") @@ -280,13 +261,12 @@ testthat::test_that("data_extract_srv uses the current session id when id is mis ) }) - testthat::test_that("data_extract_srv returns select ordered according to selection", { extract_ordered <- data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(adsl, teal.data::get_cdisc_keys("ADSL")), + choices = variable_choices(ADSL, c("STUDYID", "USUBJID")), selected = "STUDYID", ordered = TRUE ) @@ -294,7 +274,7 @@ testthat::test_that("data_extract_srv returns select ordered according to select shiny::testServer( data_extract_srv, - args = list(id = "x", data_extract_spec = extract_ordered, datasets = datasets), + args = list(id = "x", data_extract_spec = extract_ordered, datasets = data_list), expr = { session$setInputs(`dataset_ADSL_singleextract-select` = c("b", "c")) testthat::expect_identical(filter_and_select_reactive()$select, c("b", "c")) @@ -313,7 +293,7 @@ testthat::test_that("data_extract_srv returns select ordered according to choice dataname = "ADSL", select = select_spec( label = "Select variable:", - choices = variable_choices(adsl, teal.data::get_cdisc_keys("ADSL")), + choices = variable_choices(ADSL, c("STUDYID", "USUBJID")), selected = "STUDYID", ordered = FALSE ) @@ -321,7 +301,7 @@ testthat::test_that("data_extract_srv returns select ordered according to choice shiny::testServer( data_extract_srv, - args = list(id = "x", data_extract_spec = extract_unordered, datasets = datasets), + args = list(id = "x", data_extract_spec = extract_unordered, datasets = data_list), expr = { session$setInputs(`dataset_ADSL_singleextract-select` = c("b", "c")) testthat::expect_identical(filter_and_select_reactive()$select, c("b", "c")) @@ -335,22 +315,12 @@ testthat::test_that("data_extract_srv returns select ordered according to choice ) }) -datasets <- teal.slice::init_filtered_data( - list( - ADSL = list(dataset = adsl_df), - ADLB = list(dataset = adsl_df) - ), - join_keys = teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADLB", "ADLB", teal.data::get_cdisc_keys("ADLB")) - ) -) testthat::test_that("data_extract_srv with a list of multiple data_extract_spec", { extract_list <- list(adsl_extract = adsl_extract, adlb_extract = adlb_extract) shiny::testServer( data_extract_srv, - args = list(id = "x", data_extract_spec = extract_list, datasets = datasets), + args = list(id = "x", data_extract_spec = extract_list, datasets = data_list), expr = { session$setInputs(`dataset` = "ADLB") testthat::expect_identical(input$dataset, "ADLB") @@ -363,36 +333,25 @@ testthat::test_that("data_extract_srv with a list of multiple data_extract_spec" ) }) -ADSL_val <- data.frame( # nolint - STUDYID = "A", - USUBJID = LETTERS[1:10], - SEX = rep(c("F", "M"), 5), - AGE = rpois(10, 30), - BMRKR1 = rlnorm(10) -) - -adsl_extract_val <- data_extract_spec( - dataname = "ADSL", - filter = filter_spec(vars = "SEX", choices = c("F", "M"), selected = "F"), - select = select_spec( - label = "Select variable:", - choices = variable_choices(ADSL_val, c("AGE", "BMRKR1")), - selected = "AGE", - multiple = TRUE, - fixed = FALSE - ) -) - -data_list_val <- list(ADSL = reactive(ADSL_val)) -join_keys_val <- teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) testthat::test_that("select validation", { + adsl_extract <- data_extract_spec( + dataname = "ADSL", + filter = filter_spec(vars = "SEX", choices = c("F", "M"), selected = "F"), + select = select_spec( + label = "Select variable:", + choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + selected = "AGE", + multiple = TRUE, + fixed = FALSE + ) + ) server <- function(input, output, session) { adsl_reactive_input <- data_extract_srv( id = "adsl_var", - datasets = data_list_val, - data_extract_spec = adsl_extract_val, - join_keys = join_keys_val, + datasets = data_list, + data_extract_spec = adsl_extract, + join_keys = join_keys, select_validation_rule = shinyvalidate::sv_required("Please select a variable.") ) @@ -423,7 +382,7 @@ testthat::test_that("select validation", { }) testthat::test_that("validation only runs on currently selected dataset's data extract spec", { - iris_extract_val <- data_extract_spec( + iris_extract <- data_extract_spec( dataname = "IRIS", select = select_spec( label = "Select variable:", @@ -434,13 +393,12 @@ testthat::test_that("validation only runs on currently selected dataset's data e ) ) - server <- function(input, output, session) { adsl_reactive_input <- data_extract_srv( id = "adsl_var", - datasets = data_list_val, - data_extract_spec = list(adsl_extract_val, iris_extract_val), - join_keys = join_keys_val, + datasets = data_list, + data_extract_spec = list(iris_extract, iris_extract), + join_keys = join_keys, select_validation_rule = shinyvalidate::sv_required("Please select a variable.") ) @@ -470,12 +428,23 @@ testthat::test_that("validation only runs on currently selected dataset's data e }) testthat::test_that("filter validation", { + adsl_extract <- data_extract_spec( + dataname = "ADSL", + filter = filter_spec(vars = "SEX", choices = c("F", "M"), selected = "F"), + select = select_spec( + label = "Select variable:", + choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + selected = "AGE", + multiple = TRUE, + fixed = FALSE + ) + ) server <- function(input, output, session) { adsl_reactive_input <- data_extract_srv( id = "adsl_var", - datasets = data_list_val, - data_extract_spec = adsl_extract_val, - join_keys = join_keys_val, + datasets = data_list, + data_extract_spec = adsl_extract, + join_keys = join_keys, filter_validation_rule = shinyvalidate::sv_required("Please select a variable.") ) @@ -507,12 +476,23 @@ testthat::test_that("filter validation", { testthat::test_that("select validation accepts function as validator", { + adsl_extract <- data_extract_spec( + dataname = "ADSL", + filter = filter_spec(vars = "SEX", choices = c("F", "M"), selected = "F"), + select = select_spec( + label = "Select variable:", + choices = variable_choices(ADSL, c("AGE", "BMRKR1")), + selected = "AGE", + multiple = TRUE, + fixed = FALSE + ) + ) server <- function(input, output, session) { adsl_reactive_input <- data_extract_srv( id = "adsl_var", - datasets = data_list_val, - data_extract_spec = adsl_extract_val, - join_keys = join_keys_val, + datasets = data_list, + data_extract_spec = adsl_extract, + join_keys = join_keys, select_validation_rule = ~ if (nchar(.) == 0) "error" ) diff --git a/tests/testthat/test-delayed_data_extract.R b/tests/testthat/test-delayed_data_extract.R index 3f2af641..d698ed8b 100644 --- a/tests/testthat/test-delayed_data_extract.R +++ b/tests/testthat/test-delayed_data_extract.R @@ -2,12 +2,12 @@ # the objects responsible for loading, pulling and filtering the data ADSL <- teal.transform::rADSL # nolint ADTTE <- teal.transform::rADTTE # nolint -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL), - teal.data::cdisc_dataset("ADTTE", ADTTE) -) +ADAE <- teal.transform::rADAE # nolint +ADRS <- teal.transform::rADRS # nolint -ds <- teal.slice::init_filtered_data(data) +data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE), ADAE = reactive(ADAE), ADRS = reactive(ADRS)) +join_keys <- teal.data::default_cdisc_join_keys[c("ADSL", "ADTTE", "ADAE", "ADRS")] +primary_keys_list <- lapply(join_keys, function(x) x[[1]]) vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( @@ -36,15 +36,10 @@ vc_fun_short_exp <- structure( # Delayed data extract - single data connector with two scda dataset connectors ---- get_continuous <- function(data) { # example function to show selections from delayed data - idx <- vapply(data, function(x) is.numeric(x) && length(unique(x)) > 6, logical(1)) - colnames(data)[idx] + names(Filter(is.numeric, data)) } testthat::test_that("Delayed data extract - single data connector with two scda dataset connectors", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADAE <- teal.data::cdisc_dataset(dataname = "ADAE", x = teal.transform::rADAE) # nolint - data <- teal.data::cdisc_data(ADSL, ADAE) - x <- data_extract_spec( dataname = "ADSL", select = select_spec( @@ -59,32 +54,29 @@ testthat::test_that("Delayed data extract - single data connector with two scda ) ) - # test delayed data extract - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adae <- data$get_dataset("ADAE")$get_raw_data() # nolint x_expected <- data_extract_spec( dataname = "ADSL", select = select_spec( - choices = variable_choices(adsl, subset = get_continuous, key = teal.data::get_cdisc_keys("ADSL")), + choices = variable_choices(ADSL, subset = get_continuous, key = c("STUDYID", "USUBJID")), selected = NULL ) ) y_expected <- data_extract_spec( dataname = "ADAE", select = select_spec( - choices = variable_choices(adae, subset = get_continuous, key = teal.data::get_cdisc_keys("ADAE")) + choices = variable_choices( + ADAE, + subset = get_continuous, key = c("STUDYID", "USUBJID", "ASTDTM", "AETERM", "AESEQ") + ) ) ) - data_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - reactive(ds$get_data(dataname = x, filtered = TRUE)) - }) - key_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - isolate(ds$get_keys(dataname = x)) - }) - x_result <- isolate(resolve(x, datasets = data_list, keys = key_list)) - y_result <- isolate(resolve(y, datasets = data_list, keys = key_list)) + data_list <- list(ADSL = reactive(ADSL), ADAE = reactive(ADAE)) + primary_keys_list <- list( + ADSL = c("STUDYID", "USUBJID"), + ADAE = c("STUDYID", "USUBJID", "ASTDTM", "AETERM", "AESEQ") + ) + x_result <- isolate(resolve(x, datasets = data_list, keys = primary_keys_list)) + y_result <- isolate(resolve(y, datasets = data_list, keys = primary_keys_list)) testthat::expect_identical(x_result, x_expected) testthat::expect_identical(y_result, y_expected) }) @@ -92,104 +84,27 @@ testthat::test_that("Delayed data extract - single data connector with two scda # Delayed choices selected - single data connector with two scda dataset connectors ---- testthat::test_that("Delayed choices selected - single data connector with two scda dataset connectors", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADAE <- teal.data::cdisc_dataset(dataname = "ADAE", x = teal.transform::rADAE) # nolint - - data <- teal.data::cdisc_data(ADSL, ADAE) - + data_list <- list(ADSL = reactive(ADSL), ADAE = reactive(ADAE)) + primary_keys_list <- list( + ADSL = c("STUDYID", "USUBJID"), + ADAE = c("STUDYID", "USUBJID", "ASTDTM", "AETERM", "AESEQ") + ) choices <- variable_choices("ADSL") - ds <- teal.slice::init_filtered_data(data) + choices_result <- isolate(resolve(choices, datasets = data_list, keys = primary_keys_list)) - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - choices_expected <- variable_choices(adsl, key = teal.data::get_cdisc_keys("ADSL")) - data_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - reactive(ds$get_data(dataname = x, filtered = TRUE)) - }) - key_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - isolate(ds$get_keys(dataname = x)) - }) - choices_result <- isolate(resolve(choices, datasets = data_list, keys = key_list)) + choices_expected <- variable_choices(ADSL, key = c("STUDYID", "USUBJID")) testthat::expect_identical(choices_result, choices_expected) }) # Delayed data extract - filtered ---- testthat::test_that("Delayed data extract - filtered", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = rADRS) # nolint - data <- teal.data::cdisc_data(ADSL, ADRS) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices("ADSL", - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ) + data_list <- list(ADSL = reactive(ADSL), ADRS = reactive(ADRS)) + primary_keys_list <- list( + ADSL = c("STUDYID", "USUBJID"), + ADRS = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ) - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous), - selected = NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(adsl, - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous) - ) - ) - data_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - reactive(ds$get_data(dataname = x, filtered = TRUE)) - }) - key_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - isolate(ds$get_keys(dataname = x)) - }) - x_result <- isolate(resolve(x, datasets = data_list, key_list)) - y_result <- isolate(resolve(y, datasets = data_list, key_list)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) -}) - -# Delayed extract filter concatenated - single data connector with two scda dataset connectors ---- -testthat::test_that("Delayed extract filter concatenated - single data connector with two scda dataset connectors", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = rADRS) # nolint - data <- teal.data::teal_data(ADSL, ADRS) - x <- data_extract_spec( dataname = "ADSL", select = select_spec( @@ -212,31 +127,9 @@ testthat::test_that("Delayed extract filter concatenated - single data connector select = select_spec( choices = variable_choices("ADRS", subset = get_continuous), selected = c("AGE: Age" = "AGE") - ), - filter = filter_spec( - label = "Select endpoints:", - vars = c("PARAMCD", "AVISIT"), - choices = value_choices( - data = "ADRS", - var_choices = c("PARAMCD", "AVISIT"), - var_label = c("PARAMCD", "AVISIT"), - subset = function(data) { - paste( - levels(data$PARAMCD), - levels(data$AVISIT)[4:6], - sep = " - " - ) - } - ), - selected = "INVET - END OF INDUCTION", - multiple = TRUE ) ) - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint x_expected <- data_extract_spec( dataname = "ADSL", select = select_spec( @@ -246,406 +139,7 @@ testthat::test_that("Delayed extract filter concatenated - single data connector filter = filter_spec( label = "Select endpoints:", vars = "ARMCD", - choices = value_choices(adsl, - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = c("PARAMCD", "AVISIT"), - choices = value_choices( - data = ADRS, - var_choices = c("PARAMCD", "AVISIT"), - var_label = c("PARAMCD", "AVISIT"), - subset = function(data) { - paste( - levels(data$PARAMCD), - levels(data$AVISIT)[4:6], - sep = " - " - ) - } - ), - selected = "INVET - END OF INDUCTION", - multiple = TRUE - ) - ) - data_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - reactive(ds$get_data(dataname = x, filtered = TRUE)) - }) - key_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - isolate(ds$get_keys(dataname = x)) - }) - x_result <- isolate(resolve(x, datasets = data_list, key_list)) - y_result <- isolate(resolve(y, datasets = data_list, key_list)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) -}) - -# Delayed extract two filters - single data connector with two scda dataset connectors ---- -testthat::test_that("Delayed extract two filters - single data connector with two scda dataset connectors", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = rADRS) # nolint - data <- teal.data::teal_data(ADSL, ADRS) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices("ADSL", - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = "ADRS", - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = "ADRS", - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous), - selected = NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(adsl, - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous) - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = adrs, - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = adrs, - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - data_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - reactive(ds$get_data(dataname = x, filtered = TRUE)) - }) - key_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - isolate(ds$get_keys(dataname = x)) - }) - x_result <- isolate(resolve(x, datasets = data_list, key_list)) - y_result <- isolate(resolve(y, datasets = data_list, key_list)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) -}) - -# Delayed extract - dataset & connector ---- -testthat::test_that("Delayed extract - TealData with single dataset and multiple connectors", { - ADSL <- teal.data::dataset( # nolint - dataname = "ADSL", - teal.transform::rADSL, - keys = teal.data::get_cdisc_keys("ADSL"), - code = "ADSL <- teal.transform::rADSL", - label = "ADSL" - ) - - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = teal.transform::rADRS) # nolint - ADTTE <- teal.data::cdisc_dataset(dataname = "ADTTE", x = teal.transform::rADTTE) # nolint - data <- teal.data::cdisc_data(ADSL, ADRS, ADTTE) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(ADSL$get_raw_data(), var_choices = "ARMCD", var_label = "ARM"), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = "ADRS", - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = "ADRS", - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous, key = teal.data::get_cdisc_keys("ADSL")), - NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(ADSL$get_raw_data(), var_choices = "ARMCD", var_label = "ARM"), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous, key = teal.data::get_cdisc_keys("ADRS")) - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = adrs, - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = adrs, - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - data_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - reactive(ds$get_data(dataname = x, filtered = TRUE)) - }) - key_list <- sapply(X = ds$datanames(), simplify = FALSE, FUN = function(x) { - isolate(ds$get_keys(dataname = x)) - }) - x_result <- isolate(resolve(x, datasets = data_list, key_list)) - y_result <- isolate(resolve(y, datasets = data_list, key_list)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) -}) - -# with resolve_delayed -testthat::test_that("Delayed data extract - single data connector with two scda dataset connectors - resolve_delayed", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADAE <- teal.data::cdisc_dataset(dataname = "ADAE", x = teal.transform::rADAE) # nolint - - data <- teal.data::cdisc_data(ADSL, ADAE) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ) - ) - y <- data_extract_spec( - dataname = "ADAE", - select = select_spec( - choices = variable_choices("ADAE", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ) - ) - - # test delayed data extract - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adae <- data$get_dataset("ADAE")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous, key = teal.data::get_cdisc_keys("ADSL")), - selected = NULL - ) - ) - y_expected <- data_extract_spec( - dataname = "ADAE", - select = select_spec( - choices = variable_choices(adae, subset = get_continuous, key = teal.data::get_cdisc_keys("ADAE")) - ) - ) - x_result <- isolate(resolve_delayed(x, datasets = ds)) - y_result <- isolate(resolve_delayed(y, datasets = ds)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) -}) - -# Delayed choices selected - single data connector with two scda dataset connectors ---- -testthat::test_that( - desc = "Delayed choices selected - single data connector with two scda dataset connectors - resolve_delayed", - code = { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADAE <- teal.data::cdisc_dataset(dataname = "ADAE", x = teal.transform::rADAE) # nolint - data <- teal.data::cdisc_data(ADSL, ADAE) - - choices <- variable_choices("ADSL") - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - choices_expected <- variable_choices(adsl, key = teal.data::get_cdisc_keys("ADSL")) - choices_result <- isolate(resolve_delayed(choices, datasets = ds)) - testthat::expect_identical(choices_result, choices_expected) - } -) - -# Delayed data extract - filtered ---- - -testthat::test_that("Delayed data extract - filtered", { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = rADRS) # nolint - data <- teal.data::cdisc_data(ADSL, ADRS) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices("ADSL", - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ) - ) - - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous), - selected = NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(adsl, + choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = function(data) levels(data$ARMCD)[1:2] @@ -657,351 +151,12 @@ testthat::test_that("Delayed data extract - filtered", { y_expected <- data_extract_spec( dataname = "ADRS", select = select_spec( - choices = variable_choices(adrs, subset = get_continuous) - ) - ) - x_result <- isolate(resolve_delayed(x, datasets = ds)) - y_result <- isolate(resolve_delayed(y, datasets = ds)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) -}) - -# Delayed extract filter concatenated - single data connector with two scda dataset connectors ---- -testthat::test_that( - desc = "Delayed extract filter concatenated - single data connector with two scda dataset connectors - res_delayed", - code = { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = rADRS) # nolint - data <- teal.data::teal_data(ADSL, ADRS) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices("ADSL", - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ), - filter = filter_spec( - label = "Select endpoints:", - vars = c("PARAMCD", "AVISIT"), - choices = value_choices( - data = "ADRS", - var_choices = c("PARAMCD", "AVISIT"), - var_label = c("PARAMCD", "AVISIT"), - subset = function(data) { - paste( - levels(data$PARAMCD), - levels(data$AVISIT)[4:6], - sep = " - " - ) - } - ), - selected = "INVET - END OF INDUCTION", - multiple = TRUE - ) - ) - - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous), - selected = NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(adsl, - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = c("PARAMCD", "AVISIT"), - choices = value_choices( - data = adrs, - var_choices = c("PARAMCD", "AVISIT"), - var_label = c("PARAMCD", "AVISIT"), - subset = function(data) { - paste( - levels(data$PARAMCD), - levels(data$AVISIT)[4:6], - sep = " - " - ) - } - ), - selected = "INVET - END OF INDUCTION", - multiple = TRUE - ) - ) - x_result <- isolate(resolve_delayed(x, datasets = ds)) - y_result <- isolate(resolve_delayed(y, datasets = ds)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) - } -) - -# Delayed extract two filters - single data connector with two scda dataset connectors ---- -testthat::test_that( - desc = "Delayed extract two filters - single data connector with two scda dataset connectors - resolve_delayed", - code = { - ADSL <- teal.data::cdisc_dataset(dataname = "ADSL", x = rADSL) # nolint - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = rADRS) # nolint - data <- teal.data::teal_data(ADSL, ADRS) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices("ADSL", - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = "ADRS", - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = "ADRS", - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous), - selected = NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(adsl, - var_choices = "ARMCD", - var_label = "ARM", - subset = function(data) levels(data$ARMCD)[1:2] - ), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous) - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = adrs, - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = adrs, - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - x_result <- isolate(resolve_delayed(x, datasets = ds)) - y_result <- isolate(resolve_delayed(y, datasets = ds)) - testthat::expect_identical(x_result, x_expected) - testthat::expect_identical(y_result, y_expected) - } -) - -# Delayed extract - dataset & connector ---- -testthat::test_that("Delayed extract - TealData with single dataset and multiple connectors - resolve_delayed", { - ADSL <- teal.data::dataset( # nolint - dataname = "ADSL", - teal.transform::rADSL, - keys = teal.data::get_cdisc_keys("ADSL"), - code = "ADSL <- teal.transform::rADSL", - label = "ADSL" - ) - ADRS <- teal.data::cdisc_dataset(dataname = "ADRS", x = teal.transform::rADRS) # nolint - ADTTE <- teal.data::cdisc_dataset(dataname = "ADTTE", x = teal.transform::rADTTE) # nolint - data <- teal.data::cdisc_data(ADSL, ADRS, ADTTE) - - x <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices("ADSL", subset = get_continuous) - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(ADSL$get_raw_data(), var_choices = "ARMCD", var_label = "ARM"), - selected = "ARM A", - multiple = TRUE - ) - ) - y <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices("ADRS", subset = get_continuous), - selected = c("AGE: Age" = "AGE") - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = "ADRS", - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = "ADRS", - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) + choices = variable_choices(ADRS, subset = get_continuous) ) ) - ds <- teal.slice::init_filtered_data(data) - - adsl <- data$get_dataset("ADSL")$get_raw_data() # nolint - adrs <- data$get_dataset("ADRS")$get_raw_data() # nolint - x_expected <- data_extract_spec( - dataname = "ADSL", - select = select_spec( - choices = variable_choices(adsl, subset = get_continuous, key = teal.data::get_cdisc_keys("ADSL")), - NULL - ), - filter = filter_spec( - label = "Select endpoints:", - vars = "ARMCD", - choices = value_choices(ADSL$get_raw_data(), var_choices = "ARMCD", var_label = "ARM"), - selected = "ARM A", - multiple = TRUE - ) - ) - y_expected <- data_extract_spec( - dataname = "ADRS", - select = select_spec( - choices = variable_choices(adrs, subset = get_continuous, key = teal.data::get_cdisc_keys("ADRS")) - ), - filter = list( - filter_spec( - label = "Select endpoints:", - vars = "PARAMCD", - choices = value_choices( - data = adrs, - var_choices = "PARAMCD", - var_label = "PARAMCD", - subset = function(data) levels(data$PARAMCD)[2:3] - ), - selected = "OVRINV", - multiple = TRUE - ), - filter_spec( - label = "Select endpoints:", - vars = "AVISIT", - choices = value_choices( - data = adrs, - var_choices = "AVISIT", - var_label = "AVISIT", - subset = function(data) levels(data$AVISIT)[5:6] - ), - selected = "END OF INDUCTION", - multiple = TRUE - ) - ) - ) - x_result <- isolate(resolve_delayed(x, datasets = ds)) - y_result <- isolate(resolve_delayed(y, datasets = ds)) + x_result <- isolate(resolve(x, datasets = data_list, primary_keys_list)) + y_result <- isolate(resolve(y, datasets = data_list, primary_keys_list)) testthat::expect_identical(x_result, x_expected) testthat::expect_identical(y_result, y_expected) }) diff --git a/tests/testthat/test-dplyr_call_examples.R b/tests/testthat/test-dplyr_call_examples.R index 3a0a6794..5deaf32d 100644 --- a/tests/testthat/test-dplyr_call_examples.R +++ b/tests/testthat/test-dplyr_call_examples.R @@ -1,3 +1,4 @@ +# nolint start # Different join keys ------ testthat::test_that("Different join types", { merged_selectors1 <- merge_selectors( @@ -6,7 +7,7 @@ testthat::test_that("Different join types", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -14,16 +15,16 @@ testthat::test_that("Different join types", { dataname = "ADSL2", filters = NULL, select = c("SEX", "STRATA"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ) ) ) jk1 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL2", "ADSL2", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL2", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL2", "ADSL2", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL2", c("STUDYID", "USUBJID")) ) @@ -71,7 +72,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, select = "AGE", internal_id = "x1" @@ -79,7 +80,7 @@ testthat::test_that("Single wide dataset", { ) )[[1]] jk1 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -102,14 +103,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("USUBJID", "AGE", "SEX"), # adding USUBJID doesn"t affect result - keys are selected always - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk2 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -132,7 +133,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -140,14 +141,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk3 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -170,7 +171,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -178,7 +179,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ), @@ -186,7 +187,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("STRATA", "ARMCD", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -194,14 +195,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("COUNTRY"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x4" ) ) )[[1]] jk4 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -224,7 +225,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -232,7 +233,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ), @@ -240,7 +241,7 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("STRATA", "ARMCD", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -248,14 +249,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = NULL, select = c("COUNTRY"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x4" ) ) )[[1]] jk5 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -278,14 +279,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = list(list(columns = "SEX", selected = "F", multiple = TRUE, drop_keys = FALSE)), select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk6 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -309,14 +310,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = list(list(columns = "STUDYID", selected = "STUDY1", multiple = TRUE, drop_keys = FALSE)), select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk7 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -340,14 +341,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = list(list(columns = "STUDYID", selected = "STUDY1", multiple = TRUE, drop_keys = TRUE)), select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk8 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -371,14 +372,14 @@ testthat::test_that("Single wide dataset", { dataname = "ADSL", filters = list(list(columns = "STUDYID", selected = "STUDY1", multiple = TRUE, drop_keys = TRUE)), select = c("AGE", "STUDYID"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk9 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -405,7 +406,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -413,16 +414,16 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = c("SEX", "STRATA"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ) ) ) jk1 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL2", "ADSL2", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL2", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL2", "ADSL2", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL2", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -457,7 +458,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -465,15 +466,15 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk2 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL2", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL2", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -508,7 +509,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -516,7 +517,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = c("AGE", "SEX"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ), @@ -524,7 +525,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL3", filters = NULL, select = c("AGE", "SEX", "STRATA"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -532,16 +533,16 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = c("AGE", "STRATA", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x4" ) ) )[[1]] jk3 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL2", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL3", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL2", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL3", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -585,7 +586,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -593,7 +594,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = c("AGE", "SEX"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ), @@ -601,7 +602,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL3", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -609,16 +610,16 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x4" ) ) )[[1]] jk4 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL2", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL3", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL2", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL3", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -661,7 +662,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL", filters = NULL, select = c("STUDYID", "AGE"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -669,7 +670,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = c("STUDYID", "AGE", "SEX"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ), @@ -677,7 +678,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL", filters = NULL, select = "STUDYID", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -685,7 +686,7 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL3", filters = NULL, select = c("USUBJID", "AGE", "SEX", "STRATA"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x4" ), @@ -693,16 +694,16 @@ testthat::test_that("Multiple wide dataset", { dataname = "ADSL2", filters = NULL, select = c("AGE", "STRATA", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x5" ) ) )[[1]] jk5 <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL2", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADSL3", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL2", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADSL3", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -749,14 +750,14 @@ testthat::test_that("Single long dataset", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE, drop_keys = FALSE)), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk1 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( @@ -780,14 +781,14 @@ testthat::test_that("Single long dataset", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE, drop_keys = TRUE)), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk1 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( @@ -814,22 +815,21 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE, drop_keys = TRUE) ), select = c("AGE", "SEX"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk2 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( get_dplyr_call(merged_selectors2, join_keys = jk2), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("BASELINE", "SCREENING")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("BASELINE", "SCREENING")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, AGE, SEX) ) ) # AVISIT should be in select - filter is not complete (two levels selected) @@ -849,7 +849,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE, drop_keys = FALSE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -860,14 +860,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE, drop_keys = FALSE) ), select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk3 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -895,7 +895,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE, drop_keys = TRUE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -906,14 +906,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE, drop_keys = FALSE) ), select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk3 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) # failure: @@ -958,7 +958,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = "BASELINE", multiple = TRUE, drop_keys = TRUE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -969,14 +969,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE, drop_keys = TRUE) ), select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk4 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1018,7 +1018,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE"), multiple = TRUE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -1026,14 +1026,14 @@ testthat::test_that("Single long dataset", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE)), select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk5 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1075,7 +1075,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -1086,14 +1086,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk6 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1104,15 +1104,13 @@ testthat::test_that("Single long dataset", { list( deparse(quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & - AVISIT %in% c("BASELINE", "SCREENING")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("BASELINE", "SCREENING")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, AGE) %>% dplyr::rename(x1.AGE = AGE) ), 120), deparse(quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, SEX, AGE, BMRKR1) %>% dplyr::rename(x2.AGE = AGE) ), 120) @@ -1138,7 +1136,7 @@ testthat::test_that("Single long dataset", { list(columns = "SEX", selected = c("F", "M"), multiple = TRUE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -1149,14 +1147,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = c("SEX", "AGE", "BMRKR1"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk7 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1167,15 +1165,13 @@ testthat::test_that("Single long dataset", { list( quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("BASELINE", "SCREENING") & SEX %in% c("F", "M")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("BASELINE", "SCREENING") & SEX %in% c("F", "M")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, AGE) %>% dplyr::rename(x1.AGE = AGE) ), quote( ADRS %>% - dplyr::filter(PARAMCD == "INVET" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "INVET" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, SEX, AGE, BMRKR1) %>% dplyr::rename(x2.AGE = AGE) ) @@ -1202,7 +1198,7 @@ testthat::test_that("Single long dataset", { list(columns = "SEX", selected = c("F", "M"), multiple = TRUE) ), select = "AGE", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -1213,7 +1209,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = character(0), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ), @@ -1224,14 +1220,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x3" ) ) )[[1]] jk8 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1243,8 +1239,7 @@ testthat::test_that("Single long dataset", { list( quote( ADRS %>% - dplyr::filter(PARAMCD == "INVET" & AVISIT %in% - c("BASELINE", "SCREENING") & SEX %in% c("F", "M")) %>% + dplyr::filter(PARAMCD == "INVET" & AVISIT %in% c("BASELINE", "SCREENING") & SEX %in% c("F", "M")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, AGE) %>% dplyr::rename(x1.AGE = AGE) ), @@ -1255,8 +1250,7 @@ testthat::test_that("Single long dataset", { ), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, AVAL, AGE) %>% dplyr::rename(x3.AGE = AGE) ) @@ -1279,14 +1273,14 @@ testthat::test_that("Single long dataset", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE, drop_keys = TRUE)), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ) ) )[[1]] jk9 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( @@ -1321,22 +1315,21 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ) ) )[[1]] jk10 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( get_dplyr_call(merged_selectors10, join_keys = jk10), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("BASELINE", "SCREENING")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("BASELINE", "SCREENING")) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% tidyr::pivot_longer(cols = "AVAL", names_to = "MEASURE", values_to = "VALUE") %>% tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% @@ -1365,22 +1358,21 @@ testthat::test_that("Single long dataset", { list(columns = "SEX", selected = c("M", "F"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ) ) )[[1]] jk11 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( get_dplyr_call(merged_selectors11, join_keys = jk11), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & SEX %in% - c("M", "F")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & SEX %in% c("M", "F")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, PARAMCD, AVAL) %>% tidyr::pivot_longer(cols = "AVAL", names_to = "MEASURE", values_to = "VALUE") %>% tidyr::unite(KEY, MEASURE, PARAMCD) %>% @@ -1408,7 +1400,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -1419,14 +1411,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk12 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1461,7 +1453,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -1472,14 +1464,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk13 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1490,8 +1482,7 @@ testthat::test_that("Single long dataset", { list( quote( ADRS %>% - dplyr::filter(PARAMCD == "INVET" & AVISIT %in% - c("BASELINE", "SCREENING")) %>% + dplyr::filter(PARAMCD == "INVET" & AVISIT %in% c("BASELINE", "SCREENING")) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% dplyr::rename(x1.AVAL = AVAL) %>% tidyr::pivot_longer(cols = "x1.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% @@ -1500,8 +1491,7 @@ testthat::test_that("Single long dataset", { ), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% dplyr::rename(x2.AVAL = AVAL) %>% tidyr::pivot_longer(cols = "x2.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% @@ -1535,7 +1525,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("BASELINE", "SCREENING"), multiple = TRUE) ), select = character(0), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, select = character(0), internal_id = "x1" @@ -1547,14 +1537,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk14 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1565,8 +1555,7 @@ testthat::test_that("Single long dataset", { list( quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("BASELINE", "SCREENING")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("BASELINE", "SCREENING")) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT) %>% tidyr::pivot_longer(cols = tidyselect::everything(), names_to = "MEASURE", values_to = "VALUE") %>% tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% @@ -1574,8 +1563,7 @@ testthat::test_that("Single long dataset", { ), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% tidyr::pivot_longer(cols = "AVAL", names_to = "MEASURE", values_to = "VALUE") %>% tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% @@ -1606,7 +1594,7 @@ testthat::test_that("Single long dataset", { dataname = "ADRS", filters = list(list(columns = "SEX", selected = c("M", "F"), multiple = TRUE)), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -1617,14 +1605,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk15 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1644,8 +1632,7 @@ testthat::test_that("Single long dataset", { ), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% dplyr::rename(x2.AVAL = AVAL) %>% tidyr::pivot_longer(cols = "x2.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% @@ -1678,7 +1665,7 @@ testthat::test_that("Single long dataset", { list(columns = "SEX", selected = c("F", "M"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -1689,7 +1676,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x2" ), @@ -1700,14 +1687,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x3" ) ) )[[1]] jk16 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1728,8 +1715,7 @@ testthat::test_that("Single long dataset", { ), 120), deparse(quote( ADRS %>% - dplyr::filter(PARAMCD == "INVET" & AVISIT == - "SCREENING") %>% + dplyr::filter(PARAMCD == "INVET" & AVISIT == "SCREENING") %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% dplyr::rename(x2.AVAL = AVAL) %>% tidyr::pivot_longer(cols = "x2.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% @@ -1778,7 +1764,7 @@ testthat::test_that("Single long dataset", { list(columns = "SEX", selected = c("F", "M"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -1789,7 +1775,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x2" ), @@ -1800,14 +1786,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x3" ) ) )[[1]] jk17 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1819,9 +1805,9 @@ testthat::test_that("Single long dataset", { list( deparse(quote( ADRS %>% - dplyr::filter(PARAMCD %in% c("BESRSPI", "INVET") & - AVISIT %in% c("BASELINE", "SCREENING") & - SEX %in% c("F", "M")) %>% + dplyr::filter( + PARAMCD %in% c("BESRSPI", "INVET") & AVISIT %in% c("BASELINE", "SCREENING") & SEX %in% c("F", "M") + ) %>% dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% dplyr::rename(x1.AVAL = AVAL) %>% tidyr::pivot_longer(cols = "x1.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% @@ -1879,14 +1865,14 @@ testthat::test_that("Single long dataset", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE)), select = c("AVAL", "STUDYID"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ) ) )[[1]] jk18 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( @@ -1923,7 +1909,7 @@ testthat::test_that("Single long dataset", { list(columns = "SEX", selected = c("F", "M"), multiple = TRUE) ), select = c("STUDYID", "PARAMCD", "AVISIT", "AGE"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -1934,7 +1920,7 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = c("STUDYID", "PARAMCD", "AVISIT"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ), @@ -1945,14 +1931,14 @@ testthat::test_that("Single long dataset", { list(columns = "AVISIT", selected = c("SCREENING", "FOLLOW UP"), multiple = TRUE) ), select = c("STUDYID", "PARAMCD", "AVISIT", "AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x3" ) ) )[[1]] jk20 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -1964,9 +1950,7 @@ testthat::test_that("Single long dataset", { list( quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & - AVISIT %in% c("BASELINE", "SCREENING") & - SEX %in% c("F", "M")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("BASELINE", "SCREENING") & SEX %in% c("F", "M")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, PARAMCD, AGE) %>% dplyr::rename(x1.PARAMCD = PARAMCD, x1.AGE = AGE) ), @@ -1978,8 +1962,7 @@ testthat::test_that("Single long dataset", { ), quote( ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% - c("SCREENING", "FOLLOW UP")) %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT %in% c("SCREENING", "FOLLOW UP")) %>% dplyr::select(STUDYID, USUBJID, AVISIT, PARAMCD, AVAL, AGE) %>% dplyr::rename(x3.PARAMCD = PARAMCD, x3.AGE = AGE) ) @@ -2015,14 +1998,14 @@ testthat::test_that("Single long dataset", { ) ), select = c("AGE", "SEX"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ) ) )[[1]] jk21 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -2059,7 +2042,7 @@ testthat::test_that("Single long dataset", { ) ), select = c("AGE", "PARAMCD"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2080,7 +2063,7 @@ testthat::test_that("Single long dataset", { ) ), select = c("AGE", "AVISIT"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x2" ), @@ -2101,7 +2084,7 @@ testthat::test_that("Single long dataset", { ) ), select = c("COUNTRY", "AVISIT"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x3" ), @@ -2122,14 +2105,14 @@ testthat::test_that("Single long dataset", { ) ), select = c("STUDYID", "AVAL", "AGE", "PARAMCD", "AVISIT"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x4" ) ) )[[1]] jk22 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -2184,7 +2167,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADRS", filters = NULL, select = "AVAL", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x1" ), @@ -2192,14 +2175,14 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = NULL, select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk1 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2237,7 +2220,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADRS", filters = NULL, select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2295,7 +2278,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, select = "AVAL", internal_id = "x1" @@ -2304,14 +2287,14 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = NULL, select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk3 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2352,7 +2335,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2360,14 +2343,14 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk4 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2410,7 +2393,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = character(0), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2418,14 +2401,14 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk5 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2466,7 +2449,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2474,14 +2457,14 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk6 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2531,7 +2514,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -2539,14 +2522,14 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk7 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2599,7 +2582,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = "SCREENING", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -2607,7 +2590,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = TRUE, internal_id = "x2" ), @@ -2615,15 +2598,15 @@ testthat::test_that("Multiple long datasets", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ) ) )[[1]] jk8 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADSL", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADSL", c("STUDYID", "USUBJID")) ) testthat::expect_identical( @@ -2633,27 +2616,36 @@ testthat::test_that("Multiple long datasets", { deparse(get_dplyr_call(merged_selectors8, 3L, jk8), width.cutoff = 120) ), list( - deparse(quote(ADRS %>% - dplyr::filter(PARAMCD == "BESRSPI" & AVISIT == "SCREENING") %>% - dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% - dplyr::rename(x1.AVAL = AVAL) %>% - tidyr::pivot_longer(cols = "x1.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% - tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% - tidyr::pivot_wider(names_from = "KEY", values_from = "VALUE")), width.cutoff = 120), - deparse(quote( - ADTTE %>% - dplyr::filter(PARAMCD %in% c("EFS", "PFS")) %>% - dplyr::select(STUDYID, USUBJID, PARAMCD, AVAL, AGE) %>% - dplyr::rename(x2.AVAL = AVAL, x2.AGE = AGE) %>% - tidyr::pivot_longer(cols = c("x2.AVAL", "x2.AGE"), names_to = "MEASURE", values_to = "VALUE") %>% - tidyr::unite(KEY, MEASURE, PARAMCD) %>% - tidyr::pivot_wider(names_from = "KEY", values_from = "VALUE") - ), width.cutoff = 120), - deparse(quote( - ADSL %>% - dplyr::select(STUDYID, USUBJID, AGE) %>% - dplyr::rename(x3.AGE = AGE) - ), width.cutoff = 120) + deparse( + quote(ADRS %>% + dplyr::filter(PARAMCD == "BESRSPI" & AVISIT == "SCREENING") %>% + dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% + dplyr::rename(x1.AVAL = AVAL) %>% + tidyr::pivot_longer(cols = "x1.AVAL", names_to = "MEASURE", values_to = "VALUE") %>% + tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% + tidyr::pivot_wider(names_from = "KEY", values_from = "VALUE")), + width.cutoff = 120 + ), + deparse( + quote( + ADTTE %>% + dplyr::filter(PARAMCD %in% c("EFS", "PFS")) %>% + dplyr::select(STUDYID, USUBJID, PARAMCD, AVAL, AGE) %>% + dplyr::rename(x2.AVAL = AVAL, x2.AGE = AGE) %>% + tidyr::pivot_longer(cols = c("x2.AVAL", "x2.AGE"), names_to = "MEASURE", values_to = "VALUE") %>% + tidyr::unite(KEY, MEASURE, PARAMCD) %>% + tidyr::pivot_wider(names_from = "KEY", values_from = "VALUE") + ), + width.cutoff = 120 + ), + deparse( + quote( + ADSL %>% + dplyr::select(STUDYID, USUBJID, AGE) %>% + dplyr::rename(x3.AGE = AGE) + ), + width.cutoff = 120 + ) ) ) @@ -2687,7 +2679,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE)), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2695,7 +2687,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = TRUE, internal_id = "x2" ), @@ -2703,7 +2695,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -2714,16 +2706,16 @@ testthat::test_that("Multiple long datasets", { list(columns = "AVISIT", selected = c("SCREENING", "BASELINE"), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x4" ) ) )[[1]] jk9 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -2794,7 +2786,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE)), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2802,7 +2794,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = TRUE, internal_id = "x2" ), @@ -2810,7 +2802,7 @@ testthat::test_that("Multiple long datasets", { dataname = "ADSL", filters = NULL, select = "AGE", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "x3" ), @@ -2818,16 +2810,16 @@ testthat::test_that("Multiple long datasets", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "BESRSPI", multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x4" ) ) )[[1]] jk10 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) @@ -2881,7 +2873,7 @@ testthat::test_that("Multiple long datasets", { list(columns = "SEX", selected = "F", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2892,14 +2884,14 @@ testthat::test_that("Multiple long datasets", { list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk11 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) @@ -2963,7 +2955,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { ) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -2974,15 +2966,15 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE, drop_keys = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk12 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")), - teal.data::join_key("ADTTE", "ADRS", teal.data::get_cdisc_keys("ADTTE")), + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")), + teal.data::join_key("ADTTE", "ADRS", c("STUDYID", "USUBJID", "PARAMCD")), teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID", "PARAMCD")) # non-stadard keys set for example purpose ) @@ -3033,7 +3025,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = c("PARAMCD", "AVISIT"), selected = list(c("BESRSPI", "SCREENING")), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -3041,14 +3033,14 @@ testthat::test_that("Multiple long - combined/concatenated filters", { dataname = "ADTTE", filters = list(list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE)), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = TRUE, internal_id = "x2" ) ) )[[1]] jk13 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) @@ -3108,7 +3100,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = "SEX", selected = "F", multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -3119,7 +3111,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ), @@ -3129,15 +3121,15 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = c("PARAMCD", "AVISIT"), selected = list(c("OVRINV", "FOLLOW UP")), multiple = TRUE) ), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x3" ) ) )[[1]] jk14 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -3188,7 +3180,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { multiple = TRUE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x1" ), @@ -3199,7 +3191,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ), @@ -3211,15 +3203,15 @@ testthat::test_that("Multiple long - combined/concatenated filters", { multiple = TRUE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "x3" ) ) )[[1]] jk15 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_equal( @@ -3273,7 +3265,7 @@ testthat::test_that("Multiple long - combined/concatenated filters", { multiple = TRUE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "x1" ), @@ -3284,14 +3276,14 @@ testthat::test_that("Multiple long - combined/concatenated filters", { list(columns = "PARAMCD", selected = c("EFS", "PFS"), multiple = TRUE) ), select = c("AVAL", "AGE"), - keys = teal.data::get_cdisc_keys("ADTTE"), + keys = c("STUDYID", "USUBJID", "PARAMCD"), reshape = FALSE, internal_id = "x2" ) ) )[[1]] jk16 <- teal.data::join_keys( - teal.data::join_key("ADRS", "ADTTE", teal.data::get_cdisc_keys("ADSL")) + teal.data::join_key("ADRS", "ADTTE", c("STUDYID", "USUBJID")) ) testthat::expect_equal( @@ -3391,3 +3383,4 @@ testthat::test_that("Universal example", { ) ) }) +# nolint end diff --git a/tests/testthat/test-filter_spec.R b/tests/testthat/test-filter_spec.R index bd38e1e7..a5b53f05 100644 --- a/tests/testthat/test-filter_spec.R +++ b/tests/testthat/test-filter_spec.R @@ -1,3 +1,9 @@ +ADSL <- teal.transform::rADSL # nolint +ADTTE <- teal.transform::rADTTE # nolint +data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE), ADLB = reactive(ADLB)) +join_keys <- teal.data::default_cdisc_join_keys[c("ADSL", "ADTTE", "ADLB")] +primary_keys_list <- lapply(join_keys, function(x) x[[1]]) + choices <- c("val1", "val2", "val3") choices_d <- c("val1", "val1", "val2", "val3") choices_f <- as.factor(choices) @@ -173,7 +179,7 @@ testthat::test_that("delayed filter_spec", { expect_equal(names(expected_spec), names(delayed)) data_list <- list(ADSL = reactive(ADSL)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL")) + key_list <- list(ADSL = c("STUDYID", "USUBJID")) result_spec <- isolate(resolve(delayed, data_list, key_list)) testthat::expect_identical(expected_spec, isolate(resolve(delayed, data_list, key_list))) @@ -288,13 +294,6 @@ testthat::test_that("delayed filter_spec works", { testthat::expect_identical(expected_spec, isolate(resolve(delayed, data_list, key_list))) }) - -ADSL <- teal.transform::rADSL # nolint -ADTTE <- teal.transform::rADTTE # nolint - -data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) -key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) - vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( list(data = "ADSL", subset = c("STUDYID", "USUBJID"), key = NULL), @@ -355,7 +354,7 @@ testthat::test_that("delayed version of filter_spec", { ) ) - res_obj <- isolate(resolve(obj, datasets = data_list, key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, key = primary_keys_list)) exp_obj <- filter_spec( vars = variable_choices(ADSL, subset = "ARMCD"), choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")), @@ -427,7 +426,7 @@ testthat::test_that("delayed version of filter_spec", { ) ) - res_obj <- isolate(resolve(obj, datasets = data_list, key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, key = primary_keys_list)) # comparison not implemented, must be done individually testthat::expect_equal(res_obj$choices, exp_obj$choices) @@ -448,13 +447,6 @@ testthat::test_that("all_choices passed to selected identical to all choices", { # With resolve_delayed testthat::test_that("delayed filter_spec - resolve_delayed", { - set.seed(1) - ADSL <- data.frame( # nolint - USUBJID = letters[1:10], - SEX = sample(c("F", "M", "U"), 10, replace = TRUE), - stringsAsFactors = FALSE - ) - expected_spec <- filter_spec( vars = variable_choices(ADSL, "SEX"), sep = "-", @@ -473,15 +465,8 @@ testthat::test_that("delayed filter_spec - resolve_delayed", { ) testthat::expect_equal(names(expected_spec), names(delayed)) - - ds <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = ADSL)), - join_keys = teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) - ) - ) - result_spec <- isolate(resolve_delayed(delayed, ds)) - testthat::expect_identical(expected_spec, isolate(resolve_delayed(delayed, ds))) + result_spec <- isolate(resolve_delayed(delayed, datasets = data_list, keys = primary_keys_list)) + testthat::expect_identical(expected_spec, result_spec) }) @@ -497,13 +482,6 @@ testthat::test_that( ) testthat::test_that("delayed filter_spec works - resolve_delayed", { - set.seed(1) - ADSL <- data.frame( # nolint - USUBJID = letters[1:10], - SEX = sample(c("F", "M", "U"), 10, replace = TRUE), - stringsAsFactors = FALSE - ) - expected_spec <- filter_spec_internal( vars_choices = variable_choices(ADSL), vars_selected = "SEX" @@ -515,26 +493,8 @@ testthat::test_that("delayed filter_spec works - resolve_delayed", { vars_selected = "SEX" ) - testthat::expect_equal( - class(delayed), - c( - "delayed_filter_spec", - "filter_spec", - "delayed_data" - ) - ) - - testthat::expect_equal(names(expected_spec), names(delayed)) - ds <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = ADSL)) - ) - - delayed$dataname <- "ADSL" - expected_spec$dataname <- "ADSL" - testthat::expect_identical( - expected_spec, - isolate(resolve_delayed(delayed, ds)) - ) + resolved <- isolate(resolve_delayed(delayed, datasets = data_list)) + testthat::expect_identical(expected_spec, resolved) expected_spec <- data_extract_spec( dataname = "ADSL", @@ -552,17 +512,12 @@ testthat::test_that("delayed filter_spec works - resolve_delayed", { ) ) - testthat::expect_identical(expected_spec, isolate(resolve_delayed(delayed, ds))) + testthat::expect_identical( + expected_spec, + isolate(resolve_delayed(delayed, datasets = data_list)) + ) }) -ADSL <- teal.transform::rADSL # nolint -ADTTE <- teal.transform::rADTTE # nolint -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL), - teal.data::cdisc_dataset("ADTTE", ADTTE) -) -ds <- teal.slice::init_filtered_data(data) - testthat::test_that("delayed version of filter_spec - resolve_delayed", { # hard-coded vars & choices & selected obj <- filter_spec( @@ -599,7 +554,7 @@ testthat::test_that("delayed version of filter_spec - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) exp_obj <- filter_spec( vars = variable_choices(ADSL, subset = "ARMCD"), choices = value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")), @@ -671,7 +626,7 @@ testthat::test_that("delayed version of filter_spec - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) # comparison not implemented, must be done individually testthat::expect_equal(res_obj$choices, exp_obj$choices) diff --git a/tests/testthat/test-format_data_extract.R b/tests/testthat/test-format_data_extract.R index 96e55b97..22d9e7d9 100644 --- a/tests/testthat/test-format_data_extract.R +++ b/tests/testthat/test-format_data_extract.R @@ -50,10 +50,3 @@ testthat::test_that("format_data_extract integrates with data_extract_srv", { } ) }) - -testthat::test_that("format_data_extract integrates with data_extract_srv and the filtered data object", { - skip_if_too_deep(4) - shinytest::expect_pass( - shinytest::testApp(testthat::test_path("shinytest/format_data_extract"), compareImages = FALSE) - ) -}) diff --git a/tests/testthat/test-get_dplyr_call.R b/tests/testthat/test-get_dplyr_call.R index 61386ada..adb10646 100644 --- a/tests/testthat/test-get_dplyr_call.R +++ b/tests/testthat/test-get_dplyr_call.R @@ -57,7 +57,7 @@ testthat::test_that("get_rename_call", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -65,7 +65,7 @@ testthat::test_that("get_rename_call", { dataname = "ADSL", filters = NULL, select = letters, - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ), @@ -73,7 +73,7 @@ testthat::test_that("get_rename_call", { dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test3" ), @@ -81,7 +81,7 @@ testthat::test_that("get_rename_call", { dataname = "ADSL", filters = NULL, select = c("aa", "bb"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test4" ) @@ -112,7 +112,7 @@ testthat::test_that("get_reshape_call", { multiple = FALSE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test" ) @@ -136,7 +136,7 @@ testthat::test_that("get_reshape_call", { multiple = TRUE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test" ) @@ -160,11 +160,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = NULL, select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote(ADSL %>% dplyr::select(STUDYID, USUBJID)) ) @@ -176,11 +176,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = list(list(columns = "SEX", selected = list("F", "M"))), select = character(0), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -196,11 +196,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = list(list(columns = "SEX", selected = list("F", "M"))), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -216,11 +216,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = list(list(columns = "SEX", selected = list("F"))), select = c("AVAL", "SEX"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -237,11 +237,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = list(list(columns = "SEX", selected = list("F"), drop_keys = TRUE)), select = c("AVAL", "SEX"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -257,11 +257,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = list(list(columns = "STUDYID", selected = list("ANY"), drop_keys = TRUE)), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -277,11 +277,11 @@ testthat::test_that("get_dplyr_call - single filter and single select", { dataname = "ADSL", filters = list(list(columns = "STUDYID", selected = list("ANY"), drop_keys = FALSE)), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -300,7 +300,7 @@ testthat::test_that("get_dplyr_call - multiple filter(s) or multiple select(s)", dataname = "ADSL", filters = NULL, select = c("COL_1", "COL_2"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -308,13 +308,13 @@ testthat::test_that("get_dplyr_call - multiple filter(s) or multiple select(s)", dataname = "ADSL", filters = NULL, select = c("COL_2", "COL_3"), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ) ), idx = 1L, - join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) ), quote( ADSL %>% @@ -326,26 +326,32 @@ testthat::test_that("get_dplyr_call - multiple filter(s) or multiple select(s)", # multiple variable filters, single selection, reshape by all keys even if filtered out (to keep proper label) testthat::expect_equal( get_dplyr_call( - list(list( - dataname = "ADLB", - filters = list(list( - columns = c("PARAMCD", "AVISIT"), - selected = list(c("ALBCV", "SCREENING"), c("ALBCV", "BASELINE")), - multiple = TRUE - )), - select = "AVAL", - keys = teal.data::get_cdisc_keys("ADLB"), - reshape = TRUE, - internal_id = "test1" - )), - join_keys = teal.data::join_keys(teal.data::join_key("ADLB", "ADLB", teal.data::get_cdisc_keys("ADSL"))) + list( + list( + dataname = "ADLB", + filters = list( + list( + columns = c("PARAMCD", "AVISIT"), + selected = list(c("ALBCV", "SCREENING"), c("ALBCV", "BASELINE")), + multiple = TRUE + ) + ), + select = "AVAL", + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), + reshape = TRUE, + internal_id = "test1" + ) + ), + join_keys = teal.data::join_keys(teal.data::join_key("ADLB", "ADLB", c("STUDYID", "USUBJID"))) ), - quote(ADLB %>% - dplyr::filter((PARAMCD == "ALBCV" & AVISIT == "SCREENING") | (PARAMCD == "ALBCV" & AVISIT == "BASELINE")) %>% - dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% - tidyr::pivot_longer(cols = "AVAL", names_to = "MEASURE", values_to = "VALUE") %>% - tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% - tidyr::pivot_wider(names_from = "KEY", values_from = "VALUE")) + quote( + ADLB %>% + dplyr::filter((PARAMCD == "ALBCV" & AVISIT == "SCREENING") | (PARAMCD == "ALBCV" & AVISIT == "BASELINE")) %>% + dplyr::select(STUDYID, USUBJID, PARAMCD, AVISIT, AVAL) %>% + tidyr::pivot_longer(cols = "AVAL", names_to = "MEASURE", values_to = "VALUE") %>% + tidyr::unite(KEY, MEASURE, PARAMCD, AVISIT) %>% + tidyr::pivot_wider(names_from = "KEY", values_from = "VALUE") + ) ) # multiple variable filters, single select - one key filtered out and dropped from select @@ -359,11 +365,11 @@ testthat::test_that("get_dplyr_call - multiple filter(s) or multiple select(s)", multiple = TRUE )), select = "AVAL", - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" )), - join_keys = teal.data::join_keys(teal.data::join_key("ADLB", "ADLB", teal.data::get_cdisc_keys("ADSL"))) + join_keys = teal.data::join_keys(teal.data::join_key("ADLB", "ADLB", c("STUDYID", "USUBJID"))) ), quote( ADLB %>% diff --git a/tests/testthat/test-get_filter_call-datasets.R b/tests/testthat/test-get_filter_call-datasets.R index 4148afd5..fbdc6709 100644 --- a/tests/testthat/test-get_filter_call-datasets.R +++ b/tests/testthat/test-get_filter_call-datasets.R @@ -91,8 +91,10 @@ testthat::test_that("get_filter_call - data - trunc POSIX and two columns", { )) ), dataname = "ADAMSET", data = data_list)), quote( - dplyr::filter((trunc(TRTSDTM) == "2020-03-08 06:28:11" & AGE == "33") | - (trunc(TRTSDTM) == "2020-03-09 06:28:11" & is.na(AGE))) + dplyr::filter( + (trunc(TRTSDTM) == "2020-03-08 06:28:11" & AGE == "33") | + (trunc(TRTSDTM) == "2020-03-09 06:28:11" & is.na(AGE)) + ) ) ) }) @@ -120,8 +122,7 @@ testthat::test_that("get_filter_call - data - three columns", { )) ), dataname = "ADAMSET", data = data_list)), quote( - dplyr::filter((SEX == "F" & AGE == "33" & is.na(DCSREAS)) | (SEX == - "M" & is.na(AGE) & is.na(DCSREAS))) + dplyr::filter((SEX == "F" & AGE == "33" & is.na(DCSREAS)) | (SEX == "M" & is.na(AGE) & is.na(DCSREAS))) ) ) }) diff --git a/tests/testthat/test-merge_expression_module.R b/tests/testthat/test-merge_expression_module.R index 09fabc0f..ef7d89e9 100644 --- a/tests/testthat/test-merge_expression_module.R +++ b/tests/testthat/test-merge_expression_module.R @@ -1,6 +1,6 @@ -adsl <- as.data.frame(as.list(stats::setNames(nm = c(teal.data::get_cdisc_keys("ADSL"), "AGE")))) +adsl <- as.data.frame(as.list(stats::setNames(nm = c(c("STUDYID", "USUBJID"), "AGE")))) adlb <- as.data.frame( - as.list(stats::setNames(nm = c(teal.data::get_cdisc_keys("ADLB"), "AVAL", "CHG", "CHG2", "ABLFL"))) + as.list(stats::setNames(nm = c(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "AVAL", "CHG", "CHG2", "ABLFL"))) ) data_list <- list(ADSL = reactive(adsl), ADLB = reactive(adlb)) diff --git a/tests/testthat/test-merge_expression_srv.R b/tests/testthat/test-merge_expression_srv.R index ceff634f..69ea5501 100644 --- a/tests/testthat/test-merge_expression_srv.R +++ b/tests/testthat/test-merge_expression_srv.R @@ -1,19 +1,12 @@ -adsl_df <- as.data.frame(as.list(stats::setNames(nm = c(teal.data::get_cdisc_keys("ADSL"), "AGE")))) -adlb_df <- as.data.frame( - as.list(stats::setNames(nm = c(teal.data::get_cdisc_keys("ADLB"), "AVAL", "CHG", "CHG2", "ABLFL"))) +adsl <- as.data.frame(as.list(stats::setNames(nm = c(c("STUDYID", "USUBJID"), "AGE")))) +adlb <- as.data.frame( + as.list(stats::setNames(nm = c(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "AVAL", "CHG", "CHG2", "ABLFL"))) ) -adsl <- teal.data::cdisc_dataset("ADSL", adsl_df) -adlb <- teal.data::cdisc_dataset("ADLB", adlb_df) +data_list <- list(ADSL = reactive(adsl), ADLB = reactive(adlb)) +data_list_nr <- list(ADSL = adsl, ADLB = adlb) -data_list <- list(ADSL = reactive(adsl_df), ADLB = reactive(adlb_df)) -data_list_nr <- list(ADSL = adsl_df, ADLB = adlb_df) - -join_keys <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), - teal.data::join_key("ADSL", "ADLB", c("STUDYID", "USUBJID")), - teal.data::join_key("ADLB", "ADLB", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) -) +join_keys <- teal.data::default_cdisc_join_keys[c("ADSL", "ADLB")] adsl_data_extract_srv_output <- list( @@ -233,11 +226,7 @@ testthat::test_that("merge_expression_srv returns merge expression when passing testthat::test_that("merge_expression_srv throws error if datasets is not a named list", { testthat::expect_error( - shiny::testServer( - merge_expression_srv, - args = list(selector_list = selector_list, datasets = list(adsl, adlb), join_keys = join_keys), - expr = NULL - ), + merge_expression_srv(selector_list = selector_list, datasets = list(adsl, adlb), join_keys = join_keys), "Assertion on 'datasets' failed: Must have names." ) }) diff --git a/tests/testthat/test-merge_utils.R b/tests/testthat/test-merge_utils.R index fcd382f4..1c12aa74 100644 --- a/tests/testthat/test-merge_utils.R +++ b/tests/testthat/test-merge_utils.R @@ -3,7 +3,7 @@ testthat::test_that("merge_selectors makes no changes when single selector is pr dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -20,7 +20,7 @@ testthat::test_that( dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -28,7 +28,7 @@ testthat::test_that( dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ) @@ -41,7 +41,7 @@ testthat::test_that( dataname = "ADSL", filters = NULL, select = c(utils::head(letters, 3), utils::tail(letters, 3)), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -57,7 +57,7 @@ testthat::test_that("merge selectors combines two selectorsdespite duplicated in dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -65,7 +65,7 @@ testthat::test_that("merge selectors combines two selectorsdespite duplicated in dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -78,7 +78,7 @@ testthat::test_that("merge selectors combines two selectorsdespite duplicated in dataname = "ADSL", filters = NULL, select = c(utils::head(letters, 3), utils::tail(letters, 3)), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -93,7 +93,7 @@ testthat::test_that("Two pairs of selectors combined into two selectors", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -101,7 +101,7 @@ testthat::test_that("Two pairs of selectors combined into two selectors", { dataname = "ADLB", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ) @@ -109,7 +109,7 @@ testthat::test_that("Two pairs of selectors combined into two selectors", { dataname = "ADSL", filters = NULL, select = tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test3" ) @@ -117,7 +117,7 @@ testthat::test_that("Two pairs of selectors combined into two selectors", { dataname = "ADLB", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test4" ) @@ -142,7 +142,7 @@ testthat::test_that("merge does not merge when reshape differs", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -150,7 +150,7 @@ testthat::test_that("merge does not merge when reshape differs", { dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = TRUE, internal_id = "test2" ) @@ -169,7 +169,7 @@ testthat::test_that("merge does not merge when filters differs", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = TRUE, internal_id = "test1" ) @@ -177,7 +177,7 @@ testthat::test_that("merge does not merge when filters differs", { dataname = "ADSL", filters = list(list(columns = "a", selected = list("1", "2"))), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ) @@ -198,7 +198,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -206,13 +206,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADSL") + c("STUDYID", "USUBJID") ), - rlang::set_names(teal.data::get_cdisc_keys("ADSL")) + rlang::set_names(c("STUDYID", "USUBJID")) ) # this is useful when merging two subsets of long datasets -> value columns next to each other @@ -223,7 +223,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = FALSE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -231,13 +231,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) # ignore "to" selector's filter testthat::expect_identical( @@ -246,7 +246,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -254,13 +254,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = FALSE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) # subtract from keys single filter on "from" selector testthat::expect_identical( @@ -269,7 +269,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = FALSE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -277,13 +277,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = FALSE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) # subtract if multiple filter and single selection testthat::expect_identical( @@ -292,7 +292,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = TRUE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -300,13 +300,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = FALSE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) # ignore if multiple filter with multiple selection testthat::expect_identical( @@ -315,7 +315,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = c("OS", "PFS"), multiple = TRUE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -323,13 +323,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = c("OS", "PFS"), multiple = FALSE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) # subtract only keys filter cols testthat::expect_identical( @@ -342,7 +342,7 @@ testthat::test_that("get_merge_key_pair works", { list(columns = "RACE", selected = "ASIAN", multiple = FALSE) ), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -350,13 +350,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) # do not subtract from primary key if not reshape and multiple filter column @@ -366,7 +366,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = c("OS", "PFS"), multiple = TRUE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -374,13 +374,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( get_merge_key_pair( @@ -388,7 +388,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -396,13 +396,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = c("OS", "PFS"), multiple = TRUE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( get_merge_key_pair( @@ -410,7 +410,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = c("OS", "PFS"), multiple = TRUE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -418,13 +418,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = c("OS", "PFS"), multiple = TRUE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) ## reshape cases @@ -439,7 +439,7 @@ testthat::test_that("get_merge_key_pair works", { list(columns = "RACE", selected = "ASIAN", multiple = TRUE) ), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -447,13 +447,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) ## reshape cases @@ -464,7 +464,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = TRUE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test1" ), @@ -472,13 +472,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) # no changes because only "from" filter is used testthat::expect_identical( @@ -487,7 +487,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test1" ), @@ -495,13 +495,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = TRUE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(teal.data::get_cdisc_keys("ADRS")) + rlang::set_names(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) # subtract by filter column on "from" selector testthat::expect_identical( @@ -510,7 +510,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = TRUE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test1" ), @@ -518,13 +518,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = list(list(columns = "PARAMCD", selected = "OS", multiple = TRUE)), select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) # subtract by filter key column on "from" selector testthat::expect_identical( @@ -537,7 +537,7 @@ testthat::test_that("get_merge_key_pair works", { list(columns = "RACE", selected = "ASIAN", multiple = TRUE) ), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test1" ), @@ -545,13 +545,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = TRUE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADRS") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADRS"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) testthat::expect_identical( @@ -560,7 +560,7 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADLB", filters = list(list(columns = "PARAMCD", selected = "ALT", multiple = FALSE)), select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -568,13 +568,13 @@ testthat::test_that("get_merge_key_pair works", { dataname = "ADLB", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADLB"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), - teal.data::get_cdisc_keys("ADLB") + c("STUDYID", "USUBJID", "PARAMCD", "AVISIT") ), - rlang::set_names(setdiff(teal.data::get_cdisc_keys("ADLB"), "PARAMCD")) + rlang::set_names(setdiff(c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), "PARAMCD")) ) }) @@ -585,7 +585,7 @@ testthat::test_that("get_merge_call", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ) @@ -600,7 +600,7 @@ testthat::test_that("get_merge_call", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -608,12 +608,12 @@ testthat::test_that("get_merge_call", { dataname = "ADSL", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test2" ) ) - jk <- teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL"))) + jk <- teal.data::join_keys(teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID"))) testthat::expect_identical( get_merge_call(x, jk), list( @@ -627,7 +627,7 @@ testthat::test_that("get_merge_call", { dataname = "ADRS", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test1" ), @@ -635,12 +635,12 @@ testthat::test_that("get_merge_call", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ) ) - jk <- teal.data::join_keys(teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS"))) + jk <- teal.data::join_keys(teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"))) testthat::expect_identical( get_merge_call(x, jk), list( @@ -656,7 +656,7 @@ testthat::test_that("get_merge_call", { dataname = "ADSL", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADSL"), + keys = c("STUDYID", "USUBJID"), reshape = FALSE, internal_id = "test1" ), @@ -664,7 +664,7 @@ testthat::test_that("get_merge_call", { dataname = "ADRS", filters = NULL, select = utils::head(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test2" ), @@ -672,15 +672,15 @@ testthat::test_that("get_merge_call", { dataname = "ADRS", filters = NULL, select = utils::tail(letters, 3), - keys = teal.data::get_cdisc_keys("ADRS"), + keys = c("STUDYID", "USUBJID", "PARAMCD", "AVISIT"), reshape = FALSE, internal_id = "test3" ) ) jk <- teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADSL", "ADRS", teal.data::get_cdisc_keys("ADSL")), - teal.data::join_key("ADRS", "ADRS", teal.data::get_cdisc_keys("ADRS")) + teal.data::join_key("ADSL", "ADSL", c("STUDYID", "USUBJID")), + teal.data::join_key("ADSL", "ADRS", c("STUDYID", "USUBJID")), + teal.data::join_key("ADRS", "ADRS", c("STUDYID", "USUBJID", "PARAMCD", "AVISIT")) ) testthat::expect_identical( get_merge_call(x, jk), diff --git a/tests/testthat/test-resolve.R b/tests/testthat/test-resolve.R index 7620638a..296c3eb4 100644 --- a/tests/testthat/test-resolve.R +++ b/tests/testthat/test-resolve.R @@ -73,36 +73,15 @@ testthat::test_that("resolve_delayed_expr works correctly", { testthat::test_that("resolve.list works correctly", { data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) ddl_resolved <- isolate(resolve(arm_ref_comp_ddl, data_list, key_list)) testthat::expect_identical(arm_ref_comp, ddl_resolved) }) - -testthat::test_that("resolving delayed choices removes selected not in choices and give a log output", { - iris_dataset <- teal.data::dataset("IRIS", head(iris)) - - c_s <- choices_selected( - choices = variable_choices("IRIS", c("Sepal.Length", "Sepal.Width")), - selected = variable_choices("IRIS", c("Petal.Length", "Sepal.Width")) - ) - - output <- testthat::capture_output({ - data_list <- list(IRIS = reactive(head(iris))) - key_list <- list(IRIS = character(0)) - resolved_cs <- isolate(resolve(c_s, data_list, key_list)) - }) - - testthat::expect_equal(resolved_cs$selected, stats::setNames("Sepal.Width", "Sepal.Width: Sepal.Width")) - testthat::expect_true( - grepl("Removing Petal.Length from 'selected' as not in 'choices' when resolving delayed choices_selected", output) - ) -}) - testthat::test_that("resolve throws error with non-reactive data.frames or unnamed list as input to datasets", { data_list <- list(ADSL = ADSL, ADTTE = ADTTE) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) testthat::expect_error( isolate(resolve(arm_ref_comp_ddl, data_list, key_list)), @@ -119,14 +98,14 @@ testthat::test_that("resolve throws error with non-reactive data.frames or unnam testthat::test_that("resolve throws error with unnamed list or wrong names as input to keys", { data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) - key_list <- list(teal.data::get_cdisc_keys("ADSL"), teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(c("STUDYID", "USUBJID"), c("STUDYID", "USUBJID", "PARAMCD")) testthat::expect_error( isolate(resolve(arm_ref_comp_ddl, data_list, key_list)), "Assertion on 'keys' failed: Must have names." ) - key_list <- list(AA = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(AA = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) testthat::expect_error( isolate(resolve(arm_ref_comp_ddl, data_list, key_list)), @@ -137,7 +116,7 @@ testthat::test_that("resolve throws error with unnamed list or wrong names as in testthat::test_that("resolve throws error with missing arguments", { data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) testthat::expect_error( isolate(resolve(arm_ref_comp_ddl, data_list)), diff --git a/tests/testthat/test-resolve_delayed.R b/tests/testthat/test-resolve_delayed.R index 30bc8223..3e8ff93c 100644 --- a/tests/testthat/test-resolve_delayed.R +++ b/tests/testthat/test-resolve_delayed.R @@ -1,11 +1,9 @@ adsl <- teal.transform::rADSL # nolint adtte <- teal.transform::rADTTE # nolint -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", adsl), - teal.data::cdisc_dataset("ADTTE", adtte) -) -ds <- teal.slice::init_filtered_data(data) +data_list <- list(ADSL = reactive(adsl), ADTTE = reactive(adtte)) +join_keys <- teal.data::default_cdisc_join_keys[c("ADSL", "ADTTE")] +primary_keys_list <- lapply(join_keys, function(keys) keys[[1]]) testthat::test_that("resolve_delayed_expr works correctly", { # function assumptions check @@ -77,13 +75,12 @@ testthat::test_that("resolve_delayed.FilteredData works correctly", { ), ARM2 = list(ref = "A: Drug X", comp = c("B: Placebo", "C: Combination")) ) - ddl_resolved <- isolate(resolve_delayed(arm_ref_comp_ddl, ds)) + ddl_resolved <- isolate(resolve_delayed(arm_ref_comp_ddl, datasets = data_list, keys = primary_keys_list)) testthat::expect_identical(arm_ref_comp, ddl_resolved) }) testthat::test_that("resolve_delayed.list works correctly with reactive objects", { - data <- list(ADSL = reactive(adsl), ADTTE = reactive(adtte)) arm_ref_comp <- list( ARMCD = list( ref = value_choices(adtte, var_choices = "ARMCD", var_label = "ARM", subset = "ARM A"), @@ -107,8 +104,8 @@ testthat::test_that("resolve_delayed.list works correctly with reactive objects" ddl_resolved <- isolate( resolve_delayed( arm_ref_comp_ddl, - data, - keys = list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) + data_list, + keys = primary_keys_list ) ) testthat::expect_identical(arm_ref_comp, ddl_resolved) @@ -155,8 +152,7 @@ testthat::test_that("resolving delayed choices removes selected not in choices a output <- testthat::capture_output({ shiny::isolate({ - ds <- teal.slice::init_filtered_data(list(IRIS = list(dataset = head(iris)))) - resolved_cs <- resolve_delayed(c_s, ds) + resolved_cs <- resolve_delayed(c_s, datasets = list(IRIS = reactive(iris))) }) }) diff --git a/tests/testthat/test-select_spec.R b/tests/testthat/test-select_spec.R index 90ab79d8..7fe19317 100644 --- a/tests/testthat/test-select_spec.R +++ b/tests/testthat/test-select_spec.R @@ -1,3 +1,8 @@ +adsl <- teal.transform::rADSL # nolint +adtte <- teal.transform::rADTTE # nolint +data_list <- list(ADSL = reactive(adsl), ADTTE = reactive(adtte)) +primary_keys_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) + testthat::test_that("Proper argument types", { choices <- c("c1", "c2", "c3") selected <- c("c1", "c2") @@ -80,17 +85,10 @@ testthat::test_that("Multiple choices", { }) testthat::test_that("resolve select_spec works", { - set.seed(1) - ADSL <- data.frame( # nolint - USUBJID = letters[1:10], - BMRKR1 = rnorm(10), - BMRKR2 = sample(c("L", "M", "H"), 10, replace = TRUE), - stringsAsFactors = FALSE - ) - attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") # nolint + attr(adsl, "keys") <- c("STUDYID", "USUBJID") # nolint expected_spec <- select_spec( - choices = variable_choices(ADSL, c("BMRKR1", "BMRKR2")), + choices = variable_choices(adsl, c("BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -107,15 +105,12 @@ testthat::test_that("resolve select_spec works", { testthat::expect_equal(names(expected_spec), names(delayed_spec)) - data_list <- list(ADSL = reactive(ADSL)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL")) - - testthat::expect_identical(expected_spec, isolate(resolve(delayed_spec, datasets = data_list, keys = key_list))) + testthat::expect_identical( + expected_spec, + isolate(resolve(delayed_spec, datasets = data_list, keys = primary_keys_list)) + ) }) -adsl <- teal.transform::rADSL # nolint -adtte <- teal.transform::rADTTE # nolint - vc_hard <- variable_choices("ADSL", subset = c("STUDYID", "USUBJID")) vc_hard_exp <- structure( list(data = "ADSL", subset = c("STUDYID", "USUBJID"), key = NULL), @@ -159,13 +154,10 @@ testthat::test_that("delayed version of select_spec", { ) ) - data_list <- list(ADSL = reactive(adsl), ADTTE = reactive(adtte)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) - - res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, keys = primary_keys_list)) exp_obj <- select_spec( - variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(adsl, "STUDYID", key = teal.data::get_cdisc_keys("ADSL")) + variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(adsl, "STUDYID", key = c("STUDYID", "USUBJID")) ) testthat::expect_equal(res_obj, exp_obj) @@ -187,7 +179,7 @@ testthat::test_that("delayed version of select_spec", { ) ) - res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal(res_obj, exp_obj) }) @@ -215,17 +207,10 @@ testthat::test_that("default values", { # With resolve_delayed testthat::test_that("resolve_delayed select_spec works - resolve_delayed", { - set.seed(1) - ADSL <- data.frame( # nolint - USUBJID = letters[1:10], - BMRKR1 = rnorm(10), - BMRKR2 = sample(c("L", "M", "H"), 10, replace = TRUE), - stringsAsFactors = FALSE - ) - attr(ADSL, "keys") <- teal.data::get_cdisc_keys("ADSL") # nolint + attr(adsl, "keys") <- c("STUDYID", "USUBJID") # nolint expected_spec <- select_spec( - choices = variable_choices(ADSL, c("BMRKR1", "BMRKR2")), + choices = variable_choices(adsl, c("BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE @@ -242,20 +227,12 @@ testthat::test_that("resolve_delayed select_spec works - resolve_delayed", { testthat::expect_equal(names(expected_spec), names(delayed_spec)) - ds <- teal.slice::init_filtered_data( - list(ADSL = list(dataset = ADSL)), - join_keys = teal.data::join_keys( - teal.data::join_key("ADSL", "ADSL", teal.data::get_cdisc_keys("ADSL")) - ) + testthat::expect_identical( + expected_spec, + isolate(resolve_delayed(delayed_spec, datasets = data_list, keys = primary_keys_list)) ) - testthat::expect_identical(expected_spec, isolate(resolve_delayed(delayed_spec, ds))) }) -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", adsl), - teal.data::cdisc_dataset("ADTTE", adtte) -) -ds <- teal.slice::init_filtered_data(data) testthat::test_that("delayed version of select_spec - resolve_delayed", { # hard-coded choices & selected @@ -276,10 +253,10 @@ testthat::test_that("delayed version of select_spec - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) exp_obj <- select_spec( - variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = teal.data::get_cdisc_keys("ADSL")), - selected = variable_choices(adsl, "STUDYID", key = teal.data::get_cdisc_keys("ADSL")) + variable_choices(adsl, subset = c("STUDYID", "USUBJID"), key = c("STUDYID", "USUBJID")), + selected = variable_choices(adsl, "STUDYID", key = c("STUDYID", "USUBJID")) ) testthat::expect_equal(res_obj, exp_obj) @@ -301,6 +278,7 @@ testthat::test_that("delayed version of select_spec - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal(res_obj, exp_obj) }) diff --git a/tests/testthat/test-value_choices.R b/tests/testthat/test-value_choices.R index bbeb05ed..c5b16843 100644 --- a/tests/testthat/test-value_choices.R +++ b/tests/testthat/test-value_choices.R @@ -1,5 +1,7 @@ ADSL <- teal.transform::rADSL # nolint ADTTE <- teal.transform::rADTTE # nolint +data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) +primary_keys_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) testthat::test_that("Will output warnings when value_choices applied on datasets with missing values and / or labels", { data <- data.frame( @@ -40,10 +42,8 @@ testthat::test_that("delayed version of value_choices", { class = c("delayed_value_choices", "delayed_data", "choices_labeled") ) ) - data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) - res_obj <- isolate(resolve(obj, datasets = data_list, key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal( res_obj, value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")) @@ -74,7 +74,7 @@ testthat::test_that("delayed version of value_choices", { ) ) - res_obj <- isolate(resolve(obj, datasets = data_list, key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal( res_obj, value_choices(ADSL, @@ -114,7 +114,7 @@ testthat::test_that("delayed version of value_choices", { ) ) - res_obj <- isolate(resolve(obj, datasets = data_list, key_list)) + res_obj <- isolate(resolve(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal( res_obj, value_choices(ADSL, @@ -126,12 +126,7 @@ testthat::test_that("delayed version of value_choices", { # With resolve_delayed -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL), - teal.data::cdisc_dataset("ADTTE", ADTTE) -) -ds <- teal.slice::init_filtered_data(data) testthat::test_that("delayed version of value_choices - resolve_delayed", { # hard-coded subset @@ -150,7 +145,7 @@ testthat::test_that("delayed version of value_choices - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal( res_obj, value_choices(ADSL, var_choices = "ARMCD", var_label = "ARM", subset = c("ARM A", "ARM B")) @@ -182,7 +177,7 @@ testthat::test_that("delayed version of value_choices - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal( res_obj, value_choices(ADSL, @@ -223,7 +218,7 @@ testthat::test_that("delayed version of value_choices - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) testthat::expect_equal( res_obj, value_choices(ADSL, diff --git a/tests/testthat/test-variable_choices.R b/tests/testthat/test-variable_choices.R index 6349d48e..fc06eae9 100644 --- a/tests/testthat/test-variable_choices.R +++ b/tests/testthat/test-variable_choices.R @@ -1,5 +1,7 @@ ADSL <- teal.transform::rADSL # nolint ADTTE <- teal.transform::rADTTE # nolint +data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) +primary_keys_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) test_that("Can create variable_choices with datasets with no or missing labels", { example_data <- data.frame(USUBJID = 1:2, STUDYID = 1:1) @@ -33,7 +35,7 @@ test_that("delayed version of variable_choices", { ) data_list <- list(ADSL = reactive(ADSL), ADTTE = reactive(ADTTE)) - key_list <- list(ADSL = teal.data::get_cdisc_keys("ADSL"), ADTTE = teal.data::get_cdisc_keys("ADTTE")) + key_list <- list(ADSL = c("STUDYID", "USUBJID"), ADTTE = c("STUDYID", "USUBJID", "PARAMCD")) res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) expect_equal( @@ -54,7 +56,7 @@ test_that("delayed version of variable_choices", { res_obj <- isolate(resolve(obj, datasets = data_list, keys = key_list)) expect_equal( res_obj, - variable_choices(ADSL, subset = colnames(ADSL)[1:2], key = teal.data::get_cdisc_keys("ADSL")) + variable_choices(ADSL, subset = colnames(ADSL)[1:2], key = c("STUDYID", "USUBJID")) ) # non-null key value @@ -74,13 +76,6 @@ test_that("delayed version of variable_choices", { ) }) -# with resolve_delayed -data <- teal.data::cdisc_data( - teal.data::cdisc_dataset("ADSL", ADSL), - teal.data::cdisc_dataset("ADTTE", ADTTE) -) - -ds <- teal.slice::init_filtered_data(data) test_that("delayed version of variable_choices - resolve_delayed", { # hard-coded subset @@ -93,7 +88,7 @@ test_that("delayed version of variable_choices - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) expect_equal( res_obj, variable_choices(ADSL, subset = c("SEX", "ARMCD", "COUNTRY")) @@ -110,10 +105,10 @@ test_that("delayed version of variable_choices - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) expect_equal( res_obj, - variable_choices(ADSL, subset = colnames(ADSL)[1:2], key = teal.data::get_cdisc_keys("ADSL")) + variable_choices(ADSL, subset = colnames(ADSL)[1:2], key = c("STUDYID", "USUBJID")) ) # non-null key value @@ -126,7 +121,7 @@ test_that("delayed version of variable_choices - resolve_delayed", { ) ) - res_obj <- isolate(resolve_delayed(obj, datasets = ds)) + res_obj <- isolate(resolve_delayed(obj, datasets = data_list, keys = primary_keys_list)) expect_equal( res_obj, variable_choices(ADSL, key = c("USUBJID", "STUDYID"))