diff --git a/NEWS.md b/NEWS.md index 2748ed54..c95de705 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ ### Breaking changes -* Replaced `chunks` with simpler `Quosure` class. +* Replaced `chunks` with simpler `qenv` class. * Replaced `datasets` argument containing `FilteredData` with the new arguments `data` (list of reactive datasets) and `filter_panel_api` (`FilterPanelAPI`). ### Enhancements diff --git a/R/tm_g_gh_boxplot.R b/R/tm_g_gh_boxplot.R index 3ec8f39e..d2914672 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -185,8 +185,8 @@ #' ) #' ) #' ) -#' \dontrun{ -#' shinyApp(app$ui, app$server) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) #' } #' tm_g_gh_boxplot <- function(label, @@ -370,6 +370,7 @@ srv_g_boxplot <- function(id, hline_vars_labels) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") + checkmate::assert_class(data, "tdata") moduleServer(id, function(input, output, session) { @@ -449,7 +450,7 @@ srv_g_boxplot <- function(id, sprintf("You can not choose %s as x-axis variable for treatment variable %s.", xaxis, trt_group) )) - anl_q()$quosure %>% teal.code::eval_code( + anl_q()$qenv %>% teal.code::eval_code( code = bquote({ p <- goshawk::g_boxplot( data = ANL, @@ -486,7 +487,7 @@ srv_g_boxplot <- function(id, font_size <- input$font_size trt_group <- input$trt_group - anl_q()$quosure %>% teal.code::eval_code( + anl_q()$qenv %>% teal.code::eval_code( code = bquote({ tbl <- goshawk::t_summarytable( data = ANL, diff --git a/R/tm_g_gh_correlationplot.R b/R/tm_g_gh_correlationplot.R index 89e9b74d..74ac4d90 100644 --- a/R/tm_g_gh_correlationplot.R +++ b/R/tm_g_gh_correlationplot.R @@ -244,8 +244,8 @@ #' ) #' ) #' ) -#' \dontrun{ -#' shinyApp(app$ui, app$server) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) #' } tm_g_gh_correlationplot <- function(label, dataname, @@ -438,6 +438,7 @@ srv_g_correlationplot <- function(id, vline_vars_labels) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") + checkmate::assert_class(data, "tdata") moduleServer(id, function(input, output, session) { @@ -539,15 +540,15 @@ srv_g_correlationplot <- function(id, ) # analysis - private_quosure <- teal.code::new_quosure(data) %>% + private_qenv <- teal.code::new_qenv(tdata2env(data), code = get_code(data)) %>% teal.code::eval_code( code = bquote({ ANL <- .(as.name(dataset_var)) %>% # nolint dplyr::filter(.data[[.(param_var)]] %in% union(.(input$xaxis_param), .(input$yaxis_param))) }) ) - validate_has_data(private_quosure[["ANL"]], 1) - return(list(ANL = ANL, quosure = private_quosure)) + validate_has_data(private_qenv[["ANL"]], 1) + return(list(ANL = ANL, qenv = private_qenv)) }) # constraints @@ -642,7 +643,7 @@ srv_g_correlationplot <- function(id, trt_group <- input$trt_group line_vars <- unique(c(input$hline_vars, input$vline_vars)) - private_q <- anl_constraint()$quosure %>% teal.code::eval_code( + private_q <- anl_constraint()$qenv %>% teal.code::eval_code( code = bquote({ ANL_TRANSPOSED1 <- ANL %>% # nolint dplyr::select( @@ -721,12 +722,12 @@ srv_g_correlationplot <- function(id, code = bquote(attr(ANL_TRANSPOSED[[.(trt_group)]], "label") <- attr(ANL[[.(trt_group)]], "label")) # nolint ) - return(list(ANL_TRANSPOSED = private_q[["ANL_TRANSPOSED"]], quosure = private_q)) + return(list(ANL_TRANSPOSED = private_q[["ANL_TRANSPOSED"]], qenv = private_q)) }) plot_labels <- reactive({ req(anl_constraint()) - ANL <- anl_constraint()$quosure[["ANL"]] # nolint + ANL <- anl_constraint()$qenv[["ANL"]] # nolint xparam <- ANL$PARAM[ANL[[param_var]] == input$xaxis_param][1] yparam <- ANL$PARAM[ANL[[param_var]] == input$yaxis_param][1] @@ -798,7 +799,7 @@ srv_g_correlationplot <- function(id, trt_group <- input$trt_group teal.code::eval_code( - object = plot_data_transpose()$quosure, + object = plot_data_transpose()$qenv, code = bquote({ # re-establish treatment variable label p <- goshawk::g_correlationplot( diff --git a/R/tm_g_gh_density_distribution_plot.R b/R/tm_g_gh_density_distribution_plot.R index 75cdd545..799a3659 100644 --- a/R/tm_g_gh_density_distribution_plot.R +++ b/R/tm_g_gh_density_distribution_plot.R @@ -137,8 +137,8 @@ #' ) #' ) #' ) -#' \dontrun{ -#' shinyApp(app$ui, app$server) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) #' } tm_g_gh_density_distribution_plot <- function(label, # nolint dataname, @@ -292,6 +292,7 @@ srv_g_density_distribution_plot <- function(id, # nolint plot_width) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") + checkmate::assert_class(data, "tdata") moduleServer(id, function(input, output, session) { anl_q <- constr_anl_q( @@ -343,7 +344,7 @@ srv_g_density_distribution_plot <- function(id, # nolint validate(need(input$trt_group, "Please select a treatment variable")) teal.code::eval_code( - object = anl_q()$quosure, + object = anl_q()$qenv, code = bquote({ p <- goshawk::g_density_distribution_plot( data = ANL, @@ -379,7 +380,7 @@ srv_g_density_distribution_plot <- function(id, # nolint validate(need(trt_group, "Please select a treatment variable")) teal.code::eval_code( - object = anl_q()$quosure, + object = anl_q()$qenv, code = bquote( tbl <- goshawk::t_summarytable( data = ANL, diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index 831548f2..82a26755 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -147,8 +147,8 @@ #' ) #' ) #' ) -#' \dontrun{ -#' shinyApp(app$ui, app$server) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) #' } tm_g_gh_lineplot <- function(label, dataname, @@ -354,6 +354,7 @@ srv_lineplot <- function(id, plot_width) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") + checkmate::assert_class(data, "tdata") moduleServer(id, function(input, output, session) { ns <- session$ns @@ -706,11 +707,11 @@ srv_lineplot <- function(id, ) ) - private_quosure <- anl_q()$quosure + private_qenv <- anl_q()$qenv if (!methods::is(xtick, "waiver") && !is.null(xtick)) { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = bquote({ keep_index <- which(.(xtick) %in% ANL[[.(xaxis)]]) xtick <- (.(xtick))[keep_index] # extra parentheses needed for edge case, e.g. 1:5[keep_index] @@ -718,8 +719,8 @@ srv_lineplot <- function(id, }) ) } else if (methods::is(xtick, "waiver")) { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = " xtick <- ggplot2::waiver() xlabel <- ggplot2::waiver() @@ -732,7 +733,7 @@ srv_lineplot <- function(id, hline_arb_color <- horizontal_line()$line_arb_color teal.code::eval_code( - object = private_quosure, + object = private_qenv, code = bquote({ p <- goshawk::g_lineplot( data = ANL[complete.cases(ANL[, c(.(yaxis), .(xaxis))]), ], diff --git a/R/tm_g_gh_scatterplot.R b/R/tm_g_gh_scatterplot.R index 4cc3d3c3..0b7508cc 100644 --- a/R/tm_g_gh_scatterplot.R +++ b/R/tm_g_gh_scatterplot.R @@ -135,8 +135,8 @@ #' ) #' ) #' ) -#' \dontrun{ -#' shinyApp(app$ui, app$server) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) #' } #' tm_g_gh_scatterplot <- function(label, @@ -279,6 +279,7 @@ srv_g_scatterplot <- function(id, plot_width) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") + checkmate::assert_class(data, "tdata") moduleServer(id, function(input, output, session) { @@ -326,7 +327,7 @@ srv_g_scatterplot <- function(id, # nolint end teal.code::eval_code( - object = anl_q()$quosure, + object = anl_q()$qenv, code = bquote({ # re-establish treatment variable label p <- goshawk::g_scatterplot( diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index 8019a065..39611972 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -191,8 +191,8 @@ #' ) #' ) #' ) -#' \dontrun{ -#' shinyApp(app$ui, app$server) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) #' } #' tm_g_gh_spaghettiplot <- function(label, @@ -376,6 +376,7 @@ srv_g_spaghettiplot <- function(id, hline_vars_labels) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") + checkmate::assert_class(data, "tdata") moduleServer(id, function(input, output, session) { @@ -420,36 +421,36 @@ srv_g_spaghettiplot <- function(id, hline_vars <- input$hline_vars # nolint end - private_quosure <- anl_q()$quosure + private_qenv <- anl_q()$qenv # this code is needed to make sure the waiver attribute # of ggplot2::waiver is correctly passed to goshawk's spaghettiplot if (!methods::is(xtick, "waiver")) { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = bquote(xtick <- .(xtick)) ) } else { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = quote(xtick <- ggplot2::waiver()) ) } if (!methods::is(xlabel, "waiver")) { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = bquote(xlabel <- .(xlabel)) ) } else { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = quote(xlabel <- ggplot2::waiver()) ) } teal.code::eval_code( - object = private_quosure, + object = private_qenv, code = bquote({ p <- goshawk::g_spaghettiplot( data = ANL, diff --git a/R/utils.R b/R/utils.R index 7d70588c..8c89de3d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -197,7 +197,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr validate_has_variable(ANL, trt_group) # analysis - private_quosure <- teal.code::new_quosure(data) %>% + private_qenv <- teal.code::new_qenv(tdata2env(data), code = get_code(data)) %>% teal.code::eval_code( substitute(ANL <- dataname, list(dataname = as.name(dataname))) # nolint ) %>% @@ -207,8 +207,8 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr dplyr::filter(.(as.name(param_var)) == .(param_var_value)) }) ) - validate_has_data(private_quosure[["ANL"]], min_rows) - list(ANL = ANL, quosure = private_quosure) + validate_has_data(private_qenv[["ANL"]], min_rows) + list(ANL = ANL, qenv = private_qenv) }) observe({ @@ -293,7 +293,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr # e.g. `ALT.BASE2` (i.e. `PARAMCD = ALT & range_filter_on(BASE2)`) create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows) { reactive({ - private_quosure <- anl_param()$quosure + private_qenv <- anl_param()$qenv # it is assumed that constraint_var is triggering constraint_range which then trigger this clause constraint_var <- isolate(input[["constraint_var"]]) @@ -308,8 +308,8 @@ create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows) # filter constraint if (constraint_var != "NONE") { - private_quosure <- teal.code::eval_code( - object = private_quosure, + private_qenv <- teal.code::eval_code( + object = private_qenv, code = bquote({ # the below includes patients who have at least one non-NA BASE value # ideally, a patient should either have all NA values or none at all @@ -334,10 +334,10 @@ create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows) ANL <- ANL %>% dplyr::filter(USUBJID %in% filtered_usubjids) # nolint }) ) - validate_has_data(private_quosure[["ANL"]], min_rows) + validate_has_data(private_qenv[["ANL"]], min_rows) } - return(list(ANL = private_quosure[["ANL"]], quosure = private_quosure)) + return(list(ANL = private_qenv[["ANL"]], qenv = private_qenv)) }) } diff --git a/man/tm_g_gh_boxplot.Rd b/man/tm_g_gh_boxplot.Rd index 6b7d3b70..43d48170 100644 --- a/man/tm_g_gh_boxplot.Rd +++ b/man/tm_g_gh_boxplot.Rd @@ -243,8 +243,8 @@ app <- teal::init( ) ) ) -\dontrun{ -shinyApp(app$ui, app$server) +if (interactive()) { + shinyApp(app$ui, app$server) } } diff --git a/man/tm_g_gh_correlationplot.Rd b/man/tm_g_gh_correlationplot.Rd index b136d0ae..af34c638 100644 --- a/man/tm_g_gh_correlationplot.Rd +++ b/man/tm_g_gh_correlationplot.Rd @@ -320,8 +320,8 @@ app <- init( ) ) ) -\dontrun{ -shinyApp(app$ui, app$server) +if (interactive()) { + shinyApp(app$ui, app$server) } } \author{ diff --git a/man/tm_g_gh_density_distribution_plot.Rd b/man/tm_g_gh_density_distribution_plot.Rd index 0967ad12..42a3dd12 100644 --- a/man/tm_g_gh_density_distribution_plot.Rd +++ b/man/tm_g_gh_density_distribution_plot.Rd @@ -186,8 +186,8 @@ app <- teal::init( ) ) ) -\dontrun{ -shinyApp(app$ui, app$server) +if (interactive()) { + shinyApp(app$ui, app$server) } } \author{ diff --git a/man/tm_g_gh_lineplot.Rd b/man/tm_g_gh_lineplot.Rd index 06f5bc72..8dfbd12d 100644 --- a/man/tm_g_gh_lineplot.Rd +++ b/man/tm_g_gh_lineplot.Rd @@ -216,8 +216,8 @@ app <- teal::init( ) ) ) -\dontrun{ -shinyApp(app$ui, app$server) +if (interactive()) { + shinyApp(app$ui, app$server) } } \author{ diff --git a/man/tm_g_gh_scatterplot.Rd b/man/tm_g_gh_scatterplot.Rd index 4b6a12c2..4d0cf5d5 100644 --- a/man/tm_g_gh_scatterplot.Rd +++ b/man/tm_g_gh_scatterplot.Rd @@ -185,8 +185,8 @@ app <- init( ) ) ) -\dontrun{ -shinyApp(app$ui, app$server) +if (interactive()) { + shinyApp(app$ui, app$server) } } diff --git a/man/tm_g_gh_spaghettiplot.Rd b/man/tm_g_gh_spaghettiplot.Rd index 7e98799e..74f8116d 100644 --- a/man/tm_g_gh_spaghettiplot.Rd +++ b/man/tm_g_gh_spaghettiplot.Rd @@ -258,8 +258,8 @@ app <- teal::init( ) ) ) -\dontrun{ -shinyApp(app$ui, app$server) +if (interactive()) { + shinyApp(app$ui, app$server) } }