Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mesos entirely from saros.base #33

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions R/attach_chapter_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ attach_chapter_dataset <- function(chapter_structure_chapter,
data,
path,
chapter_foldername_clean,
mesos_var,
auxiliary_variables,
serialized_format = "rds") {

Expand All @@ -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 <-
Expand Down
110 changes: 34 additions & 76 deletions R/draft_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)


Expand Down
12 changes: 1 addition & 11 deletions R/gen_qmd_chapters.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,20 @@
#' main question, and being of the same data type.
#'
#' @inheritParams draft_report
#' @param mesos_group *Specific group to compare with*
#'
#' `scalar<character>` // *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
#'
gen_qmd_chapters <-
function(chapter_structure,
data,
mesos_group = NULL,
authors_col = "author",
...,
call = rlang::caller_env()
) {

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)
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions R/gen_qmd_structure.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 1 addition & 3 deletions R/log_unused_variables.R
Original file line number Diff line number Diff line change
@@ -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}}.")
Expand Down
18 changes: 4 additions & 14 deletions R/refine_chapter_overview.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
#'
#' `scalar<integer>` // *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.
Expand All @@ -116,15 +116,15 @@
#'
#' `scalar<logical>` // *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<boolean>` // *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*
#'
Expand Down Expand Up @@ -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<character>` // *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<string>` // *default:* `".variable_group_dep"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
31 changes: 0 additions & 31 deletions R/remove_empty_col_for_mesos_group.R

This file was deleted.

12 changes: 0 additions & 12 deletions R/validate_draft_report_args.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)),

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 0 additions & 10 deletions R/validate_refine_chapter_overview_args.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))),
Expand Down Expand Up @@ -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')}}.",
Expand Down
7 changes: 0 additions & 7 deletions man/draft_report.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading