From e47e2779477e3ddb43818c50423a1f529e2b3591 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 12:55:48 +0200 Subject: [PATCH] using `cards::process_formula_selectors()` instead of `.formula_list_to_named_list()` --- R/tidy_add_variable_labels.R | 23 ++++++++++++++--------- man/tidy_add_variable_labels.Rd | 13 ++++++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/R/tidy_add_variable_labels.R b/R/tidy_add_variable_labels.R index 25485e21..3707995f 100644 --- a/R/tidy_add_variable_labels.R +++ b/R/tidy_add_variable_labels.R @@ -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 @@ -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) diff --git a/man/tidy_add_variable_labels.Rd b/man/tidy_add_variable_labels.Rd index 9346430a..08951dc5 100644 --- a/man/tidy_add_variable_labels.Rd +++ b/man/tidy_add_variable_labels.Rd @@ -14,14 +14,17 @@ tidy_add_variable_labels( ) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{labels}{an optional named list or named vector of -custom variable labels} +\item{labels}{(\code{\link[gtsummary:syntax]{formula-list-selector}})\cr +An optional named list or a named vector of custom variable labels.} -\item{interaction_sep}{separator for interaction terms} +\item{interaction_sep}{(\code{string})\cr +Separator for interaction terms.} -\item{model}{the corresponding model, if not attached to \code{x}} +\item{model}{(a model object, e.g. \code{glm})\cr +The corresponding model, if not attached to \code{x}.} \item{quiet}{(\code{logical})\cr Whether \code{broom.helpers} should not return a message when requested output