diff --git a/R/attach_chapter_dataset.R b/R/attach_chapter_dataset.R index 764eae0..ef6a608 100644 --- a/R/attach_chapter_dataset.R +++ b/R/attach_chapter_dataset.R @@ -2,7 +2,6 @@ attach_chapter_dataset <- function(chapter_structure_chapter, data, path, chapter_foldername_clean, - mesos_var, auxiliary_variables, serialized_format = "rds") { @@ -19,7 +18,6 @@ attach_chapter_dataset <- function(chapter_structure_chapter, data_chapter <- data[, names(data) %in% unique(c(dep_vars, indep_vars, - mesos_var, auxiliary_variables)), drop = FALSE] filename_chapter_dataset <- diff --git a/R/draft_report.R b/R/draft_report.R index e53949d..8323725 100644 --- a/R/draft_report.R +++ b/R/draft_report.R @@ -188,7 +188,6 @@ draft_report <- title = "Report", authors = NULL, authors_col = "author", - mesos_var = NULL, chapter_yaml_file = NULL, chapter_qmd_start_section_filepath = NULL, @@ -245,91 +244,50 @@ draft_report <- all_authors <- get_authors(data = chapter_structure, col=args$authors_col) - if(!is_string(args$mesos_var)) { - uniques <- NA_character_ + chapter_filepaths <- + rlang::exec( + gen_qmd_chapters, + chapter_structure = chapter_structure, + data = data, + path = path, + !!!args[!names(args) %in% .saros.env$ignore_args]) - } else { - # Mesos reports - uniques <- pull_uniques(data[[args$mesos_var]]) - } - - report_foldername_clean <- filename_sanitizer(uniques, max_chars = args$max_clean_folder_name) - - index_filepath <- - lapply(X = - cli::cli_progress_along(uniques, # Not working well - format = "Generating mesos report for... {uniques[cli::pb_current]}", - clear = FALSE, - auto_terminate = FALSE), - FUN = function(.x) { - - - if(is.na(uniques[.x])) { # Macro - - mesos_group <- NULL - - - } else { # Mesos - mesos_group <- uniques[.x] - path <- file.path(path, report_foldername_clean[.x]) - args$title <- stringi::stri_c(if(!is.na(args$title)) args$title, - if(!is.na(uniques[.x])) uniques[.x], - ignore_null=TRUE) - } + if(isTRUE(args$combined_report)) { + report_filepath <- + gen_qmd_file( + path = path, + filename = args$report_filename, + yaml_file = args$report_yaml_file, + qmd_start_section_filepath = args$report_qmd_start_section_filepath, + qmd_end_section_filepath = args$report_qmd_end_section_filepath, + title = args$title, + authors = all_authors, + output_formats = NULL, + output_filename = NULL, + call = rlang::caller_env()) + } - chapter_filepaths <- - rlang::exec( - gen_qmd_chapters, - chapter_structure = chapter_structure, - data = data, - mesos_group = mesos_group, - path = path, - !!!args[!names(args) %in% .saros.env$ignore_args]) - - - - - if(isTRUE(args$combined_report)) { - - report_filepath <- - gen_qmd_file( - path = path, - filename = args$report_filename, - yaml_file = args$report_yaml_file, - qmd_start_section_filepath = args$report_qmd_start_section_filepath, - qmd_end_section_filepath = args$report_qmd_end_section_filepath, - title = args$title, - authors = all_authors, - output_formats = NULL, - output_filename = NULL, - call = rlang::caller_env()) - } - - index_filepath <- - gen_qmd_file( - path = path, - filename = args$index_filename, - yaml_file = args$index_yaml_file, - qmd_start_section_filepath = args$index_qmd_start_section_filepath, - qmd_end_section_filepath = args$index_qmd_end_section_filepath, - title = args$title, - authors = all_authors, - output_formats = if(!is.null(args$report_yaml_file)) find_yaml_formats(args$report_yaml_file), - output_filename = args$report_filename, - call = rlang::caller_env()) - - index_filepath + index_filepath <- + gen_qmd_file( + path = path, + filename = args$index_filename, + yaml_file = args$index_yaml_file, + qmd_start_section_filepath = args$index_qmd_start_section_filepath, + qmd_end_section_filepath = args$index_qmd_end_section_filepath, + title = args$title, + authors = all_authors, + output_formats = if(!is.null(args$report_yaml_file)) find_yaml_formats(args$report_yaml_file), + output_filename = args$report_filename, + call = rlang::caller_env()) - }) - index_filepath <- as.character(unlist(index_filepath)) - validate_path_lengths_on_win(path = path, + validate_path_lengths_on_win(path = index_filepath, max_path_warning_threshold = max_path_warning_threshold) diff --git a/R/gen_qmd_chapters.R b/R/gen_qmd_chapters.R index e3f3fa2..5eabc4f 100644 --- a/R/gen_qmd_chapters.R +++ b/R/gen_qmd_chapters.R @@ -12,12 +12,6 @@ #' main question, and being of the same data type. #' #' @inheritParams draft_report -#' @param mesos_group *Specific group to compare with* -#' -#' `scalar` // *Default:* `NULL` (`optional`) -#' -#' Both the absolute and relative folder paths are required, as strings. -#' #' #' @return Side-effects: qmd-files generated in the specified working directory. #' @keywords internal @@ -25,7 +19,6 @@ gen_qmd_chapters <- function(chapter_structure, data, - mesos_group = NULL, authors_col = "author", ..., call = rlang::caller_env() @@ -33,7 +26,6 @@ gen_qmd_chapters <- dots <- rlang::list2(...) - check_string(mesos_group, n=1, null.ok=TRUE, call = call) path <- fs::as_fs_path(dots$path) dir.create(path = path, recursive = TRUE, showWarnings = FALSE) @@ -100,7 +92,6 @@ gen_qmd_chapters <- gen_qmd_structure, data = data, chapter_structure = chapter_structure_chapter, - mesos_group = mesos_group, chapter_folderpath_absolute = chapter_folderpath_absolute, chapter_foldername = chapter_foldername_clean, !!!dots#[!names(dots) %in% c("chapter_structure", "call")] @@ -130,7 +121,6 @@ gen_qmd_chapters <- chapter_structure_chapter = chapter_structure_chapter, chapter_foldername_clean = chapter_foldername_clean, path = path, - mesos_var = dots$mesos_var, auxiliary_variables = dots$auxiliary_variables, serialized_format = dots$serialized_format) } @@ -157,7 +147,7 @@ gen_qmd_chapters <- chapter_filepaths <- unlist(chapter_filepaths) - cli::cli_process_done(msg_done = "Completed report{if(is_string(mesos_group)) paste0(' for ', mesos_group)}.") + cli::cli_process_done(msg_done = "Completed report.") chapter_filepaths diff --git a/R/gen_qmd_structure.R b/R/gen_qmd_structure.R index 7a210a6..d83b602 100644 --- a/R/gen_qmd_structure.R +++ b/R/gen_qmd_structure.R @@ -120,12 +120,6 @@ gen_qmd_structure <- return(output) } - # chapter_structure <- remove_empty_col_for_mesos_group(data = data, - # chapter_structure = chapter_structure, - # mesos_group = mesos_group, - # mesos_var = dots$mesos_var, - # hide_chunk_if_n_below = dots$hide_chunk_if_n_below) - grouping_structure <- dplyr::group_vars(chapter_structure) non_grouping_vars <- colnames(chapter_structure)[!colnames(chapter_structure) %in% grouping_structure] diff --git a/R/log_unused_variables.R b/R/log_unused_variables.R index 37d2ae1..e64dab1 100644 --- a/R/log_unused_variables.R +++ b/R/log_unused_variables.R @@ -1,13 +1,11 @@ log_unused_variables <- function(data, chapter_structure, auxiliary_variables = NULL, - mesos_var = NULL, log_file = NULL) { used_vars <- unique(c(as.character(chapter_structure$.variable_name_dep), as.character(chapter_structure$.variable_name_indep), - auxiliary_variables, - mesos_var)) + auxiliary_variables)) not_used_vars <- colnames(data)[!colnames(data) %in% used_vars] if(length(not_used_vars)>0) { cli::cli_inform("Not using the following variables in {.arg data}: {.var {not_used_vars}}.") diff --git a/R/refine_chapter_overview.R b/R/refine_chapter_overview.R index ecefdab..3bacf55 100644 --- a/R/refine_chapter_overview.R +++ b/R/refine_chapter_overview.R @@ -107,7 +107,7 @@ #' #' `scalar` // *default:* `10` (`optional`) #' -#' Whether to hide result if N for a given datasets (or mesos group) is below +#' Whether to hide result if N for a given dataset is below #' this value. NOTE: Exceptions will be made to chr_table and chr_plot as these are #' typically exempted in the first place. This might change in the future with #' a separate argument. @@ -116,15 +116,15 @@ #' #' `scalar` // *default:* `TRUE` (`optional`) #' -#' For mesos reports using the element "chr_table", open responses are -#' displayed for also the entire sample (`FALSE`) or only for the mesos +#' MOVE TO saros.contents: For reports using the element "chr_table", open responses are +#' displayed for also the entire sample (`FALSE`) or only for the target #' group to ensure data privacy (`TRUE`). #' #' @param hide_variable_if_all_na *Hide variable from outputs if containing all NA* #' #' `scalar` // *default:* `TRUE` (`optional`) #' -#' Whether to remove all variables (in particular useful for mesos) if all values are NA +#' Whether to remove variables if all values are NA. #' #' @param max_width_obj,max_width_chunk,max_width_file *Maximum object width* #' @@ -161,13 +161,6 @@ #' Column names in `data` that should always be included in datasets for #' chapter qmd-files, if `attach_chapter_dataset=TRUE`. Not publicly available. #' -#' @param mesos_var *Variable in ´data´ indicating groups to tailor reports for* -#' -#' `scalar` // *default:* `NULL` (`optional`) -#' -#' Column name in data indicating the groups for which mesos reports will be produced. -#' -#' #' @param variable_group_dep *Name for the variable_group_dep column* #' #' `scalar` // *default:* `".variable_group_dep"` @@ -247,8 +240,6 @@ refine_chapter_overview <- sep_file = "-", max_clean_folder_name = 12, # Tidy up argument name: max_width_clean_folder_name - # MESOS AND OTHER FEATURES - mesos_var = NULL, # Not in use yet auxiliary_variables = NULL, # Not in use yet ..., progress = TRUE, @@ -344,7 +335,6 @@ refine_chapter_overview <- log_unused_variables(chapter_structure = out, data = data, auxiliary_variables = auxiliary_variables, - mesos_var = mesos_var, log_file = log_file) # if(!is.factor(out$.variable_name_dep)) browser() diff --git a/R/remove_empty_col_for_mesos_group.R b/R/remove_empty_col_for_mesos_group.R deleted file mode 100644 index 734eab1..0000000 --- a/R/remove_empty_col_for_mesos_group.R +++ /dev/null @@ -1,31 +0,0 @@ -remove_empty_col_for_mesos_group <- function(data, - chapter_overview, - mesos_group = NULL, - mesos_var, - log_file = NULL, - hide_chunk_if_n_below = 10) { - if(is_string(mesos_group)) { - unique_vars <- unique(c(as.character(chapter_overview$.variable_name_dep), - as.character(chapter_overview$.variable_name_indep))) - unique_vars <- unique_vars[!is.na(unique_vars)] - for(var in unique_vars) { - tmp <- vctrs::vec_slice(data, - !is.na(data[[mesos_var]]) & - data[[mesos_var]] == mesos_group) - - if(all(is.na(tmp[[var]])) || - (length(tmp[[var]]) < hide_chunk_if_n_below) && - !is.character(tmp[[var]])) { - msg <- "In mesos_group {mesos_group}, removing empty column {var}." - cli::cli_inform(msg) - if(is_string(log_file)) { - cli::cat_print(x = paste0(msg, "\n"), file = log_file) - } - chapter_overview <- vctrs::vec_slice(chapter_overview, - as.character(chapter_overview[[".variable_name_dep"]]) != var) - } - } - } - chapter_overview - -} diff --git a/R/validate_draft_report_args.R b/R/validate_draft_report_args.R index 001205b..71ed2ad 100644 --- a/R/validate_draft_report_args.R +++ b/R/validate_draft_report_args.R @@ -30,7 +30,6 @@ validate_draft_report_args <- function(params) { chapter_structure = list(fun = function(x) validate_chapter_structure(x, core_chapter_structure_cols = core_chapter_structure_cols)), # Character vectors (not enums) - mesos_var = list(fun = function(x) is.null(x) || is_string(x)), auxiliary_variables = list(fun = function(x) is.null(x) || (is.character(x) && all(x %in% colnames(params$data)))), path = list(fun = function(x) is_string(x)), @@ -74,17 +73,6 @@ validate_draft_report_args <- function(params) { params$tabular_format <- params$tabular_format[1] params$serialized_format <- params$serialized_format[1] - if(is_string(params$mesos_var)) { - if(!any(colnames(params$data) == params$mesos_var)) { - cli::cli_abort("{.arg mesos_var}: {.arg {params$mesos_var}} not found in data.") - } - if(all(is.na(params$data[[params$mesos_var]]))) { - cli::cli_abort("{.arg mesos_var}: All mesos_var entries are NA.") - } - } - - - pkg <- switch(params$tabular_format, "delim" = "utils", diff --git a/R/validate_refine_chapter_overview_args.R b/R/validate_refine_chapter_overview_args.R index 6c577b2..8c0256f 100644 --- a/R/validate_refine_chapter_overview_args.R +++ b/R/validate_refine_chapter_overview_args.R @@ -34,7 +34,6 @@ validate_refine_chapter_overview_args <- function(params) { sep_obj = list(fun = function(x) is_string(x)), sep_chunk = list(fun = function(x) is_string(x)), sep_file = list(fun = function(x) is_string(x)), - mesos_var = list(fun = function(x) is.null(x) || is_string(x)), auxiliary_variables = list(fun = function(x) is.null(x) || (is.character(x) && all(x %in% colnames(params$data)))), always_show_bi_for_indep = list(fun = function(x) is.null(x) || (is.character(x) && all(x %in% colnames(params$data)))), variables_show_bi_for_by = list(fun = function(x) is.null(x) || (is.character(x) && all(x %in% colnames(params$data)))), @@ -79,15 +78,6 @@ validate_refine_chapter_overview_args <- function(params) { params$chunk_templates <- validate_chunk_templates(params$chunk_templates) - if(is_string(params$mesos_var)) { - if(!any(colnames(params$data) == params$mesos_var)) { - cli::cli_abort("{.arg mesos_var}: {.arg {params$mesos_var}} not found in data.") - } - if(all(is.na(params$data[[params$mesos_var]]))) { - cli::cli_abort("{.arg mesos_var}: All mesos_var entries are NA.") - } - } - if(!all(c("chapter", ".template_name") %in% params$organize_by)) { cli::cli_abort(c("{.arg organize_by} must contain both {.var {c('chapter', '.template_name')}}.", diff --git a/man/draft_report.Rd b/man/draft_report.Rd index 3dfe29b..980d844 100644 --- a/man/draft_report.Rd +++ b/man/draft_report.Rd @@ -12,7 +12,6 @@ draft_report( title = "Report", authors = NULL, authors_col = "author", - mesos_var = NULL, chapter_yaml_file = NULL, chapter_qmd_start_section_filepath = NULL, chapter_qmd_end_section_filepath = NULL, @@ -85,12 +84,6 @@ If multiple authors per chapter, separate with semicolon. Ensure consistency.} Only used if it exists. Multiple authors are separated by semicolon (and optionally with a subsequent space).} -\item{mesos_var}{\emph{Variable in ´data´ indicating groups to tailor reports for} - -\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) - -Column name in data indicating the groups for which mesos reports will be produced.} - \item{chapter_yaml_file}{\emph{Path to YAML-file to insert into each chapter qmd-file} \verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) diff --git a/man/gen_qmd_chapters.Rd b/man/gen_qmd_chapters.Rd index 7fab66b..95762db 100644 --- a/man/gen_qmd_chapters.Rd +++ b/man/gen_qmd_chapters.Rd @@ -7,7 +7,6 @@ gen_qmd_chapters( chapter_structure, data, - mesos_group = NULL, authors_col = "author", ..., call = rlang::caller_env() @@ -29,12 +28,6 @@ variables) and other informative columns as needed.} A data frame (or a srvyr-object) with the columns specified in the chapter_structure 'dep', etc columns.} -\item{mesos_group}{\emph{Specific group to compare with} - -\verb{scalar} // \emph{Default:} \code{NULL} (\code{optional}) - -Both the absolute and relative folder paths are required, as strings.} - \item{authors_col}{\emph{Column name for author} \verb{scalar} // \emph{default:} \code{"author"} (\code{optional}) diff --git a/man/refine_chapter_overview.Rd b/man/refine_chapter_overview.Rd index d7fb168..a6ac2e2 100644 --- a/man/refine_chapter_overview.Rd +++ b/man/refine_chapter_overview.Rd @@ -30,7 +30,6 @@ refine_chapter_overview( sep_chunk = "-", sep_file = "-", max_clean_folder_name = 12, - mesos_var = NULL, auxiliary_variables = NULL, ..., progress = TRUE, @@ -120,7 +119,7 @@ If N is below this value, p-value will not be shown.} \verb{scalar} // \emph{default:} \code{10} (\code{optional}) -Whether to hide result if N for a given datasets (or mesos group) is below +Whether to hide result if N for a given dataset is below this value. NOTE: Exceptions will be made to chr_table and chr_plot as these are typically exempted in the first place. This might change in the future with a separate argument.} @@ -129,14 +128,14 @@ a separate argument.} \verb{scalar} // \emph{default:} \code{TRUE} (\code{optional}) -Whether to remove all variables (in particular useful for mesos) if all values are NA} +Whether to remove variables if all values are NA.} \item{hide_chr_for_others}{\emph{Hide open response displays for others} \verb{scalar} // \emph{default:} \code{TRUE} (\code{optional}) -For mesos reports using the element "chr_table", open responses are -displayed for also the entire sample (\code{FALSE}) or only for the mesos +MOVE TO saros.contents: For reports using the element "chr_table", open responses are +displayed for also the entire sample (\code{FALSE}) or only for the target group to ensure data privacy (\code{TRUE}).} \item{organize_by}{\emph{Grouping columns} @@ -192,12 +191,6 @@ Whereas \code{max_width_file} truncates the file name, this argument truncates the folder name. It will not impact the report or chapter names in website, only the folders.} -\item{mesos_var}{\emph{Variable in ´data´ indicating groups to tailor reports for} - -\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) - -Column name in data indicating the groups for which mesos reports will be produced.} - \item{auxiliary_variables}{\emph{Auxiliary variables to be included in datasets} \verb{vector} // \emph{default:} \code{NULL} (\code{optional}) diff --git a/tests/testthat/test-draft_report.R b/tests/testthat/test-draft_report.R index 61b50e6..aea4d0b 100644 --- a/tests/testthat/test-draft_report.R +++ b/tests/testthat/test-draft_report.R @@ -37,7 +37,6 @@ testthat::test_that("draft_report", { saros.base::draft_report( chapter_structure = _, data = saros.base::ex_survey, - mesos_var = "f_uni", combined_report = TRUE, path = tmpdir) @@ -46,7 +45,7 @@ testthat::test_that("draft_report", { full.names = TRUE, recursive = TRUE, ignore.case = TRUE) testthat::expect_equal( object = length(output_files), - expected = (nrow(saros.base::ex_survey_ch_overview)+2) * dplyr::n_distinct(saros.base::ex_survey$f_uni)) + expected = (nrow(saros.base::ex_survey_ch_overview)+2)) })