Skip to content

Commit

Permalink
using cards::process_formula_selectors() instead of `.formula_list_…
Browse files Browse the repository at this point in the history
…to_named_list()`
  • Loading branch information
larmarange committed Aug 23, 2024
1 parent 114d338 commit e47e277
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
23 changes: 14 additions & 9 deletions R/tidy_add_variable_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
#'
#' It is possible to pass a custom label for an interaction
#' term in `labels` (see examples).
#' @param x a tidy tibble
#' @param labels an optional named list or named vector of
#' custom variable labels
#' @param interaction_sep separator for interaction terms
#' @param model the corresponding model, if not attached to `x`
#' @param x (`data.frame`)\cr
#' A tidy tibble as produced by `tidy_*()` functions.
#' @param labels ([`formula-list-selector`][gtsummary::syntax])\cr
#' An optional named list or a named vector of custom variable labels.
#' @param interaction_sep (`string`)\cr
#' Separator for interaction terms.
#' @param model (a model object, e.g. `glm`)\cr
#' The corresponding model, if not attached to `x`.
#' @inheritParams tidy_plus_plus
#' @export
#' @family tidy_helpers
Expand Down Expand Up @@ -68,10 +71,12 @@ tidy_add_variable_labels <- function(x,
x <- x |> tidy_identify_variables(model = model)
}

labels <- .formula_list_to_named_list(labels, var_info = x, arg_name = "labels")
if (is.list(labels)) {
labels <- unlist(labels)
}
if (is.atomic(labels)) labels <- as.list(labels) # vectors allowed
cards::process_formula_selectors(
data = scope_tidy(x),
labels = labels
)
labels <- unlist(labels)

# start with the list of terms
var_labels <- unique(x$term)
Expand Down
13 changes: 8 additions & 5 deletions man/tidy_add_variable_labels.Rd

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

0 comments on commit e47e277

Please sign in to comment.