From c9efd56b0747f9bea1c5ae0f9bad9c5786ed0e09 Mon Sep 17 00:00:00 2001 From: Nikolas Burkoff Date: Fri, 22 Jul 2022 13:54:19 +0100 Subject: [PATCH] remove filtered --- R/tm_missing_data.R | 58 ++++++++++++++++++++++----------------------- R/tm_outliers.R | 6 ++--- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index ce3acc77b..474be42c6 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -348,32 +348,32 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot teal.code::chunks_push(..., chunks = common_stack) } - anl_name <- paste0(dataname, "_FILTERED") - anl_filtered <- datasets$get_data(dataname, filtered = TRUE) - assign(anl_name, anl_filtered) + anl_name <- dataname + anl <- datasets$get_data(dataname, filtered = TRUE) + assign(anl_name, anl) teal.code::chunks_reset(chunks = common_stack) group_var <- input$group_by_var - if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl_filtered)) { + if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl)) { common_stack_push( - id = "ANL_FILTERED_selection_call", + id = "ANL_selection_call", expression = substitute( - expr = ANL_FILTERED <- anl_name[, selected_vars], # nolint + expr = ANL <- anl_name[, selected_vars], # nolint env = list(anl_name = as.name(anl_name), selected_vars = selected_vars()) ) ) } else { common_stack_push( - id = "ANL_FILTERED_call", - expression = substitute(expr = ANL_FILTERED <- anl_name, env = list(anl_name = as.name(anl_name))) # nolint + id = "ANL_call", + expression = substitute(expr = ANL <- anl_name, env = list(anl_name = as.name(anl_name))) # nolint ) } if (input$summary_type == "By Variable Levels" && !is.null(group_var) && !(group_var %in% selected_vars())) { common_stack_push( - id = "ANL_FILTERED_group_var_call", + id = "ANL_group_var_call", substitute( - expr = ANL_FILTERED[[group_var]] <- anl_name[[group_var]], # nolint + expr = ANL[[group_var]] <- anl_name[[group_var]], # nolint env = list(group_var = group_var, anl_name = as.name(anl_name)) ) ) @@ -531,7 +531,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot summary_stack_push( id = "ANL_na_column_call", expression = substitute( - expr = ANL_FILTERED[[new_col_name]] <- ifelse(rowSums(is.na(ANL_FILTERED)) > 0, NA, FALSE), # nolint + expr = AN[[new_col_name]] <- ifelse(rowSums(is.na(ANL)) > 0, NA, FALSE), # nolint env = list(new_col_name = new_col_name) ) ) @@ -540,7 +540,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot summary_stack_push( id = "analysis_vars_call", expression = substitute( - expr = analysis_vars <- setdiff(colnames(ANL_FILTERED), data_keys), + expr = analysis_vars <- setdiff(colnames(ANL), data_keys), env = list(data_keys = data_keys()) ) ) @@ -551,13 +551,13 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot expr = summary_plot_obs <- data_frame_call[, analysis_vars] %>% dplyr::summarise_all(list(function(x) sum(is.na(x)))) %>% tidyr::pivot_longer(tidyselect::everything(), names_to = "col", values_to = "n_na") %>% - dplyr::mutate(n_not_na = nrow(ANL_FILTERED) - n_na) %>% + dplyr::mutate(n_not_na = nrow(ANL) - n_na) %>% tidyr::pivot_longer(-col, names_to = "isna", values_to = "n") %>% - dplyr::mutate(isna = isna == "n_na", n_pct = n / nrow(ANL_FILTERED) * 100), + dplyr::mutate(isna = isna == "n_na", n_pct = n / nrow(ANL) * 100), env = list(data_frame_call = if (!inherits(datasets$get_data(dataname, filtered = TRUE), "tbl_df")) { - quote(tibble::as_tibble(ANL_FILTERED)) + quote(tibble::as_tibble(ANL)) } else { - quote(ANL_FILTERED) + quote(ANL) }) ) ) @@ -646,13 +646,13 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot ) summary_stack_push( id = "ndistinct_subjects_call", - expression = quote(ndistinct_subjects <- dplyr::n_distinct(ANL_FILTERED[, parent_keys])) + expression = quote(ndistinct_subjects <- dplyr::n_distinct(ANL[, parent_keys])) ) summary_stack_push( id = "summary_plot_patients_call", expression = quote( - summary_plot_patients <- ANL_FILTERED[, c(parent_keys, analysis_vars)] %>% + summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>% dplyr::group_by_at(parent_keys) %>% dplyr::summarise_all(anyNA) %>% tidyr::pivot_longer(cols = !tidyselect::all_of(parent_keys), names_to = "col", values_to = "anyna") %>% @@ -762,7 +762,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot teal.code::chunks_push( id = "combination_cutoff_call", expression = quote({ - combination_cutoff <- ANL_FILTERED %>% + combination_cutoff <- ANL %>% dplyr::mutate_all(is.na) %>% dplyr::group_by_all() %>% dplyr::tally() %>% @@ -956,8 +956,8 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot # Add common code into this stack teal.code::chunks_push_chunks(common_code_chunks(), chunks = table_stack) - # extract the ANL_FILTERED dataset for use in further validation - anl_filtered <- teal.code::chunks_get_var("ANL_FILTERED", chunks = table_stack) + # extract the ANL dataset for use in further validation + anl <- teal.code::chunks_get_var("ANL", chunks = table_stack) validate(need(input$count_type, "Please select type of counts")) if (!is.null(input$group_by_var)) { @@ -969,7 +969,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot validate( need( is.null(group_var) || - nrow(unique(anl_filtered[, group_var])) < 100, + nrow(unique(anl[, group_var])) < 100, "Please select group-by variable with fewer than 100 unique values" ) ) @@ -979,10 +979,10 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot vars <- unique(variables_select, group_var) count_type <- input$count_type # nolint (local variable is assigned and used) - if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl_filtered)) { + if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl)) { variables <- selected_vars() # nolint (local variable is assigned and used) } else { - variables <- colnames(anl_filtered) + variables <- colnames(anl) } summ_fn <- if (input$count_type == "counts") { @@ -997,7 +997,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot id = "summary_data_call_1", expression = substitute( expr = { - summary_data <- ANL_FILTERED %>% + summary_data <- ANL %>% dplyr::mutate(group_var_name := forcats::fct_explicit_na(as.factor(group_var_name), "NA")) %>% dplyr::group_by_at(group_var) %>% dplyr::filter(group_var_name %in% group_vals) @@ -1019,11 +1019,11 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot table_stack_push( id = "summary_data_call_1", expression = substitute( - expr = summary_data <- ANL_FILTERED %>% + expr = summary_data <- ANL %>% dplyr::summarise_all(summ_fn) %>% tidyr::pivot_longer(tidyselect::everything(), names_to = "Variable", - values_to = paste0("Missing (N=", nrow(ANL_FILTERED), ")") + values_to = paste0("Missing (N=", nrow(ANL), ")") ) %>% dplyr::mutate(`Variable label` = create_cols_labels(Variable), .after = Variable), env = list(summ_fn = summ_fn) @@ -1065,7 +1065,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot by_subject_stack_push( id = "analysis_vars_call", expression = substitute( - expr = analysis_vars <- setdiff(colnames(ANL_FILTERED), data_keys), + expr = analysis_vars <- setdiff(colnames(ANL), data_keys), env = list(data_keys = data_keys()) ) ) @@ -1073,7 +1073,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot by_subject_stack_push( id = "summary_plot_patients_call", expression = quote({ - summary_plot_patients <- ANL_FILTERED[, c(parent_keys, analysis_vars)] %>% + summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>% dplyr::group_by_at(parent_keys) %>% dplyr::mutate(id = dplyr::cur_group_id()) %>% dplyr::ungroup() %>% diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 732490470..7357d49e7 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -845,10 +845,10 @@ srv_outliers <- function(id, datasets, reporter, outlier_var, all_categories <- lapply( unique(anl[[categorical_var]]), function(x) { - anl_filtered <- anl %>% dplyr::filter(get(categorical_var) == x) + anl <- anl %>% dplyr::filter(get(categorical_var) == x) anl_outlier2 <- ANL_OUTLIER %>% dplyr::filter(get(categorical_var) == x) - ecdf_df <- anl_filtered %>% - dplyr::mutate(y = stats::ecdf(anl_filtered[[outlier_var]])(anl_filtered[[outlier_var]])) + ecdf_df <- anl %>% + dplyr::mutate(y = stats::ecdf(anl[[outlier_var]])(anl[[outlier_var]])) dplyr::left_join( ecdf_df,