diff --git a/NEWS.md b/NEWS.md index 305bd31e0..efbb24039 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ * Removed `Show Warnings` modals from modules. * Soft deprecated `datasets_selected` argument of modules in favor of `datanames`. * Soft deprecated `show_metadata` argument of `tm_front_page()` in favor of `datanames`. +* Modules' Show R Code widgets include library calls and their code is styled with `styler` package (#847, #786). ### Enhancements diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index ed13916f5..bafa7695c 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -434,10 +434,10 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl selector_list = selector_list, datasets = data ) - + qenv <- teal.code::eval_code(data(), 'library("ggplot2");library("dplyr");library("tidyr")') # nolint quotes anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -581,12 +581,12 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl theme = list( legend.position = "right", legend.spacing.y = quote(grid::unit(-5, "pt")), - legend.title = quote(element_text(vjust = 25)), + legend.title = quote(ggplot2::element_text(vjust = 25)), axis.text.x = substitute( - element_text(angle = angle_value, hjust = hjust_value), + ggplot2::element_text(angle = angle_value, hjust = hjust_value), list(angle_value = angle_value, hjust_value = hjust_value) ), - text = substitute(element_text(size = font_size), list(font_size = font_size)) + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)) ) ) @@ -611,24 +611,24 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) cols <- c(getOption("ggplot2.discrete.colour"), c("lightblue", "darkred", "black"))[1:3] - elbow_plot <- ggplot(mapping = aes_string(x = "component", y = "value")) + - geom_bar( - aes(fill = "Single variance"), + elbow_plot <- ggplot2::ggplot(mapping = aes_string(x = "component", y = "value")) + + ggplot2::geom_bar( + ggplot2::aes(fill = "Single variance"), data = dplyr::filter(elb_dat, metric == "Proportion of Variance"), color = "black", stat = "identity" ) + - geom_point( - aes(color = "Cumulative variance"), + ggplot2::geom_point( + ggplot2::aes(color = "Cumulative variance"), data = dplyr::filter(elb_dat, metric == "Cumulative Proportion") ) + - geom_line( - aes(group = 1, color = "Cumulative variance"), + ggplot2::geom_line( + ggplot2::aes(group = 1, color = "Cumulative variance"), data = dplyr::filter(elb_dat, metric == "Cumulative Proportion") ) + labs + - scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) + - scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + + ggplot2::scale_color_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[3])) + + ggplot2::scale_fill_manual(values = c("Cumulative variance" = cols[2], "Single variance" = cols[1])) + ggthemes + themes }, @@ -656,9 +656,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( theme = list( - text = substitute(element_text(size = font_size), list(font_size = font_size)), + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - element_text(angle = angle_val, hjust = hjust_val), + ggplot2::element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -688,15 +688,15 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl y = sin(seq(0, 2 * pi, length.out = 100)) ) - circle_plot <- ggplot(pca_rot) + - geom_point(aes_string(x = x_axis, y = y_axis)) + - geom_label( - aes_string(x = x_axis, y = y_axis, label = "label"), + circle_plot <- ggplot2::ggplot(pca_rot) + + ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis)) + + ggplot2::geom_label( + ggplot2::aes_string(x = x_axis, y = y_axis, label = "label"), nudge_x = 0.1, nudge_y = 0.05, fontface = "bold" ) + - geom_path(aes(x, y, group = 1), data = circle_data) + - geom_point(aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) + + ggplot2::geom_path(ggplot2::aes(x, y, group = 1), data = circle_data) + + ggplot2::geom_point(ggplot2::aes(x = x, y = y), data = data.frame(x = 0, y = 0), shape = "x", size = 5) + labs + ggthemes + themes @@ -790,7 +790,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_point(aes_string(x = x_axis, y = y_axis), data = pca_rot, alpha = alpha, size = size), + ggplot2::geom_point(ggplot2::aes_string(x = x_axis, y = y_axis), + data = pca_rot, alpha = alpha, size = size + ), list(x_axis = input$x_axis, y_axis = input$y_axis, alpha = input$alpha, size = input$size) ) ) @@ -801,7 +803,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl response <- ANL[[resp_col]] aes_biplot <- substitute( - aes_string(x = x_axis, y = y_axis, color = "response"), + ggplot2::aes_string(x = x_axis, y = y_axis, color = "response"), env = list(x_axis = x_axis, y_axis = y_axis) ) @@ -822,7 +824,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, quote(pca_rot$response <- as.factor(response)) ) - quote(scale_color_brewer(palette = "Dark2")) + quote(ggplot2::scale_color_brewer(palette = "Dark2")) } else if (inherits(response, "Date")) { qenv <- teal.code::eval_code( qenv, @@ -830,7 +832,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ) quote( - scale_color_gradient( + ggplot2::scale_color_gradient( low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1], high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1], labels = function(x) as.Date(x, origin = "1970-01-01") @@ -841,7 +843,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl qenv, quote(pca_rot$response <- response) ) - quote(scale_color_gradient( + quote(ggplot2::scale_color_gradient( low = c(getOption("ggplot2.discrete.colour")[2], "darkred")[1], high = c(getOption("ggplot2.discrete.colour"), "lightblue")[1] )) @@ -850,7 +852,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size), + ggplot2::geom_point(aes_biplot, data = pca_rot, alpha = alpha, size = size), env = list(aes_biplot = aes_biplot, alpha = alpha, size = size) ), scales_biplot @@ -861,8 +863,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl pca_plot_biplot_expr <- c( pca_plot_biplot_expr, substitute( - geom_segment( - aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis), + ggplot2::geom_segment( + ggplot2::aes_string(x = "xstart", y = "ystart", xend = x_axis, yend = y_axis), data = rot_vars, lineend = "round", linejoin = "round", arrow = grid::arrow(length = grid::unit(0.5, "cm")) @@ -870,8 +872,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl env = list(x_axis = x_axis, y_axis = y_axis) ), substitute( - geom_label( - aes_string( + ggplot2::geom_label( + ggplot2::aes_string( x = x_axis, y = y_axis, label = "label" @@ -882,7 +884,7 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ), env = list(x_axis = x_axis, y_axis = y_axis) ), - quote(geom_point(aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5)) + quote(ggplot2::geom_point(ggplot2::aes(x = xstart, y = ystart), data = rot_vars, shape = "x", size = 5)) ) } @@ -892,9 +894,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( labs = dev_labs, theme = list( - text = substitute(element_text(size = font_size), list(font_size = font_size)), + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - element_text(angle = angle_val, hjust = hjust_val), + ggplot2::element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -942,9 +944,9 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl dev_ggplot2_args <- teal.widgets::ggplot2_args( theme = list( - text = substitute(element_text(size = font_size), list(font_size = font_size)), + text = substitute(ggplot2::element_text(size = font_size), list(font_size = font_size)), axis.text.x = substitute( - element_text(angle = angle_val, hjust = hjust_val), + ggplot2::element_text(angle = angle_val, hjust = hjust_val), list(angle_val = angle, hjust_val = hjust) ) ) @@ -965,8 +967,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl list( quote(ggplot(pca_rot)), substitute( - geom_bar( - aes_string(x = "Variable", y = pc), + ggplot2::geom_bar( + ggplot2::aes_string(x = "Variable", y = pc), stat = "identity", color = "black", fill = c(getOption("ggplot2.discrete.colour"), "lightblue")[1] @@ -974,8 +976,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl env = list(pc = pc) ), substitute( - geom_text( - aes( + ggplot2::geom_text( + ggplot2::aes( x = Variable, y = pc_name, label = round(pc_name, 3), diff --git a/R/tm_a_regression.R b/R/tm_a_regression.R index bd976690a..419aead04 100644 --- a/R/tm_a_regression.R +++ b/R/tm_a_regression.R @@ -460,9 +460,14 @@ srv_a_regression <- function(id, ) }) + qenv <- teal.code::eval_code( + data(), + 'library("ggplot2");library("dplyr")' # nolint quotes + ) + anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -507,7 +512,7 @@ srv_a_regression <- function(id, selected = restoreInput(ns("label_var"), selected) ) - data <- fortify(stats::lm(form, data = ANL)) + data <- ggplot2::fortify(stats::lm(form, data = ANL)) cooksd <- data$.cooksd[!is.nan(data$.cooksd)] max_outlier <- max(ceiling(max(cooksd) / mean(cooksd)), 2) cur_outlier <- isolate(input$outlier) @@ -597,9 +602,9 @@ srv_a_regression <- function(id, shinyjs::show("size") shinyjs::show("alpha") plot <- substitute( - expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) + - geom_point(size = size, alpha = alpha) + - stat_smooth(method = "lm", formula = y ~ x, se = FALSE), + expr = ggplot2::ggplot(fit$model[, 2:1], ggplot2::aes_string(regressor, response)) + + ggplot2::geom_point(size = size, alpha = alpha) + + ggplot2::stat_smooth(method = "lm", formula = y ~ x, se = FALSE), env = list( regressor = regression_var()$regressor, response = regression_var()$response, @@ -617,8 +622,8 @@ srv_a_regression <- function(id, shinyjs::hide("size") shinyjs::hide("alpha") plot <- substitute( - expr = ggplot(fit$model[, 2:1], aes_string(regressor, response)) + - geom_boxplot(), + expr = ggplot2::ggplot(fit$model[, 2:1], ggplot2::aes_string(regressor, response)) + + ggplot2::geom_boxplot(), env = list(regressor = regression_var()$regressor, response = regression_var()$response) ) if (input$show_outlier) { @@ -647,7 +652,7 @@ srv_a_regression <- function(id, substitute( expr = { class(fit$residuals) <- NULL - data <- fortify(fit) + data <- ggplot2::fortify(fit) plot <- graph }, env = list( @@ -662,10 +667,10 @@ srv_a_regression <- function(id, shinyjs::show("size") shinyjs::show("alpha") plot <- substitute( - expr = ggplot(data = data, aes(.fitted, .resid)) + - geom_point(size = size, alpha = alpha) + - geom_hline(yintercept = 0, linetype = "dashed", size = 1) + - geom_line(data = smoothy, mapping = smoothy_aes), + expr = ggplot2::ggplot(data = data, ggplot2::aes(.fitted, .resid)) + + ggplot2::geom_point(size = size, alpha = alpha) + + ggplot2::geom_hline(yintercept = 0, linetype = "dashed", size = 1) + + ggplot2::geom_line(data = smoothy, mapping = smoothy_aes), env = list(size = input$size, alpha = input$alpha) ) if (input$show_outlier) { @@ -706,15 +711,15 @@ srv_a_regression <- function(id, shinyjs::show("alpha") plot_base <- output_plot_base() plot <- substitute( - expr = ggplot(data = data, aes(sample = .stdresid)) + - stat_qq(size = size, alpha = alpha) + - geom_abline(linetype = "dashed"), + expr = ggplot2::ggplot(data = data, ggplot2::aes(sample = .stdresid)) + + ggplot2::stat_qq(size = size, alpha = alpha) + + ggplot2::geom_abline(linetype = "dashed"), env = list(size = input$size, alpha = input$alpha) ) if (input$show_outlier) { plot <- substitute( expr = plot + - stat_qq( + ggplot2::stat_qq( geom = ggrepel::GeomTextRepel, label = label_col %>% data.frame(label = .) %>% @@ -765,9 +770,9 @@ srv_a_regression <- function(id, shinyjs::show("alpha") plot_base <- output_plot_base() plot <- substitute( - expr = ggplot(data = data, aes(.fitted, sqrt(abs(.stdresid)))) + - geom_point(size = size, alpha = alpha) + - geom_line(data = smoothy, mapping = smoothy_aes), + expr = ggplot2::ggplot(data = data, ggplot2::aes(.fitted, sqrt(abs(.stdresid)))) + + ggplot2::geom_point(size = size, alpha = alpha) + + ggplot2::geom_line(data = smoothy, mapping = smoothy_aes), env = list(size = input$size, alpha = input$alpha) ) if (input$show_outlier) { @@ -808,14 +813,14 @@ srv_a_regression <- function(id, shinyjs::show("alpha") plot_base <- output_plot_base() plot <- substitute( - expr = ggplot(data = data, aes(seq_along(.cooksd), .cooksd)) + - geom_col(alpha = alpha), + expr = ggplot2::ggplot(data = data, ggplot2::aes(seq_along(.cooksd), .cooksd)) + + ggplot2::geom_col(alpha = alpha), env = list(alpha = input$alpha) ) if (input$show_outlier) { plot <- substitute( expr = plot + - geom_hline( + ggplot2::geom_hline( yintercept = c( outlier * mean(data$.cooksd, na.rm = TRUE), mean(data$.cooksd, na.rm = TRUE) @@ -823,8 +828,8 @@ srv_a_regression <- function(id, color = "red", linetype = "dashed" ) + - geom_text( - aes( + ggplot2::geom_text( + ggplot2::aes( x = 0, y = mean(data$.cooksd, na.rm = TRUE), label = paste("mu", "=", round(mean(data$.cooksd, na.rm = TRUE), 4)), @@ -874,21 +879,21 @@ srv_a_regression <- function(id, shinyjs::show("alpha") plot_base <- output_plot_base() plot <- substitute( - expr = ggplot(data = data, aes(.hat, .stdresid)) + - geom_vline( + expr = ggplot2::ggplot(data = data, ggplot2::aes(.hat, .stdresid)) + + ggplot2::geom_vline( size = 1, colour = "black", linetype = "dashed", xintercept = 0 ) + - geom_hline( + ggplot2::geom_hline( size = 1, colour = "black", linetype = "dashed", yintercept = 0 ) + - geom_point(size = size, alpha = alpha) + - geom_line(data = smoothy, mapping = smoothy_aes), + ggplot2::geom_point(size = size, alpha = alpha) + + ggplot2::geom_line(data = smoothy, mapping = smoothy_aes), env = list(size = input$size, alpha = input$alpha) ) if (input$show_outlier) { @@ -929,16 +934,16 @@ srv_a_regression <- function(id, shinyjs::show("alpha") plot_base <- output_plot_base() plot <- substitute( - expr = ggplot(data = data, aes(.hat, .cooksd)) + - geom_vline(xintercept = 0, colour = NA) + - geom_abline( + expr = ggplot2::ggplot(data = data, ggplot2::aes(.hat, .cooksd)) + + ggplot2::geom_vline(xintercept = 0, colour = NA) + + ggplot2::geom_abline( slope = seq(0, 3, by = 0.5), colour = "black", linetype = "dashed", size = 1 ) + - geom_line(data = smoothy, mapping = smoothy_aes) + - geom_point(size = size, alpha = alpha), + ggplot2::geom_line(data = smoothy, mapping = smoothy_aes) + + ggplot2::geom_point(size = size, alpha = alpha), env = list(size = input$size, alpha = input$alpha) ) if (input$show_outlier) { diff --git a/R/tm_data_table.R b/R/tm_data_table.R index 5e28747f9..ea26d182a 100644 --- a/R/tm_data_table.R +++ b/R/tm_data_table.R @@ -318,9 +318,12 @@ srv_data_table <- function(id, df <- data()[[dataname]] teal::validate_has_data(df, min_nrow = 1L, msg = paste("data", dataname, "is empty")) - - teal.code::eval_code( + qenv <- teal.code::eval_code( data(), + 'library("dplyr");library("DT")' # nolint quotes + ) + teal.code::eval_code( + qenv, substitute( expr = { variables <- vars diff --git a/R/tm_g_association.R b/R/tm_g_association.R index b14a2ba34..5c67f136e 100644 --- a/R/tm_g_association.R +++ b/R/tm_g_association.R @@ -342,9 +342,13 @@ srv_tm_g_association <- function(id, selector_list = selector_list ) + qenv <- teal.code::eval_code( + data(), + 'library("ggplot2");library("dplyr");library("tern");library("ggmosaic")' # nolint quotes + ) anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) merged <- list( @@ -498,9 +502,10 @@ srv_tm_g_association <- function(id, teal.code::eval_code( substitute( expr = { - plot_top <- plot_calls[[1]] - plot_bottom <- plot_calls[[1]] - plot <- tern::stack_grobs(grobs = lapply(list(plot_top, plot_bottom), ggplotGrob)) + plots <- plot_calls + plot_top <- plots[[1]] + plot_bottom <- plots[[2]] + plot <- tern::stack_grobs(grobs = lapply(list(plot_top, plot_bottom), ggplot2::ggplotGrob)) }, env = list( plot_calls = do.call( diff --git a/R/tm_g_bivariate.R b/R/tm_g_bivariate.R index 14fec9e90..5f8c9f6d4 100644 --- a/R/tm_g_bivariate.R +++ b/R/tm_g_bivariate.R @@ -547,10 +547,14 @@ srv_g_bivariate <- function(id, selector_list = selector_list, datasets = data ) + qenv <- teal.code::eval_code( + data(), + 'library("ggplot2");library("dplyr");library("teal.modules.general")' # nolint quotes + ) anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -729,6 +733,7 @@ srv_g_bivariate <- function(id, ) # Render R code. + source_code_r <- reactive(teal.code::get_code(req(decorated_output_q_facets()))) teal.widgets::verbatim_popup_srv( @@ -856,89 +861,89 @@ bivariate_ggplot_call <- function(x_class, Reduce(function(x, y) call("+", x, y), args) } - plot_call <- substitute(ggplot(data_name), env = list(data_name = as.name(data_name))) + plot_call <- substitute(ggplot2::ggplot(data_name), env = list(data_name = as.name(data_name))) # Single data plots if (x_class == "numeric" && y_class == "NULL") { - plot_call <- reduce_plot_call(plot_call, substitute(aes(x = xval), env = list(xval = x))) + plot_call <- reduce_plot_call(plot_call, substitute(ggplot2::aes(x = xval), env = list(xval = x))) if (freq) { plot_call <- reduce_plot_call( plot_call, - quote(geom_histogram(bins = 30)), - quote(ylab("Frequency")) + quote(ggplot2::geom_histogram(bins = 30)), + quote(ggplot2::ylab("Frequency")) ) } else { plot_call <- reduce_plot_call( plot_call, - quote(geom_histogram(bins = 30, aes(y = after_stat(density)))), - quote(geom_density(aes(y = after_stat(density)))), - quote(ylab("Density")) + quote(ggplot2::geom_histogram(bins = 30, ggplot2::aes(y = ggplot2::after_stat(density)))), + quote(ggplot2::geom_density(ggplot2::aes(y = ggplot2::after_stat(density)))), + quote(ggplot2::ylab("Density")) ) } } else if (x_class == "NULL" && y_class == "numeric") { - plot_call <- reduce_plot_call(plot_call, substitute(aes(x = yval), env = list(yval = y))) + plot_call <- reduce_plot_call(plot_call, substitute(ggplot2::aes(x = yval), env = list(yval = y))) if (freq) { plot_call <- reduce_plot_call( plot_call, - quote(geom_histogram(bins = 30)), - quote(ylab("Frequency")) + quote(ggplot2::geom_histogram(bins = 30)), + quote(ggplot2::ylab("Frequency")) ) } else { plot_call <- reduce_plot_call( plot_call, - quote(geom_histogram(bins = 30, aes(y = after_stat(density)))), - quote(geom_density(aes(y = after_stat(density)))), - quote(ylab("Density")) + quote(ggplot2::geom_histogram(bins = 30, aes(y = ggplot2::after_stat(density)))), + quote(ggplot2::geom_density(ggplot2::aes(y = ggplot2::after_stat(density)))), + quote(ggplot2::ylab("Density")) ) } } else if (x_class == "factor" && y_class == "NULL") { - plot_call <- reduce_plot_call(plot_call, substitute(aes(x = xval), env = list(xval = x))) + plot_call <- reduce_plot_call(plot_call, substitute(ggplot2::aes(x = xval), env = list(xval = x))) if (freq) { plot_call <- reduce_plot_call( plot_call, - quote(geom_bar()), - quote(ylab("Frequency")) + quote(ggplot2::geom_bar()), + quote(ggplot2::ylab("Frequency")) ) } else { plot_call <- reduce_plot_call( plot_call, - quote(geom_bar(aes(y = after_stat(prop), group = 1))), - quote(ylab("Fraction")) + quote(ggplot2::geom_bar(ggplot2::aes(y = ggplot2::after_stat(prop), group = 1))), + quote(ggplot2::ylab("Fraction")) ) } } else if (x_class == "NULL" && y_class == "factor") { - plot_call <- reduce_plot_call(plot_call, substitute(aes(x = yval), env = list(yval = y))) + plot_call <- reduce_plot_call(plot_call, substitute(ggplot2::aes(x = yval), env = list(yval = y))) if (freq) { plot_call <- reduce_plot_call( plot_call, - quote(geom_bar()), - quote(ylab("Frequency")) + quote(ggplot2::geom_bar()), + quote(ggplot2::ylab("Frequency")) ) } else { plot_call <- reduce_plot_call( plot_call, - quote(geom_bar(aes(y = after_stat(prop), group = 1))), - quote(ylab("Fraction")) + quote(ggplot2::geom_bar(ggplot2::aes(y = ggplot2::after_stat(prop), group = 1))), + quote(ggplot2::ylab("Fraction")) ) } # Numeric Plots } else if (x_class == "numeric" && y_class == "numeric") { plot_call <- reduce_plot_call( plot_call, - substitute(aes(x = xval, y = yval), env = list(xval = x, yval = y)), + substitute(ggplot2::aes(x = xval, y = yval), env = list(xval = x, yval = y)), # pch = 21 for consistent coloring behaviour b/w all geoms (outline and fill properties) `if`( !is.null(size), substitute( - geom_point(alpha = alphaval, size = sizeval, pch = 21), + ggplot2::geom_point(alpha = alphaval, size = sizeval, pch = 21), env = list(alphaval = alpha, sizeval = size) ), substitute( - geom_point(alpha = alphaval, pch = 21), + ggplot2::geom_point(alpha = alphaval, pch = 21), env = list(alphaval = alpha) ) ) @@ -946,8 +951,8 @@ bivariate_ggplot_call <- function(x_class, } else if ((x_class == "numeric" && y_class == "factor") || (x_class == "factor" && y_class == "numeric")) { plot_call <- reduce_plot_call( plot_call, - substitute(aes(x = xval, y = yval), env = list(xval = x, yval = y)), - quote(geom_boxplot()) + substitute(ggplot2::aes(x = xval, y = yval), env = list(xval = x, yval = y)), + quote(ggplot2::geom_boxplot()) ) # Factor and character plots } else if (x_class == "factor" && y_class == "factor") { @@ -976,7 +981,7 @@ bivariate_ggplot_call <- function(x_class, dev_ggplot2_args <- teal.widgets::ggplot2_args(labs = labs_base) if (rotate_xaxis_labels) { - dev_ggplot2_args$theme <- list(axis.text.x = quote(element_text(angle = 45, hjust = 1))) + dev_ggplot2_args$theme <- list(axis.text.x = quote(ggplot2::element_text(angle = 45, hjust = 1))) } all_ggplot2_args <- teal.widgets::resolve_ggplot2_args( @@ -1042,7 +1047,7 @@ coloring_ggplot_call <- function(colour, !identical(size, character(0)) ) { substitute( - expr = aes(colour = colour_name, fill = fill_name, size = size_name), + expr = ggplot2::aes(colour = colour_name, fill = fill_name, size = size_name), env = list(colour_name = as.name(colour), fill_name = as.name(fill), size_name = as.name(size)) ) } else if ( @@ -1051,14 +1056,14 @@ coloring_ggplot_call <- function(colour, is_point && identical(size, character(0)) ) { - substitute(expr = aes(fill = fill_name), env = list(fill_name = as.name(fill))) + substitute(expr = ggplot2::aes(fill = fill_name), env = list(fill_name = as.name(fill))) } else if ( !identical(colour, character(0)) && !identical(fill, character(0)) && (!is_point || identical(size, character(0))) ) { substitute( - expr = aes(colour = colour_name, fill = fill_name), + expr = ggplot2::aes(colour = colour_name, fill = fill_name), env = list(colour_name = as.name(colour), fill_name = as.name(fill)) ) } else if ( @@ -1066,20 +1071,20 @@ coloring_ggplot_call <- function(colour, identical(fill, character(0)) && (!is_point || identical(size, character(0))) ) { - substitute(expr = aes(colour = colour_name), env = list(colour_name = as.name(colour))) + substitute(expr = ggplot2::aes(colour = colour_name), env = list(colour_name = as.name(colour))) } else if ( identical(colour, character(0)) && !identical(fill, character(0)) && (!is_point || identical(size, character(0))) ) { - substitute(expr = aes(fill = fill_name), env = list(fill_name = as.name(fill))) + substitute(expr = ggplot2::aes(fill = fill_name), env = list(fill_name = as.name(fill))) } else if ( identical(colour, character(0)) && identical(fill, character(0)) && is_point && !identical(size, character(0)) ) { - substitute(expr = aes(size = size_name), env = list(size_name = as.name(size))) + substitute(expr = ggplot2::aes(size = size_name), env = list(size_name = as.name(size))) } else if ( !identical(colour, character(0)) && identical(fill, character(0)) && @@ -1087,7 +1092,7 @@ coloring_ggplot_call <- function(colour, !identical(size, character(0)) ) { substitute( - expr = aes(colour = colour_name, size = size_name), + expr = ggplot2::aes(colour = colour_name, size = size_name), env = list(colour_name = as.name(colour), size_name = as.name(size)) ) } else if ( @@ -1097,7 +1102,7 @@ coloring_ggplot_call <- function(colour, !identical(size, character(0)) ) { substitute( - expr = aes(colour = colour_name, fill = fill_name, size = size_name), + expr = ggplot2::aes(colour = colour_name, fill = fill_name, size = size_name), env = list(colour_name = as.name(fill), fill_name = as.name(fill), size_name = as.name(size)) ) } else { diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index 6c9331277..7dce15bd7 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -539,9 +539,14 @@ srv_distribution <- function(id, datasets = data ) + qenv <- teal.code::eval_code( + data(), + 'library("ggplot2");library("rlistings");library("dplyr")' # nolint quotes + ) + anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -658,6 +663,7 @@ srv_distribution <- function(id, "Group by variable must be `factor`, `character`, or `integer`" ) ) + qenv <- teal.code::eval_code(qenv, 'library("forcats")') # nolint quotes qenv <- teal.code::eval_code( qenv, substitute( @@ -674,6 +680,8 @@ srv_distribution <- function(id, "Stratify by variable must be `factor`, `character`, or `integer`" ) ) + + qenv <- teal.code::eval_code(qenv, 'library("forcats")') # nolint quotes qenv <- teal.code::eval_code( qenv, substitute( @@ -796,9 +804,9 @@ srv_distribution <- function(id, plot_call <- if (length(s_var) == 0 && length(g_var) == 0) { substitute( - expr = ggplot(ANL, aes(dist_var_name)) + - geom_histogram( - position = "identity", aes(y = after_stat(m_type)), bins = bins_var, alpha = 0.3 + expr = ggplot2::ggplot(ANL, ggplot2::aes(dist_var_name)) + + ggplot2::geom_histogram( + position = "identity", ggplot2::aes(y = ggplot2::after_stat(m_type)), bins = bins_var, alpha = 0.3 ), env = list( m_type = as.name(m_type), bins_var = bins_var, dist_var_name = as.name(dist_var) @@ -806,9 +814,10 @@ srv_distribution <- function(id, ) } else if (length(s_var) != 0 && length(g_var) == 0) { substitute( - expr = ggplot(ANL, aes(dist_var_name, col = s_var_name)) + - geom_histogram( - position = "identity", aes(y = after_stat(m_type), fill = s_var), bins = bins_var, alpha = 0.3 + expr = ggplot2::ggplot(ANL, aes(dist_var_name, col = s_var_name)) + + ggplot2::geom_histogram( + position = "identity", ggplot2::aes(y = ggplot2::after_stat(m_type), fill = s_var), + bins = bins_var, alpha = 0.3 ), env = list( m_type = as.name(m_type), @@ -821,11 +830,11 @@ srv_distribution <- function(id, } else if (length(s_var) == 0 && length(g_var) != 0) { req(scales_type) substitute( - expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes(dist_var_name)) + - geom_histogram( - position = "identity", aes(y = after_stat(m_type)), bins = bins_var, alpha = 0.3 + expr = ggplot2::ggplot(ANL[ANL[[g_var]] != "NA", ], ggplot2::aes(dist_var_name)) + + ggplot2::geom_histogram( + position = "identity", ggplot2::aes(y = ggplot2::after_stat(m_type)), bins = bins_var, alpha = 0.3 ) + - facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), + ggplot2::facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), env = list( m_type = as.name(m_type), bins_var = bins_var, @@ -838,12 +847,12 @@ srv_distribution <- function(id, } else { req(scales_type) substitute( - expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes(dist_var_name, col = s_var_name)) + - geom_histogram( + expr = ggplot2::ggplot(ANL[ANL[[g_var]] != "NA", ], ggplot2::aes(dist_var_name, col = s_var_name)) + + ggplot2::geom_histogram( position = "identity", - aes(y = after_stat(m_type), fill = s_var), bins = bins_var, alpha = 0.3 + ggplot2::aes(y = ggplot2::after_stat(m_type), fill = s_var), bins = bins_var, alpha = 0.3 ) + - facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), + ggplot2::facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), env = list( m_type = as.name(m_type), bins_var = bins_var, @@ -860,8 +869,8 @@ srv_distribution <- function(id, if (add_dens_var) { plot_call <- substitute( expr = plot_call + - stat_density( - aes(y = after_stat(const * m_type2)), + ggplot2::stat_density( + ggplot2::aes(y = ggplot2::after_stat(const * m_type2)), geom = "line", position = "identity", alpha = 0.5, @@ -882,6 +891,7 @@ srv_distribution <- function(id, } if (length(t_dist) != 0 && main_type_var == "Density" && length(g_var) == 0 && length(s_var) == 0) { + qenv <- teal.code::eval_code(qenv, 'library("ggpp")') # nolint quotes qenv <- teal.code::eval_code( qenv, substitute( @@ -895,7 +905,7 @@ srv_distribution <- function(id, plot_call <- substitute( expr = plot_call + ggpp::geom_table_npc( data = data, - aes(npcx = x, npcy = y, label = label), + ggplot2::aes(npcx = x, npcy = y, label = label), hjust = 0, vjust = 1, size = 4 ), env = list(plot_call = plot_call, data = datas, label = label) @@ -916,13 +926,13 @@ srv_distribution <- function(id, plot_call <- substitute( expr = plot_call + stat_function( data = data.frame(x = range(ANL[[dist_var]]), color = mapped_dist), - aes(x, color = color), + ggplot2::aes(x, color = color), fun = mapped_dist_name, n = ndensity, size = 2, args = params ) + - scale_color_manual(values = stats::setNames("blue", mapped_dist), aesthetics = "color"), + ggplot2::scale_color_manual(values = stats::setNames("blue", mapped_dist), aesthetics = "color"), env = list( plot_call = plot_call, dist_var = dist_var, @@ -981,18 +991,18 @@ srv_distribution <- function(id, plot_call <- if (length(s_var) == 0 && length(g_var) == 0) { substitute( - expr = ggplot(ANL, aes_string(sample = dist_var)), + expr = ggplot2::ggplot(ANL, ggplot2::aes_string(sample = dist_var)), env = list(dist_var = dist_var) ) } else if (length(s_var) != 0 && length(g_var) == 0) { substitute( - expr = ggplot(ANL, aes_string(sample = dist_var, color = s_var)), + expr = ggplot2::ggplot(ANL, ggplot2::aes_string(sample = dist_var, color = s_var)), env = list(dist_var = dist_var, s_var = s_var) ) } else if (length(s_var) == 0 && length(g_var) != 0) { substitute( - expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes_string(sample = dist_var)) + - facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), + expr = ggplot2::ggplot(ANL[ANL[[g_var]] != "NA", ], ggplot2::aes_string(sample = dist_var)) + + ggplot2::facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), env = list( dist_var = dist_var, g_var = g_var, @@ -1002,8 +1012,8 @@ srv_distribution <- function(id, ) } else { substitute( - expr = ggplot(ANL[ANL[[g_var]] != "NA", ], aes_string(sample = dist_var, color = s_var)) + - facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), + expr = ggplot2::ggplot(ANL[ANL[[g_var]] != "NA", ], ggplot2::aes_string(sample = dist_var, color = s_var)) + + ggplot2::facet_wrap(~g_var_name, ncol = 1, scales = scales_raw), env = list( dist_var = dist_var, g_var = g_var, @@ -1021,11 +1031,12 @@ srv_distribution <- function(id, plot_call <- substitute( expr = plot_call + - stat_qq(distribution = mapped_dist, dparams = params), + ggplot2::stat_qq(distribution = mapped_dist, dparams = params), env = list(plot_call = plot_call, mapped_dist = as.name(unname(map_dist[t_dist]))) ) if (length(t_dist) != 0 && length(g_var) == 0 && length(s_var) == 0) { + qenv <- teal.code::eval_code(qenv, 'library("ggpp")') # nolint quotes qenv <- teal.code::eval_code( qenv, substitute( @@ -1040,7 +1051,7 @@ srv_distribution <- function(id, expr = plot_call + ggpp::geom_table_npc( data = data, - aes(npcx = x, npcy = y, label = label), + ggplot2::aes(npcx = x, npcy = y, label = label), hjust = 0, vjust = 1, size = 4 @@ -1056,7 +1067,7 @@ srv_distribution <- function(id, if (isTRUE(input$qq_line)) { plot_call <- substitute( expr = plot_call + - stat_qq_line(distribution = mapped_dist, dparams = params), + ggplot2::stat_qq_line(distribution = mapped_dist, dparams = params), env = list(plot_call = plot_call, mapped_dist = as.name(unname(map_dist[t_dist]))) ) } @@ -1220,6 +1231,7 @@ srv_distribution <- function(id, qenv <- common_q() if (length(s_var) == 0 && length(g_var) == 0) { + qenv <- teal.code::eval_code(qenv, 'library("generics")') # nolint quotes qenv <- teal.code::eval_code( qenv, substitute( @@ -1233,6 +1245,7 @@ srv_distribution <- function(id, ) ) } else { + qenv <- teal.code::eval_code(qenv, 'library("tidyr")') # nolint quotes qenv <- teal.code::eval_code( qenv, substitute( diff --git a/R/tm_g_response.R b/R/tm_g_response.R index 8c110f31b..ba26b62ec 100644 --- a/R/tm_g_response.R +++ b/R/tm_g_response.R @@ -390,9 +390,14 @@ srv_g_response <- function(id, datasets = data ) + qenv <- teal.code::eval_code( + data(), + 'library("ggplot2");library("dplyr")' # nolint quotes + ) + anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -476,8 +481,8 @@ srv_g_response <- function(id, ) plot_call <- substitute( - expr = ggplot(ANL2, aes(x = x_cl, y = ns)) + - geom_bar(aes(fill = resp_cl), stat = "identity", position = arg_position), + expr = ggplot2::ggplot(ANL2, ggplot2::aes(x = x_cl, y = ns)) + + ggplot2::geom_bar(ggplot2::aes(fill = resp_cl), stat = "identity", position = arg_position), env = list( x_cl = x_cl, resp_cl = resp_cl, @@ -487,7 +492,7 @@ srv_g_response <- function(id, if (!freq) { plot_call <- substitute( - plot_call + expand_limits(y = c(0, 1.1)), + plot_call + ggplot2::expand_limits(y = c(0, 1.1)), env = list(plot_call = plot_call) ) } @@ -495,16 +500,16 @@ srv_g_response <- function(id, if (counts) { plot_call <- substitute( expr = plot_call + - geom_text( + ggplot2::geom_text( data = ANL2, - aes(label = ns, x = x_cl, y = ns, group = resp_cl), + ggplot2::aes(label = ns, x = x_cl, y = ns, group = resp_cl), col = "white", vjust = "middle", hjust = "middle", position = position_anl2_value ) + - geom_text( - data = ANL3, aes(label = ns, x = x_cl, y = anl3_y), + ggplot2::geom_text( + data = ANL3, ggplot2::aes(label = ns, x = x_cl, y = anl3_y), hjust = hjust_value, vjust = vjust_value, position = position_anl3_value @@ -542,7 +547,7 @@ srv_g_response <- function(id, ) if (rotate_xaxis_labels) { - dev_ggplot2_args$theme[["axis.text.x"]] <- quote(element_text(angle = 45, hjust = 1)) + dev_ggplot2_args$theme[["axis.text.x"]] <- quote(ggplot2::element_text(angle = 45, hjust = 1)) } all_ggplot2_args <- teal.widgets::resolve_ggplot2_args( diff --git a/R/tm_g_scatterplot.R b/R/tm_g_scatterplot.R index 1983552de..9c447a6dd 100644 --- a/R/tm_g_scatterplot.R +++ b/R/tm_g_scatterplot.R @@ -586,10 +586,11 @@ srv_g_scatterplot <- function(id, datasets = data, merge_function = "dplyr::inner_join" ) + qenv <- teal.code::eval_code(data(), 'library("ggplot2");library("dplyr")') # nolint quotes anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) %>% teal.code::eval_code(quote(ANL)) # used to display table when running show-r-code code }) @@ -798,7 +799,7 @@ srv_g_scatterplot <- function(id, "ANL" } - plot_call <- substitute(expr = pre_pro_anl %>% ggplot(), env = list(pre_pro_anl = str2lang(pre_pro_anl))) + plot_call <- substitute(expr = pre_pro_anl %>% ggplot2::ggplot(), env = list(pre_pro_anl = str2lang(pre_pro_anl))) plot_call <- if (length(color_by_var) == 0) { substitute( @@ -966,7 +967,7 @@ srv_g_scatterplot <- function(id, ) if (rotate_xaxis_labels) { - dev_ggplot2_args$theme[["axis.text.x"]] <- quote(element_text(angle = 45, hjust = 1)) + dev_ggplot2_args$theme[["axis.text.x"]] <- quote(ggplot2::element_text(angle = 45, hjust = 1)) } all_ggplot2_args <- teal.widgets::resolve_ggplot2_args( diff --git a/R/tm_g_scatterplotmatrix.R b/R/tm_g_scatterplotmatrix.R index 4d289eb47..2fc55042b 100644 --- a/R/tm_g_scatterplotmatrix.R +++ b/R/tm_g_scatterplotmatrix.R @@ -106,7 +106,7 @@ #' label = "Select variable:", #' vars = "country_id", #' choices = value_choices(data[["sales"]], "country_id"), -#' selected = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"), +#' selected = c("DE", "FR", "IT", "PT", "GR", "NL", "BE", "LU", "AT"), #' multiple = TRUE #' ), #' select = select_spec( @@ -329,8 +329,8 @@ srv_g_scatterplotmatrix <- function(id, anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% - teal.code::eval_code(as.expression(anl_merged_input()$expr)) + qenv <- teal.code::eval_code(data(), 'library("dplyr");library("lattice")') # nolint quotes + teal.code::eval_code(qenv, as.expression(anl_merged_input()$expr)) }) merged <- list( @@ -366,6 +366,7 @@ srv_g_scatterplotmatrix <- function(id, # check character columns. If any, then those are converted to factors check_char <- vapply(ANL[, cols_names], is.character, logical(1)) + qenv <- teal.code::eval_code(qenv, 'library("dplyr")') # nolint quotes if (any(check_char)) { qenv <- teal.code::eval_code( qenv, diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index 0b789b066..aa1d73e5f 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -532,10 +532,13 @@ srv_missing_data <- function(id, group_var <- input$group_by_var anl <- data_r() + qenv <- teal.code::eval_code(data(), { + 'library("dplyr");library("ggplot2");library("tidyr");library("gridExtra")' # nolint quotes + }) qenv <- if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl)) { teal.code::eval_code( - data(), + qenv, substitute( expr = ANL <- anl_name[, selected_vars, drop = FALSE], env = list(anl_name = as.name(dataname), selected_vars = selected_vars()) @@ -543,7 +546,7 @@ srv_missing_data <- function(id, ) } else { teal.code::eval_code( - data(), + qenv, substitute(expr = ANL <- anl_name, env = list(anl_name = as.name(dataname))) ) } @@ -787,7 +790,7 @@ srv_missing_data <- function(id, dev_ggplot2_args <- teal.widgets::ggplot2_args( labs = list(x = "Variable", y = "Missing observations"), - theme = list(legend.position = "bottom", axis.text.x = quote(element_text(angle = 45, hjust = 1))) + theme = list(legend.position = "bottom", axis.text.x = quote(ggplot2::element_text(angle = 45, hjust = 1))) ) all_ggplot2_args <- teal.widgets::resolve_ggplot2_args( @@ -805,32 +808,32 @@ srv_missing_data <- function(id, qenv, substitute( summary_plot_top <- summary_plot_obs %>% - ggplot() + - aes( + ggplot2::ggplot() + + ggplot2::aes( x = factor(create_cols_labels(col), levels = x_levels), y = n_pct, fill = isna ) + - geom_bar(position = "fill", stat = "identity") + - scale_fill_manual( + ggplot2::geom_bar(position = "fill", stat = "identity") + + ggplot2::scale_fill_manual( name = "", values = c("grey90", c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]), labels = c("Present", "Missing") ) + - scale_y_continuous( + ggplot2::scale_y_continuous( labels = scales::percent_format(), breaks = seq(0, 1, by = 0.1), expand = c(0, 0) ) + - geom_text( - aes(label = ifelse(isna == TRUE, sprintf("%d [%.02f%%]", n, n_pct), ""), y = 1), + ggplot2::geom_text( + ggplot2::aes(label = ifelse(isna == TRUE, sprintf("%d [%.02f%%]", n, n_pct), ""), y = 1), hjust = 1, color = "black" ) + labs + ggthemes + themes + - coord_flip(), + ggplot2::coord_flip(), env = list( labs = parsed_ggplot2_args$labs, themes = parsed_ggplot2_args$theme, @@ -867,8 +870,8 @@ srv_missing_data <- function(id, labs = list(x = "", y = "Missing patients"), theme = list( legend.position = "bottom", - axis.text.x = quote(element_text(angle = 45, hjust = 1)), - axis.text.y = quote(element_blank()) + axis.text.x = quote(ggplot2::element_text(angle = 45, hjust = 1)), + axis.text.y = quote(ggplot2::element_blank()) ) ) @@ -887,32 +890,32 @@ srv_missing_data <- function(id, qenv, substitute( summary_plot_bottom <- summary_plot_patients %>% - ggplot() + - aes_( + ggplot2::ggplot() + + ggplot2::aes_( x = ~ factor(create_cols_labels(col), levels = x_levels), y = ~n_pct, fill = ~isna ) + - geom_bar(alpha = 1, stat = "identity", position = "fill") + - scale_y_continuous( + ggplot2::geom_bar(alpha = 1, stat = "identity", position = "fill") + + ggplot2::scale_y_continuous( labels = scales::percent_format(), breaks = seq(0, 1, by = 0.1), expand = c(0, 0) ) + - scale_fill_manual( + ggplot2::scale_fill_manual( name = "", values = c("grey90", c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]), labels = c("Present", "Missing") ) + - geom_text( - aes(label = ifelse(isna == TRUE, sprintf("%d [%.02f%%]", n, n_pct), ""), y = 1), + ggplot2::geom_text( + ggplot2::aes(label = ifelse(isna == TRUE, sprintf("%d [%.02f%%]", n, n_pct), ""), y = 1), hjust = 1, color = "black" ) + labs + ggthemes + themes + - coord_flip(), + ggplot2::coord_flip(), env = list( labs = parsed_ggplot2_args$labs, themes = parsed_ggplot2_args$theme, @@ -924,14 +927,14 @@ srv_missing_data <- function(id, if (isTRUE(input$if_patients_plot)) { within(qenv, { - g1 <- ggplotGrob(summary_plot_top) - g2 <- ggplotGrob(summary_plot_bottom) + g1 <- ggplot2::ggplotGrob(summary_plot_top) + g2 <- ggplot2::ggplotGrob(summary_plot_bottom) summary_plot <- gridExtra::gtable_cbind(g1, g2, size = "first") summary_plot$heights <- grid::unit.pmax(g1$heights, g2$heights) }) } else { within(qenv, { - g1 <- ggplotGrob(summary_plot_top) + g1 <- ggplot2::ggplotGrob(summary_plot_top) summary_plot <- g1 }) } @@ -979,7 +982,7 @@ srv_missing_data <- function(id, labs = list(x = "", y = ""), theme = list( legend.position = "bottom", - axis.text.x = quote(element_blank()) + axis.text.x = quote(ggplot2::element_blank()) ) ) @@ -998,9 +1001,9 @@ srv_missing_data <- function(id, labs = list(x = "", y = ""), theme = list( legend.position = "bottom", - axis.text.x = quote(element_blank()), - axis.ticks = quote(element_blank()), - panel.grid.major = quote(element_blank()) + axis.text.x = quote(ggplot2::element_blank()), + axis.ticks = quote(ggplot2::element_blank()), + panel.grid.major = quote(ggplot2::element_blank()) ) ) @@ -1022,14 +1025,14 @@ srv_missing_data <- function(id, combination_plot_top <- data_combination_plot_cutoff %>% dplyr::select(id, n) %>% dplyr::distinct() %>% - ggplot(aes(x = id, y = n)) + - geom_bar(stat = "identity", fill = c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]) + - geom_text( - aes(label = n), - position = position_dodge(width = 0.9), + ggplot2::ggplot(ggplot2::aes(x = id, y = n)) + + ggplot2::geom_bar(stat = "identity", fill = c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]) + + ggplot2::geom_text( + ggplot2::aes(label = n), + position = ggplot2::position_dodge(width = 0.9), vjust = -0.25 ) + - ylim(c(0, max(data_combination_plot_cutoff$n) * 1.5)) + + ggplot2::ylim(c(0, max(data_combination_plot_cutoff$n) * 1.5)) + labs1 + ggthemes1 + themes1 @@ -1037,17 +1040,17 @@ srv_missing_data <- function(id, graph_number_rows <- length(unique(data_combination_plot_cutoff$id)) graph_number_cols <- nrow(data_combination_plot_cutoff) / graph_number_rows - combination_plot_bottom <- data_combination_plot_cutoff %>% ggplot() + - aes(x = create_cols_labels(key), y = id - 0.5, fill = value) + - geom_tile(alpha = 0.85, height = 0.95) + - scale_fill_manual( + combination_plot_bottom <- data_combination_plot_cutoff %>% ggplot2::ggplot() + + ggplot2::aes(x = create_cols_labels(key), y = id - 0.5, fill = value) + + ggplot2::geom_tile(alpha = 0.85, height = 0.95) + + ggplot2::scale_fill_manual( name = "", values = c("grey90", c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]), labels = c("Present", "Missing") ) + - geom_hline(yintercept = seq_len(1 + graph_number_rows) - 1) + - geom_vline(xintercept = seq_len(1 + graph_number_cols) - 0.5, linetype = "dotted") + - coord_flip() + + ggplot2::geom_hline(yintercept = seq_len(1 + graph_number_rows) - 1) + + ggplot2::geom_vline(xintercept = seq_len(1 + graph_number_cols) - 0.5, linetype = "dotted") + + ggplot2::coord_flip() + labs2 + ggthemes2 + themes2 @@ -1064,8 +1067,8 @@ srv_missing_data <- function(id, ) within(qenv, { - g1 <- ggplotGrob(combination_plot_top) - g2 <- ggplotGrob(combination_plot_bottom) + g1 <- ggplot2::ggplotGrob(combination_plot_top) + g2 <- ggplot2::ggplotGrob(combination_plot_bottom) combination_plot <- gridExtra::gtable_rbind(g1, g2, size = "last") combination_plot$heights[7] <- grid::unit(0.2, "null") # rescale to get the bar chart smaller @@ -1109,8 +1112,12 @@ srv_missing_data <- function(id, } qenv <- if (!is.null(group_var)) { - teal.code::eval_code( + common_code_libraries_q <- teal.code::eval_code( common_code_q(), + 'library("forcats");library("glue");library("rlistings")' # nolint quotes + ) + teal.code::eval_code( + common_code_libraries_q, substitute( expr = { summary_data <- ANL %>% @@ -1158,7 +1165,7 @@ srv_missing_data <- function(id, dev_ggplot2_args <- teal.widgets::ggplot2_args( labs = list(x = "", y = ""), - theme = list(legend.position = "bottom", axis.text.x = quote(element_blank())) + theme = list(legend.position = "bottom", axis.text.x = quote(ggplot2::element_blank())) ) all_ggplot2_args <- teal.widgets::resolve_ggplot2_args( @@ -1235,20 +1242,20 @@ srv_missing_data <- function(id, teal.code::eval_code( substitute( expr = { - by_subject_plot <- ggplot(summary_plot_patients, aes( + by_subject_plot <- ggplot2::ggplot(summary_plot_patients, ggplot2::aes( x = factor(id, levels = order_subjects), y = factor(col, levels = ordered_columns[["column"]]), fill = isna )) + - geom_raster() + - annotate( + ggplot2::geom_raster() + + ggplot2::annotate( "text", x = length(order_subjects), y = seq_len(nrow(ordered_columns)), hjust = 1, label = sprintf("%d [%.02f%%]", ordered_columns[["na_count"]], ordered_columns[["na_percent"]]) ) + - scale_fill_manual( + ggplot2::scale_fill_manual( name = "", values = c("grey90", c(getOption("ggplot2.discrete.colour")[2], "#ff2951ff")[1]), labels = c("Present", "Missing (at least one)") diff --git a/R/tm_outliers.R b/R/tm_outliers.R index fcd8ac75c..f618e4b14 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -439,7 +439,13 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + teal.code::eval_code( + data(), + paste0( + 'library("dplyr");library("tidyr");', # nolint quotes + 'library("tibble");library("ggplot2");library("rlistings")' + ) + ) %>% # nolint quotes teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -751,9 +757,9 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, plot_call <- quote(ANL %>% ggplot()) plot_call <- if (input$boxplot_alts == "Box plot") { - substitute(expr = plot_call + geom_boxplot(outlier.shape = NA), env = list(plot_call = plot_call)) + substitute(expr = plot_call + ggplot2::geom_boxplot(outlier.shape = NA), env = list(plot_call = plot_call)) } else if (input$boxplot_alts == "Violin plot") { - substitute(expr = plot_call + geom_violin(), env = list(plot_call = plot_call)) + substitute(expr = plot_call + ggplot2::geom_violin(), env = list(plot_call = plot_call)) } else { NULL } @@ -761,15 +767,15 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, plot_call <- if (identical(categorical_var, character(0)) || is.null(categorical_var)) { inner_call <- substitute( expr = plot_call + - aes(x = "Entire dataset", y = outlier_var_name) + - scale_x_discrete(), + ggplot2::aes(x = "Entire dataset", y = outlier_var_name) + + ggplot2::scale_x_discrete(), env = list(plot_call = plot_call, outlier_var_name = as.name(outlier_var)) ) if (nrow(ANL_OUTLIER) > 0) { substitute( - expr = inner_call + geom_point( + expr = inner_call + ggplot2::geom_point( data = ANL_OUTLIER, - aes(x = "Entire dataset", y = outlier_var_name, color = is_outlier_selected) + ggplot2::aes(x = "Entire dataset", y = outlier_var_name, color = is_outlier_selected) ), env = list(inner_call = inner_call, outlier_var_name = as.name(outlier_var)) ) @@ -779,12 +785,12 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, } else { substitute( expr = plot_call + - aes(y = outlier_var_name, x = reorder(categorical_var_name, order)) + - xlab(categorical_var) + - scale_x_discrete() + - geom_point( + ggplot2::aes(y = outlier_var_name, x = reorder(categorical_var_name, order)) + + ggplot2::xlab(categorical_var) + + ggplot2::scale_x_discrete() + + ggplot2::geom_point( data = ANL_OUTLIER, - aes(x = as.factor(categorical_var_name), y = outlier_var_name, color = is_outlier_selected) + ggplot2::aes(x = as.factor(categorical_var_name), y = outlier_var_name, color = is_outlier_selected) ), env = list( plot_call = plot_call, @@ -815,7 +821,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, common_code_q(), substitute( expr = box_plot <- plot_call + - scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")) + + ggplot2::scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")) + labs + ggthemes + themes, env = list( plot_call = plot_call, @@ -840,10 +846,10 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, # plot plot_call <- substitute( expr = ANL %>% - ggplot(aes(x = outlier_var_name)) + - geom_density() + - geom_rug(data = ANL_OUTLIER, aes(x = outlier_var_name, color = is_outlier_selected)) + - scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")), + ggplot2::ggplot(ggplot2::aes(x = outlier_var_name)) + + ggplot2::geom_density() + + ggplot2::geom_rug(data = ANL_OUTLIER, ggplot2::aes(x = outlier_var_name, color = is_outlier_selected)) + + ggplot2::scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")), env = list(outlier_var_name = as.name(outlier_var)) ) @@ -851,7 +857,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, substitute(expr = plot_call, env = list(plot_call = plot_call)) } else { substitute( - expr = plot_call + facet_grid(~ reorder(categorical_var_name, order)), + expr = plot_call + ggplot2::facet_grid(~ reorder(categorical_var_name, order)), env = list(plot_call = plot_call, categorical_var_name = as.name(categorical_var)) ) } @@ -901,8 +907,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, # plot plot_call <- substitute( - expr = ANL %>% ggplot(aes(x = outlier_var_name)) + - stat_ecdf(), + expr = ANL %>% ggplot2::ggplot(ggplot2::aes(x = outlier_var_name)) + + ggplot2::stat_ecdf(), env = list(outlier_var_name = as.name(outlier_var)) ) if (length(categorical_var) == 0) { @@ -952,7 +958,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ) ) plot_call <- substitute( - expr = plot_call + facet_grid(~ reorder(categorical_var_name, order)), + expr = plot_call + ggplot2::facet_grid(~ reorder(categorical_var_name, order)), env = list(plot_call = plot_call, categorical_var_name = as.name(categorical_var)) ) } @@ -977,8 +983,11 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, qenv, substitute( expr = cumulative_plot <- plot_call + - geom_point(data = outlier_points, aes(x = outlier_var_name, y = y, color = is_outlier_selected)) + - scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")) + + ggplot2::geom_point( + data = outlier_points, + ggplot2::aes(x = outlier_var_name, y = y, color = is_outlier_selected) + ) + + ggplot2::scale_color_manual(values = c("TRUE" = "red", "FALSE" = "black")) + labs + ggthemes + themes, env = list( plot_call = plot_call, diff --git a/R/tm_t_crosstable.R b/R/tm_t_crosstable.R index f251ec31e..ea55c7e29 100644 --- a/R/tm_t_crosstable.R +++ b/R/tm_t_crosstable.R @@ -311,10 +311,10 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, selector_list = selector_list, merge_function = merge_function ) - + qenv <- teal.code::eval_code(data(), 'library("rtables");library("tern");library("dplyr")') # nolint quotes anl_merged_q <- reactive({ req(anl_merged_input()) - data() %>% + qenv %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) diff --git a/R/tm_variable_browser.R b/R/tm_variable_browser.R index 720b73d76..b8ec4bae4 100644 --- a/R/tm_variable_browser.R +++ b/R/tm_variable_browser.R @@ -713,11 +713,11 @@ plot_var_summary <- function(var, var <- stringr::str_wrap(var, width = wrap_character) } var <- if (isTRUE(remove_NA_hist)) as.vector(stats::na.omit(var)) else var - ggplot(data.frame(var), aes(x = forcats::fct_infreq(as.factor(var)))) + - geom_bar( + ggplot2::ggplot(data.frame(var), ggplot2::aes(x = forcats::fct_infreq(as.factor(var)))) + + ggplot2::geom_bar( stat = "count", aes(fill = ifelse(is.na(var), "withcolor", "")), show.legend = FALSE ) + - scale_fill_manual(values = c("gray50", "tan")) + ggplot2::scale_fill_manual(values = c("gray50", "tan")) } } else if (is.numeric(var)) { validate(need(any(!is.na(var)), "No data left to visualize.")) @@ -729,8 +729,8 @@ plot_var_summary <- function(var, if (numeric_as_factor) { var <- factor(var) - ggplot(NULL, aes(x = var)) + - geom_histogram(stat = "count") + ggplot2::ggplot(NULL, ggplot2::aes(x = var)) + + ggplot2::geom_histogram(stat = "count") } else { # remove outliers if (outlier_definition != 0) { @@ -749,10 +749,10 @@ plot_var_summary <- function(var, } ## histogram binwidth <- get_bin_width(var) - p <- ggplot(data = data.frame(var = var), aes(x = var, y = after_stat(count))) + - geom_histogram(binwidth = binwidth) + - scale_y_continuous( - sec.axis = sec_axis( + p <- ggplot2::ggplot(data = data.frame(var = var), ggplot2::aes(x = var, y = ggplot2::after_stat(count))) + + ggplot2::geom_histogram(binwidth = binwidth) + + ggplot2::scale_y_continuous( + sec.axis = ggplot2::sec_axis( trans = ~ . / nrow(data.frame(var = var)), labels = scales::percent, name = "proportion (in %)" @@ -760,11 +760,11 @@ plot_var_summary <- function(var, ) if (display_density) { - p <- p + geom_density(aes(y = after_stat(count * binwidth))) + p <- p + ggplot2::geom_density(ggplot2::aes(y = ggplot2::after_stat(count * binwidth))) } if (outlier_definition != 0) { - p <- p + annotate( + p <- p + ggplot2::annotate( geom = "text", label = outlier_text, x = Inf, y = Inf, @@ -779,8 +779,8 @@ plot_var_summary <- function(var, } else if (inherits(var, "Date") || inherits(var, "POSIXct") || inherits(var, "POSIXlt")) { var_num <- as.numeric(var) binwidth <- get_bin_width(var_num, 1) - p <- ggplot(data = data.frame(var = var), aes(x = var, y = after_stat(count))) + - geom_histogram(binwidth = binwidth) + p <- ggplot2::ggplot(data = data.frame(var = var), ggplot2::aes(x = var, y = ggplot2::after_stat(count))) + + ggplot2::geom_histogram(binwidth = binwidth) } else { grid::textGrob( paste(strwrap( @@ -818,7 +818,7 @@ plot_var_summary <- function(var, theme = do.call("theme", all_ggplot2_args$theme) ) } - plot_main <- ggplotGrob(plot_main) + plot_main <- ggplot2::ggplotGrob(plot_main) } grid::grid.draw(plot_main) diff --git a/R/utils.R b/R/utils.R index 50d747f6c..44da1c3eb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -90,10 +90,10 @@ add_facet_labels <- function(p, xfacet_label = NULL, yfacet_label = NULL) { checkmate::assert_character(xfacet_label, null.ok = TRUE, min.len = 1) checkmate::assert_character(yfacet_label, null.ok = TRUE, min.len = 1) if (is.null(xfacet_label) && is.null(yfacet_label)) { - return(ggplotGrob(p)) + return(ggplot2::ggplotGrob(p)) } grid::grid.grabExpr({ - g <- ggplotGrob(p) + g <- ggplot2::ggplotGrob(p) # we are going to replace these, so we make sure they have nothing in them checkmate::assert_class(g$grobs[[grep("xlab-t", g$layout$name, fixed = TRUE)]], "zeroGrob") diff --git a/man/tm_g_scatterplotmatrix.Rd b/man/tm_g_scatterplotmatrix.Rd index 9bd448f7d..32530ca8a 100644 --- a/man/tm_g_scatterplotmatrix.Rd +++ b/man/tm_g_scatterplotmatrix.Rd @@ -148,7 +148,7 @@ app <- init( label = "Select variable:", vars = "country_id", choices = value_choices(data[["sales"]], "country_id"), - selected = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"), + selected = c("DE", "FR", "IT", "PT", "GR", "NL", "BE", "LU", "AT"), multiple = TRUE ), select = select_spec( @@ -223,8 +223,8 @@ if (interactive()) { \section{Examples in Shinylive}{ \describe{ \item{example-1}{ - \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6usTmpIy0YnH+GRgmzPDsFZW6tPy6ALxVHWAAIq54ugpgAGJYk6WTAJJ2cxNgzgDKK5MACsvjkwDis-tgAHIAMltgAEJj82DnjlcAgntyuJ2VEkQ6jBDwZH6pnUpCIjA6EC6XQI7AATKV4bpEQBGBFo3SojGlTGw96fLrUKD0ODUURAmGTACyJBYBHyrCuWDgqEE9DoBEmikhXTx3MqhIgEkEUCkiRMsFo1FYQPFGjBEKhlRhmIAzKU1boNRqUdj1djeYrdITiaTyUMDjIYFBlByTgAJEkiG2MohWixwTn4g1dVBEFmEzQkM0ADg1ADYAOylMMABlKABYoxi4xjMcik8jMTGMGHSgBOb2VFhwYIDGEqgCsSYrFdVMcxFZjFfzKJViPjdYROdKocLXn4qDNKow8a7SdhGDTI9K2Y12cR2aT2ebumzWZHff4cHopDNE5xGG106R3ZPR9HZ67F4n565lTvulE3AaWRSLTacAVXR6QORiEbHx8lURA1GwiQ-gMT4wJEn74kqQyjFcMxXEsVwbFcuxXEcVwXFctxXI8LxvIBhqiLQABeegDABcG6IwzKEgQVH2E4rhAX2rAlowQKiGCpDsFBMFwvWMaILCMbiaUAF0Qx6jMQ4LhyH2OgQIIzGCSI7AUmAohWtQ1BXPA-C0IIMBXISjBSFcJB0D4nJSSm9GRHJQIKc4fYENaTH6XAvSQREmkwm5pRTM85zrO5DmlE5jHyaxfYAI7CmQeTSgMfxgjA7DSciMYpuJHlEKIpBkulECZdlKbBvlMZ9qgjBECYeRAhljBZdJknJg+XIAL5cgAVkQKiJAA1nArCiMUGS2Fkg3DWNE1fnNECjeNQzVGQdRiFcG21PUohXD09mdMtq0cJMT4iAdJyXdtJxHWA3qnQt60gZt+1XLd12lNpD1ApMu1gQ9SlKFyShoIOWQqHkX4pECJSdHwQhXUCSPCGIX6VKQMCJBIiSiJ5pDkIwkRENjgR1KEmMEkSJL-WA6yE8TpO7lae2hHMtFaCwtBEijAx0MV1NQikiRhLUIL46gcAUkBhopNA8D04DH14LRUKiCSMu7pBWsaFLMvC4aRq034AyTOseu7tzdR82IiCc3Lxt0kNTGlboNu82ycCJC7tBu1NQTAMAANvXtd0ALoR32xuPlbvlmpMxZQFcEgDlcW47sdTuGjAwiaDBrmsSRsddGCW70X5LEuCXpemLQoQJwMoXhWxdcPoaMddKL4vMProjS7LdcK7AzEXc+33q10TXUMTMqSsTBtD3XJsmvTlsiBoHs83bDtqznio2+7oegaw4H8I7K9VPkrsNAM3PUGpvs3-7GMpMH49XZMUf3IDZ-A7XUumtN7kCrtpRCJxkInFQicdCJxMInGwicXCJx8InEIicV42cr551nrQQuAw3JT3vIA0iVseJWyXkbQ0xo6bmwZuQz2dtRB71Ic7F+bsgRMO9s-W+k134hx0hPb+EcfpDCStaTQpAGQnGIMVb6qx6qNTyJyLuZCQFN0GJMCRKVpE7SKiVK4SimqkGwSvXBBcRBFxrsQsujAK6aOCrYyoTVG5VxbhFWxHdFTePvF6ToXIuS0BMLodgKhiYgm0J+JSZROiiEKBAVgzx0DsAhgAEkELQUo6TNaMF+L1JQYAeoRyAA}{Open in Shinylive} - \if{html}{\out{}} + \href{https://shinylive.io/r/app/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCLTIyoBUrQBucAAQAeALS6AZoIgbaJdnN0AVLAFUAokqUBiXVIhrqu-lCkULpwAB6wqCJKAUEGxlzUAPoxUDbRgcFGugDutKQAFirsKbi6IEq6usTmpIy0YnH+GRgmzPDsFZW6tPy6ALxVHWAAIq54ugpgAGJYk6WTAJJ2cxNgzgDKK5MACsvjkwDis-tgAHIAMltgAEJj82DnjlcAgntyuJ2VEkQ6jBDwZH6pnUpCIjA6EC6XQI7AATKV4bpEQBGBFo3SojGlTGw96fLrUKD0ODUURAmGTACyJBYBHyrCuWDgqEE9DoBEmikhXTx3MqhIgEkEUCkiRMsFo1FYQPFGjBEKhlRhmIAzKU1boNRqUdj1djeYrdITiaTyUMDjIYFBlByTgAJEkiG2MohWixwTn4g1dVBEFmEzQkM0ADg1ADYAOylMMABlKABYoxi4xjMcik8jMTGMGHSgBOb2VFhwYIDGEqgCsSYrFdVMcxFZjFfzKJViPjdYROdKocLXn4qDNKow8a7SdhGDTI9K2Y12cR2aT2ebumzWZHff4cHopDNE5xGG106R3ZPR9HZ67F4n565lTvulE3AaWRSLTacAVXR6QORiEbHx8lURA1GwiQ-gMT4wJEn74kqQyjFcMxXEsVwbFcuxXEcVwXFctxXI8LxvIBhqiLQABeegDABcG6IwzKEgQVH2E4rhAX2rAlowQKiGCpDsFBMFwvWMaILCMbiaUAF0Qx6jMQ4LhyH2OgQIIzGCSI7AUmAohWtQ1BXPA-C0IIMBXISjBSFcJB0D4nJSSm9GRHJQIKc4fYENaTH6XAvSQREmkwm5pRTM85zrO5DmlE5jHyaxfYAI7CmQeTSgMfxgjA7DSciMYpuJHlEKIpBkulECZdlKbBvlMZ9qgjBECYeRAhljBZdJknJg+XIAL5cgAVkQKiJAA1nArCiMUGS2Fkg3DWNE1fnNECjeNQzVGQdRiFcG21PUohXD09mdMtq0cJMT4iAdJyXdtJxHWA3qnQt60gZt+1XLd12lNpD1ApMu1gQ9SlKFyShoIOWQqHkX4pECJSdHwQhXUCSPCGIX6VKQMCJBIiSiJ5pDkIwkRENjgR1KEmMEkSJL-WA6yE8TpO7lae2hHMtFaCwtBEijAx0MV1NQikiRhLUIL46gcAUkBhopNA8D04DH14LRUKiCSMu7pBWsaFLMvC4aRq034AyTOseu7tzdR82IiCc3Lxt0kNTGlboNu82ycCJC7tBu1NQTAMAANvXtd0ALoR32xuPlbvlmpMxZQFcEgDlcW47sdTuGjAwiaDBrmsSRsddGCW70X5LEuCXpemLQoQJwMoXhWxdcPoaMddKL4vMProjS7LdcK7AzEXc+33q10TXUMTMqSsTBtD3XJsmvTlsiBoHs83bDtqznio2+7oegaw4H8I7K9VPkrsNAM3PUGpvs3-7GMpMH49XZMUf3IDZ-A7XUumtN7kCrtpRCJxkInFQicTCJxsInFwicfCJxCInFeNnK+edZ60ELgMNyU97yANIlbHiVsl5G0NMaOm5sGakM9nbUQe9iHOxfm7IEDDvbP1vpNd+IcdIT2-hHH6QwkrWk0KQBkJxiDFW+qseqjU8ici7iQkBTdBiTDESlSRO0iolSuAopqpBMEr2wQXEQRca6ELLowCu6jgrWMqE1RuVcW4RWsR3RUnj7xek6FyLktATC6HYCoYmIJtCfiUmUToohCgQFYM8dA7AIYABJBC0FKKkzWjBfi9SUGAHqEcgA}{Open in Shinylive} + \if{html}{\out{}} \if{html}{\out{}} } \item{example-2}{ diff --git a/tests/testthat/test_g_expert_cl.R b/tests/testthat/test_g_expert_cl.R index 01de250e4..41398f0ab 100644 --- a/tests/testthat/test_g_expert_cl.R +++ b/tests/testthat/test_g_expert_cl.R @@ -6,29 +6,29 @@ testthat::test_that("coloring_ggplot_call can work with all combinations", { testthat::expect_equal( coloring_ggplot_call("ADSL", character(0), character(0), FALSE) %>% deparse(), - "aes(colour = ADSL)" + "ggplot2::aes(colour = ADSL)" ) testthat::expect_equal( coloring_ggplot_call("ADSL", "ADSL", character(0), FALSE) %>% deparse(), - "aes(colour = ADSL, fill = ADSL)" + "ggplot2::aes(colour = ADSL, fill = ADSL)" ) testthat::expect_equal( coloring_ggplot_call("ADSL", "ADSL", "ADSL", FALSE) %>% deparse(), - "aes(colour = ADSL, fill = ADSL)" + "ggplot2::aes(colour = ADSL, fill = ADSL)" ) testthat::expect_equal( coloring_ggplot_call("ADSL", "ADSL", character(0), TRUE) %>% deparse(), - "aes(colour = ADSL, fill = ADSL)" + "ggplot2::aes(colour = ADSL, fill = ADSL)" ) testthat::expect_equal( coloring_ggplot_call("ADSL", "ADSL", "ADSL", TRUE) %>% deparse(), - "aes(colour = ADSL, fill = ADSL, size = ADSL)" + "ggplot2::aes(colour = ADSL, fill = ADSL, size = ADSL)" ) testthat::expect_equal( coloring_ggplot_call("ADSL", character(0), "ADSL", TRUE) %>% deparse(), - "aes(colour = ADSL, size = ADSL)" + "ggplot2::aes(colour = ADSL, size = ADSL)" ) }) testthat::test_that("coloring_ggplot_call can work with all combinations without colour_var", { @@ -39,26 +39,26 @@ testthat::test_that("coloring_ggplot_call can work with all combinations without testthat::expect_equal( coloring_ggplot_call(character(0), "ADSL", character(0), FALSE) %>% deparse(), - "aes(fill = ADSL)" + "ggplot2::aes(fill = ADSL)" ) testthat::expect_equal( coloring_ggplot_call(character(0), "ADSL", "ADSL", FALSE) %>% deparse(), - "aes(fill = ADSL)" + "ggplot2::aes(fill = ADSL)" ) testthat::expect_equal( coloring_ggplot_call(character(0), "ADSL", character(0), TRUE) %>% deparse(), - "aes(fill = ADSL)" + "ggplot2::aes(fill = ADSL)" ) testthat::expect_equal( coloring_ggplot_call(character(0), "ADSL", "ADSL", TRUE) %>% deparse(), - "aes(colour = ADSL, fill = ADSL, size = ADSL)" + "ggplot2::aes(colour = ADSL, fill = ADSL, size = ADSL)" ) }) testthat::test_that("coloring_ggplot_call can work size_var", { testthat::expect_equal( coloring_ggplot_call(character(0), character(0), "ADSL", TRUE) %>% deparse(), - "aes(size = ADSL)" + "ggplot2::aes(size = ADSL)" ) testthat::expect_equal( coloring_ggplot_call(character(0), character(0), character(0), TRUE),