Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Emily de la Rua <59304861+edelarua@users.noreply.github.com>
Signed-off-by: Davide Garolini <dgarolini@gmail.com>
  • Loading branch information
Melkiades and edelarua authored Sep 7, 2023
1 parent 8347c31 commit 0882056
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ a_summary_internal <- function(x,

# Check for custom labels from control_analyze_vars
if (is.numeric(x)) {
default_labels <- get_stats("analyze_vars", type, add_pval = compare) %>%
default_labels <- .stats %>%
get_label_from_stats()
for (i in intersect(.stats, c("mean_ci", "mean_pval", "median_ci", "quantiles"))) {
if (!i %in% names(.labels) || .labels[[i]] == default_labels[[i]]) {
Expand Down
2 changes: 1 addition & 1 deletion R/summary_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ summary_custom <- function(type = "numeric",
lifecycle::deprecate_warn(
"0.9.0.9001",
"summary_custom()",
details = "Please use get_stats and get_* directly instead."
details = "Please use `get_stats`, `get_format_from_stats`, and `get_label_from_stats` directly instead."
)

.stats <- get_stats("analyze_vars", type, stats_custom, add_pval = include_pval)
Expand Down
22 changes: 11 additions & 11 deletions R/utils_defaults_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ assert_allowed_types <- function(type) {
invisible(default_type)
}

#' Defaults for stats methods names and their relative formats/labels
#' Defaults for statistical method names and their associated formats & labels
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' Utility functions to get valid statistic methods for different method groups
#' (`.stats`) and their relative formats (`.formats`) and labels (`.labels`). This utility
#' (`.stats`) and their associated formats (`.formats`) and labels (`.labels`). This utility
#' is used across `tern`, but some of its working principles can be seen in [analyze_vars()].
#' See notes to understand why this is experimental.
#'
#' @param stats (`character`) \cr statistical methods to get defaults formats for.
#' @param type (`character`) \cr type of data and result desired. Some stats defaults (and their formats and labels),
#' @param stats (`character`)\cr statistical methods to get defaults formats for.
#' @param type (`character`)\cr type of data and result desired. Some stats defaults (and their formats and labels),
#' differ if you need to analyze different type of values. See Details for available options.
#'
#' @details
Expand Down Expand Up @@ -101,8 +101,8 @@ get_stats <- function(method_groups, type = NULL, stats_in = NULL, add_pval = FA
"geom_cv"
),
stop(
"The inserted method_group (", mgi, ")",
ifelse(add_typ_to_err, paste0(" and type (", paste0(typ, collapse = " "), ")"), ""),
"The selected method group (", mgi, ")",
ifelse(add_typ_to_err, paste0(" with type(s) ", paste0(typ, collapse = ", ")), ""),
" has no default statistical method."
)
)
Expand All @@ -126,7 +126,7 @@ get_stats <- function(method_groups, type = NULL, stats_in = NULL, add_pval = FA
"numeric" %in% type && stats_in_pval_value != "pval") {
stop(
"Inserted p-value (", stats_in_pval_value, ") is not valid for type ",
type, ". Use the other from pval pval_counts."
type, ". Use ", paste(ifelse(stats_in_pval_value == "pval", "pval_counts", "pval")), " instead."
)
}

Expand Down Expand Up @@ -155,12 +155,12 @@ get_stats <- function(method_groups, type = NULL, stats_in = NULL, add_pval = FA
# If intersect did not find matches (and no pval?) -> error
if (length(out) == 0) {
stop(
"The selected method_groups (", paste0(method_groups, collapse = " "), ")",
"The selected method group(s) (", paste0(method_groups, collapse = ", "), ")",
ifelse(is.null(type), "", paste0(
" and types (",
paste0(type, collapse = " "), ")"
" with type(s) ",
paste0(type, collapse = ", ")
)),
" does not have the required default statistical methods:\n",
" do not have the required default statistical methods:\n",
paste0(stats_in, collapse = " ")
)
}
Expand Down

0 comments on commit 0882056

Please sign in to comment.