From 776a96c061683eb2da24314b15db797f0755161e Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Thu, 22 Aug 2024 16:21:02 +0200 Subject: [PATCH 01/16] =?UTF-8?q?selectors=20such=20as=20`all=5Fcategorica?= =?UTF-8?q?l()`=20are=20now=20compatible=20with=20`gtsummary`=20=20version?= =?UTF-8?q?=20=E2=89=A5=202.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #270 --- DESCRIPTION | 4 +- NAMESPACE | 3 + NEWS.md | 5 ++ R/broom.helpers-package.R | 2 +- R/reexport.R | 4 ++ R/scope_tidy.R | 89 ++++++++++++++++++++++++++++ R/select_helpers.R | 86 ++++++++------------------- R/select_utilities.R | 21 ++++--- man/reexports.Rd | 3 +- man/scope_tidy.Rd | 43 ++++++++++++++ man/select_helpers.Rd | 25 +++++--- tests/testthat/test-select_helpers.R | 21 +------ 12 files changed, 203 insertions(+), 103 deletions(-) create mode 100644 R/scope_tidy.R create mode 100644 man/scope_tidy.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 61f7cd78..a05d149f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Depends: Imports: broom (>= 0.8), cli, - dplyr, + dplyr (>= 1.1.0), labelled, lifecycle, purrr, @@ -49,7 +49,7 @@ Suggests: glmmTMB, glue, gt, - gtsummary (>= 1.6.3), + gtsummary (>= 2.0.0), knitr, lavaan, lfe, diff --git a/NAMESPACE b/NAMESPACE index 958bee9a..44f6bf1e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -149,6 +149,7 @@ export(model_list_variables) export(num_range) export(one_of) export(plot_marginal_predictions) +export(scope_tidy) export(seq_range) export(starts_with) export(tidy_add_coefficients_type) @@ -185,6 +186,7 @@ export(tidy_zeroinfl) export(variables_to_contrast) export(variables_to_predict) export(vars) +export(where) importFrom(cli,cli_alert_danger) importFrom(cli,cli_alert_info) importFrom(cli,cli_code) @@ -201,6 +203,7 @@ importFrom(dplyr,num_range) importFrom(dplyr,one_of) importFrom(dplyr,starts_with) importFrom(dplyr,vars) +importFrom(dplyr,where) importFrom(lifecycle,deprecate_soft) importFrom(purrr,"%||%") importFrom(rlang,.data) diff --git a/NEWS.md b/NEWS.md index f36f4741..d121dadc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # broom.helpers (development version) +**Fixes** + +- selectors such as `all_categorical()` are now compatible with `gtsummary` + version ≥ 2.0.0 (#270) + # broom.helpers 1.16.0 **New features** diff --git a/R/broom.helpers-package.R b/R/broom.helpers-package.R index cce0bb59..0a527d5b 100644 --- a/R/broom.helpers-package.R +++ b/R/broom.helpers-package.R @@ -8,7 +8,7 @@ NULL # because `where` is not exported by tidyselect # cf. https://github.com/r-lib/tidyselect/issues/201 -utils::globalVariables(c(".", "where")) +utils::globalVariables(c(".")) # update named vectors, y values overriding x values if common name .update_vector <- function(x, y) { diff --git a/R/reexport.R b/R/reexport.R index 5741ccf1..9dfe8c7b 100644 --- a/R/reexport.R +++ b/R/reexport.R @@ -41,3 +41,7 @@ dplyr::last_col #' @importFrom dplyr one_of #' @export dplyr::one_of + +#' @importFrom dplyr where +#' @export +dplyr::where diff --git a/R/scope_tidy.R b/R/scope_tidy.R new file mode 100644 index 00000000..646cdbaa --- /dev/null +++ b/R/scope_tidy.R @@ -0,0 +1,89 @@ +#' Scoping a tidy tibble allowing to tidy select +#' +#' This function uses the information from a model tidy tibble to generate +#' a data frame exposing the different variables of the model, +#' data frame that could be used for tidy selection. In addition, columns +#' `"var_type"`, `"var_class"` and `"contrasts_type"` are scoped and their +#' values are added as attributes to the data frame. +#' For example, if `var_type='continuous'` for variable `"age"`, then the +#' attribute `attr(.$age, 'gtsummary.var_type') <- 'continuous'` is set. +#' That attribute is then used in a selector like `all_continuous()`. +#' Note: attributes are prefixed with `"gtsummary."` to be compatible with +#' selectors provided by `{gtsummary}`. +#' +#' @param x a tidy tibble, with a `"variable"` column, as returned by +#' `tidy_identify_variables ()` +#' @param data an optional data frame the attributes will be added to +#' @return a data frame +#' @export +#' @examples +#' mod <- lm(Sepal.Length ~ Sepal.Width * Species, data = iris) +#' tt <- mod |> tidy_and_attach() |> tidy_add_contrasts() +#' +#' scope_tidy(tt) |> str() +#' scope_tidy(tt, data = model_get_model_frame(mod)) |> str() +#' +#' scope_tidy(tt) |> dplyr::select(dplyr::starts_with("Se")) |> names() +#' scope_tidy(tt) |> dplyr::select(where(is.factor)) |> names() +#' scope_tidy(tt) |> dplyr::select(all_continuous()) |> names() +#' scope_tidy(tt) |> dplyr::select(all_contrasts()) |> names() +#' scope_tidy(tt) |> dplyr::select(all_interaction()) |> names() +#' scope_tidy(tt) |> dplyr::select(all_intercepts()) |> names() +scope_tidy <- function(x, data = NULL) { + if (!"variable" %in% names(x)) { + cli::cli_abort( + "The {.code .$x} data frame does not have the required {.val variable} column." + ) + } + + # if data not passed, use table_body to construct one + if (rlang::is_empty(data)) { + data <- dplyr::tibble(!!!rlang::rep_named(unique(x$variable), logical(0L))) + + # if var_class available in x, convert colums + if ("var_class" %in% names(x)) { + df_class <- x[c("variable", "var_class")] |> + unique() |> + tidyr::drop_na() + for (i in seq_len(nrow(df_class))) { + f <- switch ( + df_class$var_class[i], + "character" = as.character, + "factor" = as.factor, + "ordered" = as.ordered, + "integer" = as.integer, + "numeric" = as.numeric, + "complex" = as.complex, + "Date" = as.Date, + "POSIXlt" = as.POSIXlt, + "POSIXct" = as.POSIXct, + "difftime" = as.difftime, + as.logical + ) + data[[df_class$variable[i]]] <- f(NA) + } + } + } + + # only keeping rows that have corresponding column names in data + x <- x |> dplyr::filter(.data$variable %in% names(data)) + + # if x passed, add columns as attr to data + base_attr_cols <- c("var_type", "var_class", "contrasts_type") + attr_cols <- x |> + dplyr::select(any_of(base_attr_cols)) |> + names() + + # add attributes + for (v in attr_cols) { + df_attr <- x[c("variable", v)] |> + unique() |> + tidyr::drop_na() + for (i in seq_len(nrow(df_attr))) { + attr(data[[df_attr$variable[i]]], paste0("gtsummary.", v)) <- df_attr[[v]][i] + } + } + + # return data frame with attributes + data +} diff --git a/R/select_helpers.R b/R/select_helpers.R index f80f0930..e717714e 100644 --- a/R/select_helpers.R +++ b/R/select_helpers.R @@ -14,13 +14,17 @@ #' (see `vignette("broom_mixed_intro", package = "broom.mixed")`) #' @name select_helpers #' @rdname select_helpers -#' @param dichotomous Logical indicating whether to include dichotomous variables. -#' Default is `TRUE` +#' @param dichotomous logical indicating whether to include dichotomous +#' variables, default is `TRUE` #' @param contrasts_type type of contrast to select. When `NULL`, all variables with a #' contrast will be selected. Default is `NULL`. Select among contrast types -#' `c("treatment", "sum", "poly", "helmert", "other")` +#' `c("treatment", "sum", "poly", "helmert", "sdif", "other")` +#' @param continuous2 (for compatibility with `{gtsummary}`) logical indicating +#' whether to include continuous2 variables, default is `TRUE`, see +#' [`gtsummary::all_continuous2()`] #' #' @return A character vector of column names selected +#' @seealso [scope_tidy()] #' @examplesIf interactive() #' glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) |> #' tidy_plus_plus(exponentiate = TRUE, include = all_categorical()) @@ -38,95 +42,53 @@ NULL #' @rdname select_helpers #' @export -all_continuous <- function() { - .generic_selector("variable", "var_type", - startsWith(.data$var_type, "continuous"), - fun_name = "all_continuous" - ) +all_continuous <- function(continuous2 = TRUE) { + types <- if (continuous2) c("continuous", "continuous2") else "continuous" + + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% types)) } #' @rdname select_helpers #' @export -all_dichotomous <- function() { - .generic_selector("variable", "var_type", - .data$var_type %in% "dichotomous", - fun_name = "all_dichotomous" - ) +all_categorical <- function(dichotomous = TRUE) { + types <- if (dichotomous) c("categorical", "dichotomous") else "categorical" + + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% types)) } #' @rdname select_helpers #' @export -all_categorical <- function(dichotomous = TRUE) { - types <- switch(dichotomous, - c("categorical", "dichotomous") - ) %||% "categorical" - - .generic_selector("variable", "var_type", - .data$var_type %in% .env$types, - fun_name = "all_categorical" - ) +all_dichotomous <- function() { + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% "dichotomous")) } #' @rdname select_helpers #' @export all_interaction <- function() { - .generic_selector("variable", "var_type", - .data$var_type %in% "interaction", - fun_name = "all_interaction" - ) + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% "interaction")) } #' @rdname select_helpers #' @export all_ran_pars <- function() { - .generic_selector("variable", "var_type", - .data$var_type %in% "ran_pars", - fun_name = "all_ran_pars" - ) + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% "ran_pars")) } #' @rdname select_helpers #' @export all_ran_vals <- function() { - .generic_selector("variable", "var_type", - .data$var_type %in% "ran_vals", - fun_name = "all_ran_vals" - ) + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% "ran_vals")) } - #' @rdname select_helpers #' @export all_intercepts <- function() { - .generic_selector("variable", "var_type", - .data$var_type %in% "intercept", - fun_name = "all_intercepts" - ) + where(function(x) isTRUE(attr(x, "gtsummary.var_type") %in% "intercept")) } #' @rdname select_helpers #' @export -all_contrasts <- function(contrasts_type = NULL) { - # if no types specified, select all contrasts - if (is.null(contrasts_type)) { - return( - .generic_selector("variable", "contrasts_type", - !is.na(.data$contrasts_type), - fun_name = "all_contrasts" - ) - ) - # otherwise, select those specified in `contrasts_type=` - } else { - contrasts_type <- - match.arg(contrasts_type, - c("treatment", "sum", "poly", "helmert", "other"), - several.ok = TRUE - ) - return( - .generic_selector("variable", "contrasts_type", - .data$contrasts_type %in% .env$contrasts_type, - fun_name = "all_contrasts" - ) - ) - } +all_contrasts <- function(contrasts_type = c("treatment", "sum", "poly", "helmert", "sdif", "other")) { + contrasts_type <- rlang::arg_match(contrasts_type, multiple = TRUE) + where(function(x) isTRUE(attr(x, "gtsummary.contrasts_type") %in% contrasts_type)) } diff --git a/R/select_utilities.R b/R/select_utilities.R index c825a213..17556e4a 100644 --- a/R/select_utilities.R +++ b/R/select_utilities.R @@ -230,15 +230,18 @@ return(NULL) } - # convert var_info to data frame if data not provided ------------------------ - if (is.null(data)) data <- .var_info_to_df(var_info) - - if (!is.null(var_info)) { - # scoping the variable types - .scope_var_info(var_info) - # un-scoping on exit - on.exit(rm(list = ls(envir = env_variable_type), envir = env_variable_type)) - } + # if var_info is provided, scope it + if (!is.null(var_info)) data <- scope_tidy(var_info, data) + + # # convert var_info to data frame if data not provided ------------------------ + # if (is.null(data)) data <- .var_info_to_df(var_info) + # + # if (!is.null(var_info)) { + # # scoping the variable types + # .scope_var_info(var_info) + # # un-scoping on exit + # on.exit(rm(list = ls(envir = env_variable_type), envir = env_variable_type)) + # } # determine if selecting input begins with `var()` select_input_starts_var <- diff --git a/man/reexports.Rd b/man/reexports.Rd index 9355b393..3077f856 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -14,6 +14,7 @@ \alias{everything} \alias{last_col} \alias{one_of} +\alias{where} \title{Objects exported from other packages} \keyword{internal} \description{ @@ -21,6 +22,6 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{dplyr}{\code{\link[dplyr:reexports]{all_of}}, \code{\link[dplyr:reexports]{any_of}}, \code{\link[dplyr:reexports]{contains}}, \code{\link[dplyr:reexports]{ends_with}}, \code{\link[dplyr:reexports]{everything}}, \code{\link[dplyr:reexports]{last_col}}, \code{\link[dplyr:reexports]{matches}}, \code{\link[dplyr:reexports]{num_range}}, \code{\link[dplyr:reexports]{one_of}}, \code{\link[dplyr:reexports]{starts_with}}, \code{\link[dplyr]{vars}}} + \item{dplyr}{\code{\link[dplyr:reexports]{all_of}}, \code{\link[dplyr:reexports]{any_of}}, \code{\link[dplyr:reexports]{contains}}, \code{\link[dplyr:reexports]{ends_with}}, \code{\link[dplyr:reexports]{everything}}, \code{\link[dplyr:reexports]{last_col}}, \code{\link[dplyr:reexports]{matches}}, \code{\link[dplyr:reexports]{num_range}}, \code{\link[dplyr:reexports]{one_of}}, \code{\link[dplyr:reexports]{starts_with}}, \code{\link[dplyr]{vars}}, \code{\link[dplyr:reexports]{where}}} }} diff --git a/man/scope_tidy.Rd b/man/scope_tidy.Rd new file mode 100644 index 00000000..dc4e166e --- /dev/null +++ b/man/scope_tidy.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scope_tidy.R +\name{scope_tidy} +\alias{scope_tidy} +\title{Scoping a tidy tibble allowing to tidy select} +\usage{ +scope_tidy(x, data = NULL) +} +\arguments{ +\item{x}{a tidy tibble, with a \code{"variable"} column, as returned by +\code{tidy_identify_variables ()}} + +\item{data}{an optional data frame the attributes will be added to} +} +\value{ +a data frame +} +\description{ +This function uses the information from a model tidy tibble to generate +a data frame exposing the different variables of the model, +data frame that could be used for tidy selection. In addition, columns +\code{"var_type"}, \code{"var_class"} and \code{"contrasts_type"} are scoped and their +values are added as attributes to the data frame. +For example, if \code{var_type='continuous'} for variable \code{"age"}, then the +attribute \code{attr(.$age, 'gtsummary.var_type') <- 'continuous'} is set. +That attribute is then used in a selector like \code{all_continuous()}. +Note: attributes are prefixed with \code{"gtsummary."} to be compatible with +selectors provided by \code{{gtsummary}}. +} +\examples{ +mod <- lm(Sepal.Length ~ Sepal.Width * Species, data = iris) +tt <- mod |> tidy_and_attach() |> tidy_add_contrasts() + +scope_tidy(tt) |> str() +scope_tidy(tt, data = model_get_model_frame(mod)) |> str() + +scope_tidy(tt) |> dplyr::select(dplyr::starts_with("Se")) |> names() +scope_tidy(tt) |> dplyr::select(where(is.factor)) |> names() +scope_tidy(tt) |> dplyr::select(all_continuous()) |> names() +scope_tidy(tt) |> dplyr::select(all_contrasts()) |> names() +scope_tidy(tt) |> dplyr::select(all_interaction()) |> names() +scope_tidy(tt) |> dplyr::select(all_intercepts()) |> names() +} diff --git a/man/select_helpers.Rd b/man/select_helpers.Rd index a0d6b247..0e95e345 100644 --- a/man/select_helpers.Rd +++ b/man/select_helpers.Rd @@ -3,8 +3,8 @@ \name{select_helpers} \alias{select_helpers} \alias{all_continuous} -\alias{all_dichotomous} \alias{all_categorical} +\alias{all_dichotomous} \alias{all_interaction} \alias{all_ran_pars} \alias{all_ran_vals} @@ -12,12 +12,12 @@ \alias{all_contrasts} \title{Select helper functions} \usage{ -all_continuous() - -all_dichotomous() +all_continuous(continuous2 = TRUE) all_categorical(dichotomous = TRUE) +all_dichotomous() + all_interaction() all_ran_pars() @@ -26,15 +26,21 @@ all_ran_vals() all_intercepts() -all_contrasts(contrasts_type = NULL) +all_contrasts( + contrasts_type = c("treatment", "sum", "poly", "helmert", "sdif", "other") +) } \arguments{ -\item{dichotomous}{Logical indicating whether to include dichotomous variables. -Default is \code{TRUE}} +\item{continuous2}{(for compatibility with \code{{gtsummary}}) logical indicating +whether to include continuous2 variables, default is \code{TRUE}, see +\code{\link[gtsummary:select_helpers]{gtsummary::all_continuous2()}}} + +\item{dichotomous}{logical indicating whether to include dichotomous +variables, default is \code{TRUE}} \item{contrasts_type}{type of contrast to select. When \code{NULL}, all variables with a contrast will be selected. Default is \code{NULL}. Select among contrast types -\code{c("treatment", "sum", "poly", "helmert", "other")}} +\code{c("treatment", "sum", "poly", "helmert", "sdif", "other")}} } \value{ A character vector of column names selected @@ -71,3 +77,6 @@ glm(response ~ age + trt + grade + stage, ) \dontshow{\}) # examplesIf} } +\seealso{ +\code{\link[=scope_tidy]{scope_tidy()}} +} diff --git a/tests/testthat/test-select_helpers.R b/tests/testthat/test-select_helpers.R index 3865dc89..0bef4ef7 100644 --- a/tests/testthat/test-select_helpers.R +++ b/tests/testthat/test-select_helpers.R @@ -4,7 +4,7 @@ test_that("select_helpers: .select_to_varnames", { ) expect_equal( - .select_to_varnames(select = vars(hp, mpg), data = mtcars), + .select_to_varnames(select = c(hp, mpg), data = mtcars), dplyr::select(mtcars, hp, mpg) |> colnames() ) @@ -262,25 +262,6 @@ test_that("select_helpers: .select_to_varnames", { ) }) -test_that("select_helpers: .generic_selector ", { - mod <- glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) - - expect_error( - tidy_and_attach(mod) |> - tidy_identify_variables() |> - tidy_add_variable_labels(labels = all_contrasts("helmert") ~ "HELMERT!") - ) - - expect_error( - all_continuous() - ) - - expect_equal( - .var_info_to_df(letters) |> names(), - letters - ) -}) - test_that("select_helpers: .formula_list_to_named_list ", { mod <- glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) tidy_mod <- tidy_plus_plus(mod) From 0d77dd5b6b88db5a30a89a76adee06fc9e9bb17f Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Thu, 22 Aug 2024 16:56:44 +0200 Subject: [PATCH 02/16] lint --- R/scope_tidy.R | 2 +- R/select_helpers.R | 2 +- R/select_utilities.R | 10 ---------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/R/scope_tidy.R b/R/scope_tidy.R index 646cdbaa..21b8c360 100644 --- a/R/scope_tidy.R +++ b/R/scope_tidy.R @@ -46,7 +46,7 @@ scope_tidy <- function(x, data = NULL) { unique() |> tidyr::drop_na() for (i in seq_len(nrow(df_class))) { - f <- switch ( + f <- switch( df_class$var_class[i], "character" = as.character, "factor" = as.factor, diff --git a/R/select_helpers.R b/R/select_helpers.R index e717714e..cf228374 100644 --- a/R/select_helpers.R +++ b/R/select_helpers.R @@ -88,7 +88,7 @@ all_intercepts <- function() { #' @rdname select_helpers #' @export -all_contrasts <- function(contrasts_type = c("treatment", "sum", "poly", "helmert", "sdif", "other")) { +all_contrasts <- function(contrasts_type = c("treatment", "sum", "poly", "helmert", "sdif", "other")) { # nolint contrasts_type <- rlang::arg_match(contrasts_type, multiple = TRUE) where(function(x) isTRUE(attr(x, "gtsummary.contrasts_type") %in% contrasts_type)) } diff --git a/R/select_utilities.R b/R/select_utilities.R index 17556e4a..f29ec9ac 100644 --- a/R/select_utilities.R +++ b/R/select_utilities.R @@ -233,16 +233,6 @@ # if var_info is provided, scope it if (!is.null(var_info)) data <- scope_tidy(var_info, data) - # # convert var_info to data frame if data not provided ------------------------ - # if (is.null(data)) data <- .var_info_to_df(var_info) - # - # if (!is.null(var_info)) { - # # scoping the variable types - # .scope_var_info(var_info) - # # un-scoping on exit - # on.exit(rm(list = ls(envir = env_variable_type), envir = env_variable_type)) - # } - # determine if selecting input begins with `var()` select_input_starts_var <- !rlang::quo_is_symbol(select) && # if not a symbol (ie name) From c4d825efdefc804b4d1602b2903aca3eb5e4f2c0 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Thu, 22 Aug 2024 17:06:00 +0200 Subject: [PATCH 03/16] pkgdown --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index c07ace8f..32494b0e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -71,6 +71,7 @@ reference: - title: Variable type selectors - contents: - starts_with("all_") + - scope_tidy - title: Exported utility functions - contents: From 97e4ad3d3cae27aae473dcb3c21596beb7cccb9d Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Thu, 22 Aug 2024 18:12:01 +0200 Subject: [PATCH 04/16] in some cases x$variable could be a factor --- R/scope_tidy.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/scope_tidy.R b/R/scope_tidy.R index 21b8c360..ba4ecdad 100644 --- a/R/scope_tidy.R +++ b/R/scope_tidy.R @@ -38,7 +38,12 @@ scope_tidy <- function(x, data = NULL) { # if data not passed, use table_body to construct one if (rlang::is_empty(data)) { - data <- dplyr::tibble(!!!rlang::rep_named(unique(x$variable), logical(0L))) + data <- dplyr::tibble( + !!!rlang::rep_named( + unique(as.character(x$variable)), + logical(0L) + ) + ) # if var_class available in x, convert colums if ("var_class" %in% names(x)) { From e8842325c669cc020f28df8f509772c64a7990f3 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Thu, 22 Aug 2024 21:02:50 +0200 Subject: [PATCH 05/16] testing better doc --- R/tidy_plus_plus.R | 113 +++++++++++-------- R/tidy_select_variables.R | 9 +- man/tidy_add_estimate_to_reference_rows.Rd | 5 +- man/tidy_add_header_rows.Rd | 10 +- man/tidy_add_pairwise_contrasts.Rd | 10 +- man/tidy_add_reference_rows.Rd | 5 +- man/tidy_add_term_labels.Rd | 10 +- man/tidy_add_variable_labels.Rd | 10 +- man/tidy_disambiguate_terms.Rd | 5 +- man/tidy_identify_variables.Rd | 5 +- man/tidy_plus_plus.Rd | 119 ++++++++++++--------- man/tidy_select_variables.Rd | 9 +- 12 files changed, 183 insertions(+), 127 deletions(-) diff --git a/R/tidy_plus_plus.R b/R/tidy_plus_plus.R index 3e96426f..b5e108dd 100644 --- a/R/tidy_plus_plus.R +++ b/R/tidy_plus_plus.R @@ -17,57 +17,78 @@ #' * [tidy_add_coefficients_type()] #' * [tidy_detach_model()] #' -#' @param model a model to be attached/tidied -#' @param tidy_fun option to specify a custom tidier function -#' @param conf.int should confidence intervals be computed? (see [broom::tidy()]) -#' @param conf.level level of confidence for confidence intervals (default: 95%) -#' @param exponentiate logical indicating whether or not to exponentiate the -#' coefficient estimates. This is typical for logistic, Poisson and Cox models, +#' @param model A model to be attached/tidied. +#' @param tidy_fun (`function`)\cr +#' Option to specify a custom tidier function. +#' @param conf.int (`logical`)\cr +#' Should confidence intervals be computed? (see [broom::tidy()]) +#' @param conf.level (`numeric`)\cr +#' Level of confidence for confidence intervals (default: 95%). +#' @param exponentiate (`logical`)\cr +#' Whether or not to exponentiate the coefficient estimates. +#' This is typical for logistic, Poisson and Cox models, #' but a bad idea if there is no log or logit link; defaults to `FALSE`. -#' @param model_matrix_attr logical indicating whether model frame and model -#' matrix should be added as attributes of `model` (respectively named -#' `"model_frame"` and `"model_matrix"`) and passed through -#' @param variable_labels a named list or a named vector of custom variable labels -#' @param term_labels a named list or a named vector of custom term labels -#' @param interaction_sep separator for interaction terms -#' @param categorical_terms_pattern a [glue pattern][glue::glue()] for -#' labels of categorical terms with treatment or sum contrasts -#' (see [model_list_terms_levels()]) -#' @param disambiguate_terms should terms be disambiguated with +#' @param model_matrix_attr (`logical`)\cr +#' Whether model frame and model matrix should be added as attributes of `model` +#' (respectively named `"model_frame"` and `"model_matrix"`) and passed through. +#' @param variable_labels ([`formula-list-selector`][gtsummary::syntax])\cr +#' A named list or a named vector of custom variable labels. +#' @param term_labels (`list` or `vector`)\cr +#' A named list or a named vector of custom term labels. +#' @param interaction_sep (`string`)\cr +#' Separator for interaction terms. +#' @param categorical_terms_pattern (`string`)\cr +#' A [glue pattern][glue::glue()] for labels of categorical terms with treatment +#' or sum contrasts (see [model_list_terms_levels()]). +#' @param disambiguate_terms (`logical`)\cr +#' Should terms be disambiguated with #' [tidy_disambiguate_terms()]? (default `TRUE`) -#' @param disambiguate_sep separator for [tidy_disambiguate_terms()] -#' @param add_reference_rows should reference rows be added? -#' @param no_reference_row variables (accepts [tidyselect][dplyr::select] notation) -#' for those no reference row should be added, when `add_reference_rows = TRUE` -#' @param add_pairwise_contrasts apply [tidy_add_pairwise_contrasts()]? -#' `r lifecycle::badge("experimental")` -#' @param pairwise_variables variables to add pairwise contrasts -#' (accepts [tidyselect][dplyr::select] notation) -#' @param keep_model_terms keep original model terms for variables where +#' @param disambiguate_sep (`string`)\cr +#' Separator for [tidy_disambiguate_terms()]. +#' @param add_reference_rows (`logical`)\cr +#' Should reference rows be added? +#' @param no_reference_row ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables for those no reference row should be added, +#' when `add_reference_rows = TRUE`. +#' @param add_pairwise_contrasts (`logical`)\cr +#' Apply [tidy_add_pairwise_contrasts()]? +#' @param pairwise_variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables to add pairwise contrasts. +#' @param keep_model_terms (`logical`)\cr +#' Keep original model terms for variables where #' pairwise contrasts are added? (default is `FALSE`) -#' @param pairwise_reverse determines whether to use `"pairwise"` (if `TRUE`) -#' or `"revpairwise"` (if `FALSE`), see [emmeans::contrast()] -#' @param contrasts_adjust optional adjustment method when computing contrasts, -#' see [emmeans::contrast()] (if `NULL`, use `emmeans` default) -#' @param emmeans_args list of additional parameter to pass to -#' [emmeans::emmeans()] when computing pairwise contrasts -#' @param add_estimate_to_reference_rows should an estimate value be added -#' to reference rows? -#' @param add_header_rows should header rows be added? -#' @param show_single_row variables that should be displayed -#' on a single row (accepts [tidyselect][dplyr::select] notation), when -#' `add_header_rows` is `TRUE` -#' @param add_n should the number of observations be added? -#' @param intercept should the intercept(s) be included? +#' @param pairwise_reverse (`logical`)\cr +#' Determines whether to use `"pairwise"` (if `TRUE`) +#' or `"revpairwise"` (if `FALSE`), see [emmeans::contrast()]. +#' @param contrasts_adjust (`string`)\cr +#' Optional adjustment method when computing contrasts, +#' see [emmeans::contrast()] (if `NULL`, use `emmeans` default). +#' @param emmeans_args (`list`)\cr +#' List of additional parameter to pass to +#' [emmeans::emmeans()] when computing pairwise contrasts. +#' @param add_estimate_to_reference_rows (`logical`)\cr +#' Should an estimate value be added to reference rows? +#' @param add_header_rows (`logical`)\cr +#' Should header rows be added? +#' @param show_single_row ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables that should be displayed on a single row, +#' when `add_header_rows` is `TRUE`. +#' @param add_n (`logical`)\cr +#' Should the number of observations be added? +#' @param intercept (`logical`)\cr +#' Should the intercept(s) be included? #' @inheritParams tidy_select_variables -#' @param keep_model should the model be kept as an attribute of the final -#' result? -#' @param tidy_post_fun custom function applied to the results at the end of +#' @param keep_model (`logical`)\cr +#' Should the model be kept as an attribute of the final result? +#' @param tidy_post_fun (`function`)\cr +#' Custom function applied to the results at the end of #' `tidy_plus_plus()` (see note) -#' @param quiet logical argument whether broom.helpers should not return -#' a message when requested output cannot be generated. Default is `FALSE` -#' @param strict logical argument whether broom.helpers should return an error -#' when requested output cannot be generated. Default is `FALSE` +#' @param quiet (`logical`)\cr +#' Whether `broom.helpers` should not return a message when requested output +#' cannot be generated. Default is `FALSE`. +#' @param strict (`logical`)\cr +#' Whether `broom.helpers` should return an error +#' when requested output cannot be generated. Default is `FALSE`. #' @param ... other arguments passed to `tidy_fun()` #' @note #' `tidy_post_fun` is applied to the result at the end of `tidy_plus_plus()` diff --git a/R/tidy_select_variables.R b/R/tidy_select_variables.R index aaeec90a..f8696971 100644 --- a/R/tidy_select_variables.R +++ b/R/tidy_select_variables.R @@ -6,11 +6,12 @@ #' @details #' If the `variable` column is not yet available in `x`, #' [tidy_identify_variables()] will be automatically applied. -#' @param x a tidy tibble -#' @param include variables to include. Accepts [tidyselect][dplyr::select] -#' syntax. Use `-` to remove a variable. Default is `everything()`. +#' @param x (`data.frame`)\cr +#' A tidy tibble. +#' @param include ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables to include. Default is `everything()`. #' See also [all_continuous()], [all_categorical()], [all_dichotomous()] -#' and [all_interaction()] +#' and [all_interaction()]. #' @return #' The `x` tibble limited to the included variables (and eventually the intercept), #' sorted according to the `include` parameter. diff --git a/man/tidy_add_estimate_to_reference_rows.Rd b/man/tidy_add_estimate_to_reference_rows.Rd index cb5acc29..c957b8ec 100644 --- a/man/tidy_add_estimate_to_reference_rows.Rd +++ b/man/tidy_add_estimate_to_reference_rows.Rd @@ -24,8 +24,9 @@ previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}, used only for s \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} } \description{ For categorical variables with a treatment contrast diff --git a/man/tidy_add_header_rows.Rd b/man/tidy_add_header_rows.Rd index d6fe2dfb..b958a871 100644 --- a/man/tidy_add_header_rows.Rd +++ b/man/tidy_add_header_rows.Rd @@ -22,11 +22,13 @@ See also \code{\link[=all_dichotomous]{all_dichotomous()}}} \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} -\item{strict}{logical argument whether broom.helpers should return an error -when requested output cannot be generated. Default is \code{FALSE}} +\item{strict}{(\code{logical})\cr +Whether \code{broom.helpers} should return an error +when requested output cannot be generated. Default is \code{FALSE}.} } \description{ For variables with several terms (usually categorical variables but diff --git a/man/tidy_add_pairwise_contrasts.Rd b/man/tidy_add_pairwise_contrasts.Rd index 86c1c7e7..992a26ac 100644 --- a/man/tidy_add_pairwise_contrasts.Rd +++ b/man/tidy_add_pairwise_contrasts.Rd @@ -34,13 +34,15 @@ see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \co \item{conf.level}{confidence level, by default use the value indicated previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}} -\item{emmeans_args}{list of additional parameter to pass to -\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts} +\item{emmeans_args}{(\code{list})\cr +List of additional parameter to pass to +\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts.} \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_add_reference_rows.Rd b/man/tidy_add_reference_rows.Rd index 27e51ee6..b5c0acb3 100644 --- a/man/tidy_add_reference_rows.Rd +++ b/man/tidy_add_reference_rows.Rd @@ -21,8 +21,9 @@ See also \code{\link[=all_categorical]{all_categorical()}} and \code{\link[=all_ \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} } \description{ For categorical variables with a treatment contrast diff --git a/man/tidy_add_term_labels.Rd b/man/tidy_add_term_labels.Rd index b5aebd02..3c167384 100644 --- a/man/tidy_add_term_labels.Rd +++ b/man/tidy_add_term_labels.Rd @@ -28,11 +28,13 @@ labels of categorical terms with treatment or sum contrasts \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} -\item{strict}{logical argument whether broom.helpers should return an error -when requested output cannot be generated. Default is \code{FALSE}} +\item{strict}{(\code{logical})\cr +Whether \code{broom.helpers} should return an error +when requested output cannot be generated. Default is \code{FALSE}.} } \description{ Will add term labels in a \code{label} column, based on: diff --git a/man/tidy_add_variable_labels.Rd b/man/tidy_add_variable_labels.Rd index 4b1adc77..9346430a 100644 --- a/man/tidy_add_variable_labels.Rd +++ b/man/tidy_add_variable_labels.Rd @@ -23,11 +23,13 @@ custom variable labels} \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} -\item{strict}{logical argument whether broom.helpers should return an error -when requested output cannot be generated. Default is \code{FALSE}} +\item{strict}{(\code{logical})\cr +Whether \code{broom.helpers} should return an error +when requested output cannot be generated. Default is \code{FALSE}.} } \description{ Will add variable labels in a \code{var_label} column, based on: diff --git a/man/tidy_disambiguate_terms.Rd b/man/tidy_disambiguate_terms.Rd index 2b1ac635..65711dd9 100644 --- a/man/tidy_disambiguate_terms.Rd +++ b/man/tidy_disambiguate_terms.Rd @@ -13,8 +13,9 @@ tidy_disambiguate_terms(x, sep = ".", model = tidy_get_model(x), quiet = FALSE) \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} } \description{ For mixed models, the \code{term} column returned by \code{broom.mixed} may have diff --git a/man/tidy_identify_variables.Rd b/man/tidy_identify_variables.Rd index d8345f76..1b74192b 100644 --- a/man/tidy_identify_variables.Rd +++ b/man/tidy_identify_variables.Rd @@ -11,8 +11,9 @@ tidy_identify_variables(x, model = tidy_get_model(x), quiet = FALSE) \item{model}{the corresponding model, if not attached to \code{x}} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} } \description{ \code{tidy_identify_variables()} will add to the tidy tibble diff --git a/man/tidy_plus_plus.Rd b/man/tidy_plus_plus.Rd index 9e91d245..46073619 100644 --- a/man/tidy_plus_plus.Rd +++ b/man/tidy_plus_plus.Rd @@ -39,89 +39,110 @@ tidy_plus_plus( ) } \arguments{ -\item{model}{a model to be attached/tidied} +\item{model}{A model to be attached/tidied.} -\item{tidy_fun}{option to specify a custom tidier function} +\item{tidy_fun}{(\code{function})\cr +Option to specify a custom tidier function.} -\item{conf.int}{should confidence intervals be computed? (see \code{\link[broom:reexports]{broom::tidy()}})} +\item{conf.int}{(\code{logical})\cr +Should confidence intervals be computed? (see \code{\link[broom:reexports]{broom::tidy()}})} -\item{conf.level}{level of confidence for confidence intervals (default: 95\%)} +\item{conf.level}{(\code{numeric})\cr +Level of confidence for confidence intervals (default: 95\%).} -\item{exponentiate}{logical indicating whether or not to exponentiate the -coefficient estimates. This is typical for logistic, Poisson and Cox models, +\item{exponentiate}{(\code{logical})\cr +Whether or not to exponentiate the coefficient estimates. +This is typical for logistic, Poisson and Cox models, but a bad idea if there is no log or logit link; defaults to \code{FALSE}.} -\item{model_matrix_attr}{logical indicating whether model frame and model -matrix should be added as attributes of \code{model} (respectively named -\code{"model_frame"} and \code{"model_matrix"}) and passed through} +\item{model_matrix_attr}{(\code{logical})\cr +Whether model frame and model matrix should be added as attributes of \code{model} +(respectively named \code{"model_frame"} and \code{"model_matrix"}) and passed through.} -\item{variable_labels}{a named list or a named vector of custom variable labels} +\item{variable_labels}{(\code{\link[gtsummary:syntax]{formula-list-selector}})\cr +A named list or a named vector of custom variable labels.} -\item{term_labels}{a named list or a named vector of custom term labels} +\item{term_labels}{(\code{list} or \code{vector})\cr +A named list or a named vector of custom term labels.} -\item{interaction_sep}{separator for interaction terms} +\item{interaction_sep}{(\code{string})\cr +Separator for interaction terms.} -\item{categorical_terms_pattern}{a \link[glue:glue]{glue pattern} for -labels of categorical terms with treatment or sum contrasts -(see \code{\link[=model_list_terms_levels]{model_list_terms_levels()}})} +\item{categorical_terms_pattern}{(\code{string})\cr +A \link[glue:glue]{glue pattern} for labels of categorical terms with treatment +or sum contrasts (see \code{\link[=model_list_terms_levels]{model_list_terms_levels()}}).} -\item{disambiguate_terms}{should terms be disambiguated with +\item{disambiguate_terms}{(\code{logical})\cr +Should terms be disambiguated with \code{\link[=tidy_disambiguate_terms]{tidy_disambiguate_terms()}}? (default \code{TRUE})} -\item{disambiguate_sep}{separator for \code{\link[=tidy_disambiguate_terms]{tidy_disambiguate_terms()}}} +\item{disambiguate_sep}{(\code{string})\cr +Separator for \code{\link[=tidy_disambiguate_terms]{tidy_disambiguate_terms()}}.} -\item{add_reference_rows}{should reference rows be added?} +\item{add_reference_rows}{(\code{logical})\cr +Should reference rows be added?} -\item{no_reference_row}{variables (accepts \link[dplyr:select]{tidyselect} notation) -for those no reference row should be added, when \code{add_reference_rows = TRUE}} +\item{no_reference_row}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables for those no reference row should be added, +when \code{add_reference_rows = TRUE}.} -\item{add_pairwise_contrasts}{apply \code{\link[=tidy_add_pairwise_contrasts]{tidy_add_pairwise_contrasts()}}? -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}} +\item{add_pairwise_contrasts}{(\code{logical})\cr +Apply \code{\link[=tidy_add_pairwise_contrasts]{tidy_add_pairwise_contrasts()}}?} -\item{pairwise_variables}{variables to add pairwise contrasts -(accepts \link[dplyr:select]{tidyselect} notation)} +\item{pairwise_variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables to add pairwise contrasts.} -\item{keep_model_terms}{keep original model terms for variables where +\item{keep_model_terms}{(\code{logical})\cr +Keep original model terms for variables where pairwise contrasts are added? (default is \code{FALSE})} -\item{pairwise_reverse}{determines whether to use \code{"pairwise"} (if \code{TRUE}) -or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}} +\item{pairwise_reverse}{(\code{logical})\cr +Determines whether to use \code{"pairwise"} (if \code{TRUE}) +or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}.} -\item{contrasts_adjust}{optional adjustment method when computing contrasts, -see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default)} +\item{contrasts_adjust}{(\code{string})\cr +Optional adjustment method when computing contrasts, +see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default).} -\item{emmeans_args}{list of additional parameter to pass to -\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts} +\item{emmeans_args}{(\code{list})\cr +List of additional parameter to pass to +\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts.} -\item{add_estimate_to_reference_rows}{should an estimate value be added -to reference rows?} +\item{add_estimate_to_reference_rows}{(\code{logical})\cr +Should an estimate value be added to reference rows?} -\item{add_header_rows}{should header rows be added?} +\item{add_header_rows}{(\code{logical})\cr +Should header rows be added?} -\item{show_single_row}{variables that should be displayed -on a single row (accepts \link[dplyr:select]{tidyselect} notation), when -\code{add_header_rows} is \code{TRUE}} +\item{show_single_row}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables that should be displayed on a single row, +when \code{add_header_rows} is \code{TRUE}.} -\item{add_n}{should the number of observations be added?} +\item{add_n}{(\code{logical})\cr +Should the number of observations be added?} -\item{intercept}{should the intercept(s) be included?} +\item{intercept}{(\code{logical})\cr +Should the intercept(s) be included?} -\item{include}{variables to include. Accepts \link[dplyr:select]{tidyselect} -syntax. Use \code{-} to remove a variable. Default is \code{everything()}. +\item{include}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables to include. Default is \code{everything()}. See also \code{\link[=all_continuous]{all_continuous()}}, \code{\link[=all_categorical]{all_categorical()}}, \code{\link[=all_dichotomous]{all_dichotomous()}} -and \code{\link[=all_interaction]{all_interaction()}}} +and \code{\link[=all_interaction]{all_interaction()}}.} -\item{keep_model}{should the model be kept as an attribute of the final -result?} +\item{keep_model}{(\code{logical})\cr +Should the model be kept as an attribute of the final result?} -\item{tidy_post_fun}{custom function applied to the results at the end of +\item{tidy_post_fun}{(\code{function})\cr +Custom function applied to the results at the end of \code{tidy_plus_plus()} (see note)} -\item{quiet}{logical argument whether broom.helpers should not return -a message when requested output cannot be generated. Default is \code{FALSE}} +\item{quiet}{(\code{logical})\cr +Whether \code{broom.helpers} should not return a message when requested output +cannot be generated. Default is \code{FALSE}.} -\item{strict}{logical argument whether broom.helpers should return an error -when requested output cannot be generated. Default is \code{FALSE}} +\item{strict}{(\code{logical})\cr +Whether \code{broom.helpers} should return an error +when requested output cannot be generated. Default is \code{FALSE}.} \item{...}{other arguments passed to \code{tidy_fun()}} } diff --git a/man/tidy_select_variables.Rd b/man/tidy_select_variables.Rd index 1a5d3b1a..d48658e2 100644 --- a/man/tidy_select_variables.Rd +++ b/man/tidy_select_variables.Rd @@ -7,12 +7,13 @@ tidy_select_variables(x, include = everything(), model = tidy_get_model(x)) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble.} -\item{include}{variables to include. Accepts \link[dplyr:select]{tidyselect} -syntax. Use \code{-} to remove a variable. Default is \code{everything()}. +\item{include}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables to include. Default is \code{everything()}. See also \code{\link[=all_continuous]{all_continuous()}}, \code{\link[=all_categorical]{all_categorical()}}, \code{\link[=all_dichotomous]{all_dichotomous()}} -and \code{\link[=all_interaction]{all_interaction()}}} +and \code{\link[=all_interaction]{all_interaction()}}.} \item{model}{the corresponding model, if not attached to \code{x}} } From 59dd5d2600d0cd99ff4b279e2cce6356be272a71 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 12:02:36 +0200 Subject: [PATCH 06/16] deprecation of `.select_to_varnames()`, `.formula_list_to_named_list()`, `.generic_selector()` and `.is_selector_scoped()` --- DESCRIPTION | 1 + NEWS.md | 8 ++++++++ R/select_utilities.R | 29 ++++++++++++++++++++++++++- man/dot-formula_list_to_named_list.Rd | 6 ++++++ man/dot-generic_selector.Rd | 3 ++- man/dot-select_to_varnames.Rd | 6 ++++++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a05d149f..c4ecbe4a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,7 @@ Depends: R (>= 4.2) Imports: broom (>= 0.8), + cards, cli, dplyr (>= 1.1.0), labelled, diff --git a/NEWS.md b/NEWS.md index a921acd5..ca526069 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,14 @@ version ≥ 2.0.0 (#270) - `model_get_model_frame.coxph()` has been fixed to return a correct model frame a subject identifier is passed to `survival::coxph()` (#268) + +**Deprecated functions** + +- `.select_to_varnames()`, `.formula_list_to_named_list()`, + `.generic_selector()` and `.is_selector_scoped()` are now deprecated and + will be removed in a future release: you may consider + `cards::process_selectors()` and `cards::process_formula_selectors()` as + alternatives (#270) # broom.helpers 1.16.0 diff --git a/R/select_utilities.R b/R/select_utilities.R index f29ec9ac..6958dfb9 100644 --- a/R/select_utilities.R +++ b/R/select_utilities.R @@ -1,5 +1,9 @@ #' Convert formula selector to a named list #' +#' `r lifecycle::badge("deprecated")`\cr +#' This function will soon be removed from `broom.helpers`. Please consider +#' [`cards::process_formula_selectors()`] as an alternative. +#' #' Functions takes a list of formulas, a named list, or a combination of named #' elements with formula elements and returns a named list. #' For example, `list(age = 1, starts_with("stage") ~ 2)`. @@ -23,12 +27,18 @@ #' @param null_allowed Are `NULL` values accepted for the right hand side of #' formulas? #' @inheritParams .select_to_varnames -#' +#' @keywords internal #' @export .formula_list_to_named_list <- function(x, data = NULL, var_info = NULL, arg_name = NULL, select_single = FALSE, type_check = NULL, type_check_msg = NULL, null_allowed = TRUE) { + lifecycle::deprecate_soft( + "1.17.0", + ".formula_list_to_named_list()", + "cards::process_formula_selectors()" + ) + # if NULL provided, return NULL ---------------------------------------------- if (is.null(x)) { return(NULL) @@ -201,6 +211,10 @@ #' Variable selector #' +#' `r lifecycle::badge("deprecated")`\cr +#' This function will soon be removed from `broom.helpers`. Please consider +#' [`cards::process_selectors()`] as an alternative. +#' #' Function takes `select()`-like inputs and converts the selector to #' a character vector of variable names. Functions accepts tidyselect syntax, #' and additional selector functions defined within the package @@ -216,9 +230,16 @@ #' variable. Default is `FALSE` #' #' @return A character vector of variable names +#' @keywords internal #' @export .select_to_varnames <- function(select, data = NULL, var_info = NULL, arg_name = NULL, select_single = FALSE) { + lifecycle::deprecate_soft( + "1.17.0", + ".select_to_varnames()", + "cards::process_selectors()" + ) + if (is.null(data) && is.null(var_info)) { cli::cli_abort("At least one of {.arg data} or {.arg var_info} must be specified.") } @@ -292,6 +313,8 @@ #' Generate a custom selector function #' +#' `r lifecycle::badge("deprecated")` +#' #' @param variable_column string indicating column variable names are stored #' @param select_column character vector of columns used in the `select_expr=` argument #' @param select_expr unquoted predicate command to subset a data frame to select variables @@ -303,8 +326,10 @@ #' in `env_variable_type$df_var_info`. #' #' @return custom selector functions +#' @keywords internal #' @export .generic_selector <- function(variable_column, select_column, select_expr, fun_name) { + lifecycle::deprecate_soft("1.17.0", ".generic_selector()") # ensuring the proper data has been scoped to use this function if (!.is_selector_scoped(variable_column, select_column)) { cli_alert_danger("Cannot use selector '{fun_name}()' in this context.") @@ -324,8 +349,10 @@ } #' @rdname dot-generic_selector +#' @keywords internal #' @export .is_selector_scoped <- function(variable_column, select_column) { + lifecycle::deprecate_soft("1.17.0", ".is_selector_scoped()") exists("df_var_info", envir = env_variable_type) && all(c(variable_column, select_column) %in% names(env_variable_type$df_var_info)) } diff --git a/man/dot-formula_list_to_named_list.Rd b/man/dot-formula_list_to_named_list.Rd index 38d2ba22..7b6917a8 100644 --- a/man/dot-formula_list_to_named_list.Rd +++ b/man/dot-formula_list_to_named_list.Rd @@ -41,6 +41,11 @@ error message will be printed.} formulas?} } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}\cr +This function will soon be removed from \code{broom.helpers}. Please consider +\code{\link[cards:process_selectors]{cards::process_formula_selectors()}} as an alternative. +} +\details{ Functions takes a list of formulas, a named list, or a combination of named elements with formula elements and returns a named list. For example, \code{list(age = 1, starts_with("stage") ~ 2)}. @@ -56,3 +61,4 @@ formula in a list; e.g. \code{everything() ~ 1} is equivalent to passing \code{list(everything() ~ 1)} } +\keyword{internal} diff --git a/man/dot-generic_selector.Rd b/man/dot-generic_selector.Rd index c79f1375..a2f57f9d 100644 --- a/man/dot-generic_selector.Rd +++ b/man/dot-generic_selector.Rd @@ -23,9 +23,10 @@ This helps with error messaging.} custom selector functions } \description{ -Generate a custom selector function +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} } \details{ \code{.is_selector_scoped()} checks if a selector has been properly registered in \code{env_variable_type$df_var_info}. } +\keyword{internal} diff --git a/man/dot-select_to_varnames.Rd b/man/dot-select_to_varnames.Rd index 9edb8b3a..39d68bec 100644 --- a/man/dot-select_to_varnames.Rd +++ b/man/dot-select_to_varnames.Rd @@ -31,7 +31,13 @@ variable. Default is \code{FALSE}} A character vector of variable names } \description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}\cr +This function will soon be removed from \code{broom.helpers}. Please consider +\code{\link[cards:process_selectors]{cards::process_selectors()}} as an alternative. +} +\details{ Function takes \code{select()}-like inputs and converts the selector to a character vector of variable names. Functions accepts tidyselect syntax, and additional selector functions defined within the package } +\keyword{internal} From 3eb9918933c907ca152c6964e333a27d310c0a6b Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 12:15:09 +0200 Subject: [PATCH 07/16] use of `cards::process_selectors()` instead of `.select_to_varnames()` --- R/scope_tidy.R | 4 ++-- R/tidy_add_header_rows.R | 20 ++++++++++---------- R/tidy_add_reference_rows.R | 20 ++++++++++---------- R/tidy_plus_plus.R | 3 ++- R/tidy_select_variables.R | 11 +++++++---- man/tidy_add_header_rows.Rd | 13 +++++++------ man/tidy_add_reference_rows.Rd | 13 +++++++------ man/tidy_plus_plus.Rd | 3 ++- man/tidy_select_variables.Rd | 5 +++-- 9 files changed, 50 insertions(+), 42 deletions(-) diff --git a/R/scope_tidy.R b/R/scope_tidy.R index ba4ecdad..3538f06f 100644 --- a/R/scope_tidy.R +++ b/R/scope_tidy.R @@ -36,7 +36,7 @@ scope_tidy <- function(x, data = NULL) { ) } - # if data not passed, use table_body to construct one + # if data not passed, use x to construct one if (rlang::is_empty(data)) { data <- dplyr::tibble( !!!rlang::rep_named( @@ -45,7 +45,7 @@ scope_tidy <- function(x, data = NULL) { ) ) - # if var_class available in x, convert colums + # if var_class available in x, convert columns if ("var_class" %in% names(x)) { df_class <- x[c("variable", "var_class")] |> unique() |> diff --git a/R/tidy_add_header_rows.R b/R/tidy_add_header_rows.R index c5c84b8d..3e9f5634 100644 --- a/R/tidy_add_header_rows.R +++ b/R/tidy_add_header_rows.R @@ -18,12 +18,13 @@ #' #' If the `label` column is not yet available in `x`, #' [tidy_add_term_labels()] will be automatically applied. -#' @param x a tidy tibble -#' @param show_single_row a vector indicating the names of binary -#' variables that should be displayed on a single row. -#' Accepts [tidyselect][dplyr::select] syntax. Default is `NULL`. -#' See also [all_dichotomous()] -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param show_single_row ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Names of dichotomous variables that should be displayed on a single row. +#' See also [all_dichotomous()]. +#' @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 @@ -91,10 +92,9 @@ tidy_add_header_rows <- function(x, # if reference_rows have been defined, removal of reference row variables_to_simplify <- NULL # obtain character vector of selected variables - show_single_row <- .select_to_varnames( - {{ show_single_row }}, - var_info = x, - arg_name = "show_single_row" + cards::process_selectors( + data = scope_tidy(x), + show_single_row = {{ show_single_row }} ) has_reference_row <- "reference_row" %in% names(x) diff --git a/R/tidy_add_reference_rows.R b/R/tidy_add_reference_rows.R index aacada32..97b5c00c 100644 --- a/R/tidy_add_reference_rows.R +++ b/R/tidy_add_reference_rows.R @@ -19,12 +19,13 @@ #' [tidy_add_term_labels()] after `tidy_add_reference_rows()` #' rather than before. Similarly, it is better to apply #' `tidy_add_reference_rows()` before [tidy_add_n()]. -#' @param x a tidy tibble -#' @param no_reference_row a vector indicating the name of variables -#' for those no reference row should be added. -#' Accepts [tidyselect][dplyr::select] syntax. Default is `NULL`. -#' See also [all_categorical()] and [all_dichotomous()] -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param no_reference_row ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables for those no reference row should be added. +#' See also [all_categorical()] and [all_dichotomous()]. +#' @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 @@ -120,10 +121,9 @@ tidy_add_reference_rows <- function( } # obtain character vector of selected variables - no_reference_row <- .select_to_varnames( - {{ no_reference_row }}, - var_info = x, - arg_name = "no_reference_row" + cards::process_selectors( + data = scope_tidy(x), + no_reference_row = {{ no_reference_row }} ) terms_levels <- model_list_terms_levels(model) diff --git a/R/tidy_plus_plus.R b/R/tidy_plus_plus.R index b5e108dd..b691f448 100644 --- a/R/tidy_plus_plus.R +++ b/R/tidy_plus_plus.R @@ -17,7 +17,8 @@ #' * [tidy_add_coefficients_type()] #' * [tidy_detach_model()] #' -#' @param model A model to be attached/tidied. +#' @param model (a model object, e.g. `glm`)\cr +#' A model to be attached/tidied. #' @param tidy_fun (`function`)\cr #' Option to specify a custom tidier function. #' @param conf.int (`logical`)\cr diff --git a/R/tidy_select_variables.R b/R/tidy_select_variables.R index f8696971..65a9b523 100644 --- a/R/tidy_select_variables.R +++ b/R/tidy_select_variables.R @@ -7,16 +7,16 @@ #' If the `variable` column is not yet available in `x`, #' [tidy_identify_variables()] will be automatically applied. #' @param x (`data.frame`)\cr -#' A tidy tibble. +#' A tidy tibble as produced by `tidy_*()` functions. #' @param include ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' Variables to include. Default is `everything()`. #' See also [all_continuous()], [all_categorical()], [all_dichotomous()] #' and [all_interaction()]. +#' @param model (a model object, e.g. `glm`)\cr +#' The corresponding model, if not attached to `x`. #' @return #' The `x` tibble limited to the included variables (and eventually the intercept), #' sorted according to the `include` parameter. -#' -#' @param model the corresponding model, if not attached to `x` #' @export #' @family tidy_helpers #' @examples @@ -54,7 +54,10 @@ tidy_select_variables <- function( .attributes <- .save_attributes(x) # obtain character vector of selected variables - include <- .select_to_varnames({{ include }}, var_info = x, arg_name = "include") + cards::process_selectors( + data = scope_tidy(x), + include = {{ include }} + ) # order result, intercept first then by the order of include if ("y.level" %in% names(x)) { diff --git a/man/tidy_add_header_rows.Rd b/man/tidy_add_header_rows.Rd index b958a871..321e277c 100644 --- a/man/tidy_add_header_rows.Rd +++ b/man/tidy_add_header_rows.Rd @@ -13,14 +13,15 @@ tidy_add_header_rows( ) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{show_single_row}{a vector indicating the names of binary -variables that should be displayed on a single row. -Accepts \link[dplyr:select]{tidyselect} syntax. Default is \code{NULL}. -See also \code{\link[=all_dichotomous]{all_dichotomous()}}} +\item{show_single_row}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Names of dichotomous variables that should be displayed on a single row. +See also \code{\link[=all_dichotomous]{all_dichotomous()}}.} -\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 diff --git a/man/tidy_add_reference_rows.Rd b/man/tidy_add_reference_rows.Rd index b5c0acb3..f415c5c9 100644 --- a/man/tidy_add_reference_rows.Rd +++ b/man/tidy_add_reference_rows.Rd @@ -12,14 +12,15 @@ tidy_add_reference_rows( ) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{no_reference_row}{a vector indicating the name of variables -for those no reference row should be added. -Accepts \link[dplyr:select]{tidyselect} syntax. Default is \code{NULL}. -See also \code{\link[=all_categorical]{all_categorical()}} and \code{\link[=all_dichotomous]{all_dichotomous()}}} +\item{no_reference_row}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables for those no reference row should be added. +See also \code{\link[=all_categorical]{all_categorical()}} and \code{\link[=all_dichotomous]{all_dichotomous()}}.} -\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 diff --git a/man/tidy_plus_plus.Rd b/man/tidy_plus_plus.Rd index 46073619..f8ce35e1 100644 --- a/man/tidy_plus_plus.Rd +++ b/man/tidy_plus_plus.Rd @@ -39,7 +39,8 @@ tidy_plus_plus( ) } \arguments{ -\item{model}{A model to be attached/tidied.} +\item{model}{(a model object, e.g. \code{glm})\cr +A model to be attached/tidied.} \item{tidy_fun}{(\code{function})\cr Option to specify a custom tidier function.} diff --git a/man/tidy_select_variables.Rd b/man/tidy_select_variables.Rd index d48658e2..9710f804 100644 --- a/man/tidy_select_variables.Rd +++ b/man/tidy_select_variables.Rd @@ -8,14 +8,15 @@ tidy_select_variables(x, include = everything(), model = tidy_get_model(x)) } \arguments{ \item{x}{(\code{data.frame})\cr -A tidy tibble.} +A tidy tibble as produced by \verb{tidy_*()} functions.} \item{include}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr Variables to include. Default is \code{everything()}. See also \code{\link[=all_continuous]{all_continuous()}}, \code{\link[=all_categorical]{all_categorical()}}, \code{\link[=all_dichotomous]{all_dichotomous()}} and \code{\link[=all_interaction]{all_interaction()}}.} -\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}.} } \value{ The \code{x} tibble limited to the included variables (and eventually the intercept), From 114d338ad2967bb3a283b7ee18155a69703096f1 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 12:42:28 +0200 Subject: [PATCH 08/16] vars() is deprecated --- tests/testthat/test-select_helpers.R | 5 ----- tests/testthat/test-select_variables.R | 6 ------ 2 files changed, 11 deletions(-) diff --git a/tests/testthat/test-select_helpers.R b/tests/testthat/test-select_helpers.R index 0bef4ef7..da15518b 100644 --- a/tests/testthat/test-select_helpers.R +++ b/tests/testthat/test-select_helpers.R @@ -32,11 +32,6 @@ test_that("select_helpers: .select_to_varnames", { .select_to_varnames(select = NULL, data = mtcars), NULL ) - - expect_equal( - .select_to_varnames(select = vars(dplyr::everything(), -mpg), data = mtcars), - dplyr::select(mtcars, dplyr::everything(), -mpg) |> colnames() - ) }) test_that("select_helpers: all_*()", { diff --git a/tests/testthat/test-select_variables.R b/tests/testthat/test-select_variables.R index 7e8e5d16..ecaa1fd5 100644 --- a/tests/testthat/test-select_variables.R +++ b/tests/testthat/test-select_variables.R @@ -44,12 +44,6 @@ test_that("tidy_select_variables() works for basic models", { res |> tidy_select_variables(include = stage) ) - # testing vars() selector - expect_equivalent( - res |> tidy_select_variables(include = vars(grade, trt)), - res |> tidy_select_variables(include = c(grade, trt)) - ) - # no error when none selected expect_error( res |> tidy_select_variables(include = starts_with("zzzzzzz")), From e47e2779477e3ddb43818c50423a1f529e2b3591 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 12:55:48 +0200 Subject: [PATCH 09/16] 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 From 2d6cabc1b83c1854e2ce73201683638598897e25 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 13:14:30 +0200 Subject: [PATCH 10/16] removing some tests --- tests/testthat/test-select_helpers.R | 203 --------------------------- 1 file changed, 203 deletions(-) diff --git a/tests/testthat/test-select_helpers.R b/tests/testthat/test-select_helpers.R index da15518b..c2bced3f 100644 --- a/tests/testthat/test-select_helpers.R +++ b/tests/testthat/test-select_helpers.R @@ -1,39 +1,3 @@ -test_that("select_helpers: .select_to_varnames", { - expect_error( - .select_to_varnames(mpg) - ) - - expect_equal( - .select_to_varnames(select = c(hp, mpg), data = mtcars), - dplyr::select(mtcars, hp, mpg) |> colnames() - ) - - expect_equal( - .select_to_varnames(select = mpg, data = mtcars), - dplyr::select(mtcars, mpg) |> colnames() - ) - - expect_equal( - .select_to_varnames(select = "mpg", data = mtcars), - dplyr::select(mtcars, "mpg") |> colnames() - ) - - expect_equal( - .select_to_varnames(select = c("hp", "mpg"), data = mtcars), - dplyr::select(mtcars, c("hp", "mpg")) |> colnames() - ) - - expect_equal( - .select_to_varnames(select = c(hp, mpg), data = mtcars), - dplyr::select(mtcars, c(hp, mpg)) |> colnames() - ) - - expect_equal( - .select_to_varnames(select = NULL, data = mtcars), - NULL - ) -}) - test_that("select_helpers: all_*()", { mod <- glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) mod_tidy <- tidy_and_attach(mod) @@ -251,172 +215,5 @@ test_that("select_helpers: tidy_add_variable_labels", { ) }) -test_that("select_helpers: .select_to_varnames", { - expect_error( - .select_to_varnames(c(mpg, hp), data = mtcars, select_single = TRUE) - ) -}) - -test_that("select_helpers: .formula_list_to_named_list ", { - mod <- glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) - tidy_mod <- tidy_plus_plus(mod) - - expect_error( - .formula_list_to_named_list(list(age ~ "Age", TRUE), var_info = tidy_mod) - ) - - expect_error( - .formula_list_to_named_list(list(age ~ "Age"), - var_info = tidy_mod, - type_check = is.character - ), - NA - ) - expect_error( - .formula_list_to_named_list(list(age ~ "Age"), - var_info = tidy_mod, - type_check = is.logical - ) - ) - expect_error( - .formula_list_to_named_list(letters, - var_info = tidy_mod, - type_check = is.logical - ) - ) - - expect_equal( - .formula_list_to_named_list(age ~ "Age", var_info = tidy_mod), - list(age = "Age") - ) - - expect_equal( - .formula_list_to_named_list(~"Age", var_info = tidy_mod), - list(age = "Age", trt = "Age", grade = "Age", `age:trt` = "Age") - ) - expect_equal( - .formula_list_to_named_list(list(~"Age", `age:trt` = "interact"), var_info = tidy_mod), - list(age = "Age", trt = "Age", grade = "Age", `age:trt` = "interact") - ) - - expect_error( - .formula_list_to_named_list(list(age ~ "Age"), - var_info = tidy_mod, type_check = is.logical, - arg_name = "label" - ) - ) - expect_error( - .formula_list_to_named_list(list(age ~ "Age"), - var_info = tidy_mod, - type_check = is.logical, arg_name = "label", - type_check_msg = "Age msg error" - ), - "Age msg error" - ) - expect_error( - .formula_list_to_named_list("Age", - var_info = tidy_mod, - type_check = rlang::is_string, - arg_name = "label" - ), - "Did you mean `everything" - ) - expect_error( - .formula_list_to_named_list("Age", - var_info = tidy_mod, - type_check = rlang::is_string, - arg_name = "label" - ), - "Age" - ) - expect_error( - .formula_list_to_named_list(~"Age", - var_info = tidy_mod, - type_check = rlang::is_string, - arg_name = "label" - ), - NA - ) - - expect_error( - .formula_list_to_named_list(list(age ~ NULL), - var_info = tidy_mod, - type_check = is.logical - ), - NA - ) - expect_error( - .formula_list_to_named_list(list(age ~ NULL), - var_info = tidy_mod, - type_check = is.logical, null_allowed = FALSE - ) - ) - expect_error( - select_test <- - .formula_list_to_named_list( - list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL), - data = gtsummary::trial, - arg_name = "label", - type_check = rlang::is_string, - type_check_msg = NULL, - null_allowed = TRUE - ), - NA - ) - expect_equal( - select_test, - list(response = "Response", age = "?AGE?", stage = "?AGE?", trt = NULL) - ) - - expect_error( - .formula_list_to_named_list( - list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL), - data = gtsummary::trial, - arg_name = "label", - type_check = rlang::is_string, - type_check_msg = NULL, - null_allowed = FALSE - ) - ) - - expect_error( - .formula_list_to_named_list( - list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL), - data = gtsummary::trial, - arg_name = "label", - select_single = TRUE - ) - ) - expect_error( - .formula_list_to_named_list( - list(response = "Response", dplyr::contains("age") ~ "?AGE?", trt = NULL), - data = gtsummary::trial, - select_single = TRUE - ) - ) -}) - -test_that("select_helpers: .scope_var_info", { - mod_tidy <- lm(mpg ~ hp, mtcars) |> tidy_and_attach() - # can scope a data frame with no variable - expect_error( - .scope_var_info(mod_tidy |> tidy_identify_variables()), NA - ) - - # no error when non-data frame is scoped - expect_error( - .scope_var_info(mod_tidy$term), NA - ) -}) - - -test_that("select_helpers: .var_info_to_df ", { - mod_tidy <- lm(mpg ~ hp, mtcars) |> tidy_and_attach() - - # can convert a tibble without a var_class column - expect_error( - .var_info_to_df(mod_tidy |> tidy_identify_variables() |> dplyr::select(-var_class)), NA - ) -}) From 089150f1ade225c921f89ae068bcf45e3685a2b2 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 13:18:58 +0200 Subject: [PATCH 11/16] updating tidy_add_pairwise_contrasts() --- R/tidy_add_pairwise_contrasts.R | 37 +++++++++++++++++------------- man/tidy_add_pairwise_contrasts.Rd | 30 ++++++++++++++---------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/R/tidy_add_pairwise_contrasts.R b/R/tidy_add_pairwise_contrasts.R index 6f8233d2..77aa713d 100644 --- a/R/tidy_add_pairwise_contrasts.R +++ b/R/tidy_add_pairwise_contrasts.R @@ -13,18 +13,24 @@ #' For multi-components models, such as zero-inflated Poisson or beta #' regression, support of pairwise contrasts is still experimental. #' -#' @param x a tidy tibble -#' @param variables a vector indicating the name of variables -#' for those pairwise contrasts should be added. -#' Accepts [tidyselect][dplyr::select] syntax. Default is [all_categorical()] -#' @param keep_model_terms keep terms from the model? -#' @param pairwise_reverse determines whether to use `"pairwise"` (if `TRUE`) -#' or `"revpairwise"` (if `FALSE`), see [emmeans::contrast()] -#' @param contrasts_adjust optional adjustment method when computing contrasts, -#' see [emmeans::contrast()] (if `NULL`, use `emmeans` default) -#' @param conf.level confidence level, by default use the value indicated -#' previously in [tidy_and_attach()] -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param variables include ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables for those pairwise contrasts should be added. +#' Default is [all_categorical()]. +#' @param keep_model_terms (`logical`)\cr +#' Keep terms from the model? +#' @param pairwise_reverse (`logical`)\cr +#' Determines whether to use `"pairwise"` (if `TRUE`) +#' or `"revpairwise"` (if `FALSE`), see [emmeans::contrast()]. +#' @param contrasts_adjust (`string`)\cr +#' Optional adjustment method when computing contrasts, +#' see [emmeans::contrast()] (if `NULL`, use `emmeans` default). +#' @param conf.level (`numeric`)\cr +#' Confidence level, by default use the value indicated +#' previously in [tidy_and_attach()]. +#' @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 @@ -94,10 +100,9 @@ tidy_add_pairwise_contrasts <- function( } # obtain character vector of selected variables - variables <- .select_to_varnames( - {{ variables }}, - var_info = x, - arg_name = "variables" + cards::process_selectors( + data = scope_tidy(x), + variables = {{ variables }} ) if (isTRUE(.attributes$exponentiate) && is.null(emmeans_args$type)) { diff --git a/man/tidy_add_pairwise_contrasts.Rd b/man/tidy_add_pairwise_contrasts.Rd index 992a26ac..62d0bc7b 100644 --- a/man/tidy_add_pairwise_contrasts.Rd +++ b/man/tidy_add_pairwise_contrasts.Rd @@ -17,28 +17,34 @@ tidy_add_pairwise_contrasts( ) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{variables}{a vector indicating the name of variables -for those pairwise contrasts should be added. -Accepts \link[dplyr:select]{tidyselect} syntax. Default is \code{\link[=all_categorical]{all_categorical()}}} +\item{variables}{include (\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables for those pairwise contrasts should be added. +Default is \code{\link[=all_categorical]{all_categorical()}}.} -\item{keep_model_terms}{keep terms from the model?} +\item{keep_model_terms}{(\code{logical})\cr +Keep terms from the model?} -\item{pairwise_reverse}{determines whether to use \code{"pairwise"} (if \code{TRUE}) -or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}} +\item{pairwise_reverse}{(\code{logical})\cr +Determines whether to use \code{"pairwise"} (if \code{TRUE}) +or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}.} -\item{contrasts_adjust}{optional adjustment method when computing contrasts, -see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default)} +\item{contrasts_adjust}{(\code{string})\cr +Optional adjustment method when computing contrasts, +see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default).} -\item{conf.level}{confidence level, by default use the value indicated -previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}} +\item{conf.level}{(\code{numeric})\cr +Confidence level, by default use the value indicated +previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}.} \item{emmeans_args}{(\code{list})\cr List of additional parameter to pass to \code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts.} -\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 From 9e1552666f430e9c4e5f5fdd9b6037b94da4af65 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 13:53:31 +0200 Subject: [PATCH 12/16] removing strict and quiet from tidy_add_variable_labels() --- R/tidy_add_term_labels.R | 2 +- R/tidy_add_variable_labels.R | 22 ++++--------------- R/tidy_plus_plus.R | 6 +++--- man/tidy_add_variable_labels.Rd | 18 ++++------------ tests/testthat/test-add_variable_labels.R | 26 ----------------------- 5 files changed, 12 insertions(+), 62 deletions(-) diff --git a/R/tidy_add_term_labels.R b/R/tidy_add_term_labels.R index fe56579c..75e3bde1 100644 --- a/R/tidy_add_term_labels.R +++ b/R/tidy_add_term_labels.R @@ -76,7 +76,7 @@ tidy_add_term_labels <- function(x, } if (!"var_label" %in% names(x)) { - x <- x |> tidy_add_variable_labels(model = model, quiet = quiet) + x <- x |> tidy_add_variable_labels(model = model) } if (!"contrasts" %in% names(x)) { x <- x |> tidy_add_contrasts(model = model) diff --git a/R/tidy_add_variable_labels.R b/R/tidy_add_variable_labels.R index 3707995f..a41613c7 100644 --- a/R/tidy_add_variable_labels.R +++ b/R/tidy_add_variable_labels.R @@ -16,8 +16,6 @@ #' 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 @@ -36,17 +34,15 @@ #' tidy_and_attach() |> #' tidy_add_variable_labels( #' labels = list( -#' "(Intercept)" = "Custom intercept", -#' Sex = "Gender", -#' "Class:Age" = "Custom label" +#' "(Intercept)" ~ "Custom intercept", +#' Sex ~ "Gender", +#' "Class:Age" ~ "Custom label" #' ) #' ) tidy_add_variable_labels <- function(x, labels = NULL, interaction_sep = " * ", - model = tidy_get_model(x), - quiet = FALSE, - strict = FALSE) { + model = tidy_get_model(x)) { if (is.null(model)) { cli::cli_abort(c( "{.arg model} is not provided.", @@ -95,16 +91,6 @@ tidy_add_variable_labels <- function(x, var_labels <- var_labels |> .update_vector(additional_labels) - # check if all elements of labels are in x - # show a message otherwise - not_found <- setdiff(names(labels), names(var_labels)) - if (length(not_found) > 0 && !quiet) { - cli_alert_danger("{.code {not_found}} terms have not been found in {.code x}.") - } - if (length(not_found) > 0 && strict) { - cli::cli_abort("Incorrect call with `labels=`. Quitting execution.", call = NULL) - } - var_labels <- var_labels |> .update_vector(labels) diff --git a/R/tidy_plus_plus.R b/R/tidy_plus_plus.R index b691f448..7b56540e 100644 --- a/R/tidy_plus_plus.R +++ b/R/tidy_plus_plus.R @@ -222,8 +222,7 @@ tidy_plus_plus <- function(model, res <- res |> tidy_add_variable_labels( labels = variable_labels, - interaction_sep = interaction_sep, - quiet = quiet + interaction_sep = interaction_sep ) |> tidy_add_term_labels( labels = term_labels, @@ -236,7 +235,8 @@ tidy_plus_plus <- function(model, res <- res |> tidy_add_header_rows( show_single_row = {{ show_single_row }}, - strict = strict, quiet = quiet + strict = strict, + quiet = quiet ) } diff --git a/man/tidy_add_variable_labels.Rd b/man/tidy_add_variable_labels.Rd index 08951dc5..eab0617b 100644 --- a/man/tidy_add_variable_labels.Rd +++ b/man/tidy_add_variable_labels.Rd @@ -8,9 +8,7 @@ tidy_add_variable_labels( x, labels = NULL, interaction_sep = " * ", - model = tidy_get_model(x), - quiet = FALSE, - strict = FALSE + model = tidy_get_model(x) ) } \arguments{ @@ -25,14 +23,6 @@ Separator for interaction terms.} \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 -cannot be generated. Default is \code{FALSE}.} - -\item{strict}{(\code{logical})\cr -Whether \code{broom.helpers} should return an error -when requested output cannot be generated. Default is \code{FALSE}.} } \description{ Will add variable labels in a \code{var_label} column, based on: @@ -63,9 +53,9 @@ glm(Survived ~ Class * Age * Sex, data = df, weights = df$n, family = binomial) tidy_and_attach() |> tidy_add_variable_labels( labels = list( - "(Intercept)" = "Custom intercept", - Sex = "Gender", - "Class:Age" = "Custom label" + "(Intercept)" ~ "Custom intercept", + Sex ~ "Gender", + "Class:Age" ~ "Custom label" ) ) } diff --git a/tests/testthat/test-add_variable_labels.R b/tests/testthat/test-add_variable_labels.R index 759100b2..1bb61ab7 100644 --- a/tests/testthat/test-add_variable_labels.R +++ b/tests/testthat/test-add_variable_labels.R @@ -51,32 +51,6 @@ test_that("tidy_add_variable_labels() works for basic models", { ) ) - # no error if providing labels not corresponding to an existing variable - # but display a message - expect_error( - mod |> - tidy_and_attach() |> - tidy_add_variable_labels( - labels = list(aaa = "aaa", bbb = "bbb", ccc = 44) - ), - NA - ) - expect_message( - mod |> - tidy_and_attach() |> - tidy_add_variable_labels( - labels = list(aaa = "aaa", bbb = "bbb", ccc = 44) - ) - ) - expect_error( - mod |> - tidy_and_attach() |> - tidy_add_variable_labels( - labels = list(aaa = "aaa", bbb = "bbb", ccc = 44), - strict = TRUE - ) - ) - # model with only an interaction term mod <- lm(age ~ factor(response):marker, gtsummary::trial) res <- mod |> From 1d648d45571e56d29fbc1218fe01e1439862a99d Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 15:46:43 +0200 Subject: [PATCH 13/16] lint --- tests/testthat/test-select_helpers.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/testthat/test-select_helpers.R b/tests/testthat/test-select_helpers.R index c2bced3f..3584b343 100644 --- a/tests/testthat/test-select_helpers.R +++ b/tests/testthat/test-select_helpers.R @@ -214,6 +214,3 @@ test_that("select_helpers: tidy_add_variable_labels", { c("b0", "AGE", "Drug", "Grade", "Interaction") ) }) - - - From 82a8a588134f3c06f389e027b6afe8fd20fe230d Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 17:07:22 +0200 Subject: [PATCH 14/16] improve doc fix #272 --- NEWS.md | 21 ++- R/assert_package.R | 18 ++- R/broom.helpers-package.R | 6 +- R/custom_tidiers.R | 59 ++++---- R/helpers.R | 17 ++- R/marginal_tidiers.R | 148 ++++++++++++--------- R/model_compute_terms_contributions.R | 3 +- R/model_get_assign.R | 3 +- R/model_get_coefficients_type.R | 3 +- R/model_get_contrasts.R | 3 +- R/model_get_model.R | 3 +- R/model_get_model_frame.R | 3 +- R/model_get_model_matrix.R | 5 +- R/model_get_n.R | 3 +- R/model_get_nlevels.R | 3 +- R/model_get_offset.R | 3 +- R/model_get_pairwise_contrasts.R | 19 ++- R/model_get_response.R | 3 +- R/model_get_response_variable.R | 3 +- R/model_get_terms.R | 3 +- R/model_get_weights.R | 3 +- R/model_get_xlevels.R | 3 +- R/model_identify_variables.R | 3 +- R/model_list_contrasts.R | 3 +- R/model_list_higher_order_variables.R | 3 +- R/model_list_terms_levels.R | 14 +- R/model_list_variables.R | 15 ++- R/scope_tidy.R | 10 +- R/select_helpers.R | 19 +-- R/tidy_add_coefficients_type.R | 12 +- R/tidy_add_contrasts.R | 9 +- R/tidy_add_estimate_to_reference_rows.R | 17 ++- R/tidy_add_n.R | 6 +- R/tidy_add_term_labels.R | 19 +-- R/tidy_and_attach.R | 22 ++- R/tidy_disambiguate_terms.R | 9 +- R/tidy_identify_variables.R | 6 +- R/tidy_plus_plus.R | 2 +- R/tidy_remove_intercept.R | 6 +- man/assert_package.Rd | 18 ++- man/dot-clean_backticks.Rd | 11 +- man/dot-escape_regex.Rd | 3 +- man/model_compute_terms_contributions.Rd | 3 +- man/model_get_assign.Rd | 3 +- man/model_get_coefficients_type.Rd | 3 +- man/model_get_contrasts.Rd | 3 +- man/model_get_model.Rd | 3 +- man/model_get_model_frame.Rd | 3 +- man/model_get_model_matrix.Rd | 5 +- man/model_get_n.Rd | 3 +- man/model_get_nlevels.Rd | 3 +- man/model_get_offset.Rd | 3 +- man/model_get_pairwise_contrasts.Rd | 21 +-- man/model_get_response.Rd | 3 +- man/model_get_response_variable.Rd | 3 +- man/model_get_terms.Rd | 3 +- man/model_get_weights.Rd | 3 +- man/model_get_xlevels.Rd | 3 +- man/model_identify_variables.Rd | 3 +- man/model_list_contrasts.Rd | 3 +- man/model_list_higher_order_variables.Rd | 3 +- man/model_list_terms_levels.Rd | 16 ++- man/model_list_variables.Rd | 15 ++- man/scope_tidy.Rd | 10 +- man/select_helpers.Rd | 19 +-- man/seq_range.Rd | 6 +- man/tidy_add_coefficients_type.Rd | 12 +- man/tidy_add_contrasts.Rd | 9 +- man/tidy_add_estimate_to_reference_rows.Rd | 17 ++- man/tidy_add_n.Rd | 6 +- man/tidy_add_term_labels.Rd | 19 +-- man/tidy_all_effects.Rd | 12 +- man/tidy_attach_model.Rd | 34 ++--- man/tidy_avg_comparisons.Rd | 14 +- man/tidy_avg_slopes.Rd | 14 +- man/tidy_broom.Rd | 5 +- man/tidy_disambiguate_terms.Rd | 9 +- man/tidy_ggpredict.Rd | 12 +- man/tidy_identify_variables.Rd | 6 +- man/tidy_marginal_contrasts.Rd | 38 +++--- man/tidy_marginal_means.Rd | 14 +- man/tidy_marginal_predictions.Rd | 30 +++-- man/tidy_margins.Rd | 12 +- man/tidy_multgee.Rd | 12 +- man/tidy_parameters.Rd | 12 +- man/tidy_plus_plus.Rd | 2 +- man/tidy_remove_intercept.Rd | 6 +- man/tidy_with_broom_or_parameters.Rd | 14 +- man/tidy_zeroinfl.Rd | 16 ++- 89 files changed, 604 insertions(+), 406 deletions(-) diff --git a/NEWS.md b/NEWS.md index ca526069..3ce96439 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,20 +1,28 @@ # broom.helpers (development version) -**Fixes** +**Documentation** -- selectors such as `all_categorical()` are now compatible with `gtsummary` - version ≥ 2.0.0 (#270) -- `model_get_model_frame.coxph()` has been fixed to return a correct model - frame a subject identifier is passed to `survival::coxph()` (#268) +- Documentation has been improved, showing now clearly the type expected + for each argument (#272) -**Deprecated functions** +**Deprecated functions and changes in selectors functions** +- selectors such as `all_categorical()` are now compatible with `gtsummary` + version ≥ 2.0.0 (#270) +- new function `scope_tidy()` to scope a tidy tibble allowing + to tidy select (#270) - `.select_to_varnames()`, `.formula_list_to_named_list()`, `.generic_selector()` and `.is_selector_scoped()` are now deprecated and will be removed in a future release: you may consider `cards::process_selectors()` and `cards::process_formula_selectors()` as alternatives (#270) +**Fixes** + +- `model_get_model_frame.coxph()` has been fixed to return a correct model + frame a subject identifier is passed to `survival::coxph()` (#268) + + # broom.helpers 1.16.0 **New features** @@ -49,6 +57,7 @@ (#260 @jackmwolf) - `tidy_marginal_predictions()` has been updated to avoid the use of the deprecated function `marginaleffects::datagridcf()` (#256) + # broom.helpers 1.15.0 diff --git a/R/assert_package.R b/R/assert_package.R index bf3c7efc..0956b470 100644 --- a/R/assert_package.R +++ b/R/assert_package.R @@ -8,17 +8,23 @@ #' will return, if any, the minimum version of `pkg` required by `pkg_search`, #' `NULL` if no minimum version required. #' -#' @param pkg Package required -#' @param fn Calling function from the user perspective. Used to write +#' @param pkg (`string`)\cr +#' Name of the required package. +#' @param fn (`string`)\cr +#' Name of the calling function from the user perspective. Used to write #' informative error messages. -#' @param pkg_search the package the function will search for a minimum +#' @param pkg_search (`string`)\cr +#' Name of the package the function will search for a minimum #' required version from. -#' @param boolean logical indicating whether to return a `TRUE`/`FALSE`, rather +#' @param boolean (`logical`)\cr +#' Whether to return a `TRUE`/`FALSE`, rather #' than error when package/package version not available. Default is `FALSE`, #' which will return an error if `pkg` is not installed. -#' @param remove_duplicates if several versions of a package are installed, +#' @param remove_duplicates (`logical`)\cr +#' If several versions of a package are installed, #' should only the first one be returned? -#' @param lib.loc location of `R` library trees to search through, see +#' @param lib.loc (`string`)\cr +#' Location of `R` library trees to search through, see #' `utils::installed.packages()`. #' @details #' `get_all_packages_dependencies()` could be used to get the list of diff --git a/R/broom.helpers-package.R b/R/broom.helpers-package.R index 0a527d5b..fb4e2029 100644 --- a/R/broom.helpers-package.R +++ b/R/broom.helpers-package.R @@ -77,8 +77,10 @@ utils::globalVariables(c(".")) #' Sequence generation between min and max #' -#' @param x a numeric vector -#' @param length.out desired length of the sequence +#' @param x (`numeric`)\cr +#' A numeric vector. +#' @param length.out (`integer`)\cr +#' Desired length of the sequence (a positive integer). #' @details #' `seq_range(x, length.out)` is a shortcut for #' `seq(min(x, na.rm = TRUE), max(x, na.rm = TRUE), length.out = length.out)` diff --git a/R/custom_tidiers.R b/R/custom_tidiers.R index 9b3a1f69..8e9bf964 100644 --- a/R/custom_tidiers.R +++ b/R/custom_tidiers.R @@ -2,11 +2,13 @@ #' #' Use [parameters::model_parameters()] to tidy a model and apply #' `parameters::standardize_names(style = "broom")` to the output -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to [parameters::model_parameters()] +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to [parameters::model_parameters()]. #' @note #' For [betareg::betareg()], the component column in the results is standardized #' with [broom::tidy()], using `"mean"` and `"precision"` values. @@ -71,12 +73,14 @@ tidy_parameters <- function(x, conf.int = TRUE, conf.level = .95, ...) { #' #' Try to tidy a model with `broom::tidy()`. If it fails, will try to tidy the #' model using `parameters::model_parameters()` through `tidy_parameters()`. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to `broom::tidy()` or -#' `parameters::model_parameters()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to `broom::tidy()` or +#' `parameters::model_parameters()`. #' @export #' @family custom_tieders tidy_with_broom_or_parameters <- function(x, conf.int = TRUE, conf.level = .95, ...) { @@ -239,8 +243,9 @@ tidy_with_broom_or_parameters <- function(x, conf.int = TRUE, conf.level = .95, #' Tidy with `broom::tidy()` and checks that all arguments are used #' -#' @param x a model to tidy -#' @param ... additional parameters passed to `broom::tidy()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param ... Additional parameters passed to `broom::tidy()`. #' @family custom_tieders #' @export tidy_broom <- function(x, ...) { @@ -254,11 +259,13 @@ tidy_broom <- function(x, ...) { #' A tidier for models generated with `multgee::nomLORgee()` or `multgee::ordLORgee()`. #' Term names will be updated to be consistent with generic models. The original #' term names are preserved in an `"original_term"` column. -#' @param x a `multgee::nomLORgee()` or a `multgee::ordLORgee()` model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to `parameters::model_parameters()` +#' @param x (`LORgee`)\cr +#' A `multgee::nomLORgee()` or a `multgee::ordLORgee()` model. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to `parameters::model_parameters()`. #' @details #' To be noted, for `multgee::nomLORgee()`, the baseline `y` category is the #' latest modality of `y`. @@ -334,13 +341,15 @@ tidy_multgee <- function(x, conf.int = TRUE, conf.level = .95, ...) { #' A tidier for models generated with `pscl::zeroinfl()` or `pscl::hurdle()`. #' Term names will be updated to be consistent with generic models. The original #' term names are preserved in an `"original_term"` column. -#' @param x a `pscl::zeroinfl()` or a `pscl::hurdle()` model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param component `NULL` or one of `"all"`, `"conditional"`, `"zi"`, or -#' `"zero_inflated"` -#' @param ... additional parameters passed to `parameters::model_parameters()` +#' @param x (`zeroinfl` or `hurdle`)\cr +#' A `pscl::zeroinfl()` or a `pscl::hurdle()` model. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param component (`string`)\cr +#' `NULL` or one of `"all"`, `"conditional"`, `"zi"`, or `"zero_inflated"`. +#' @param ... Additional parameters passed to `parameters::model_parameters()`. #' @export #' @family custom_tieders #' @examplesIf interactive() diff --git a/R/helpers.R b/R/helpers.R index 191eafc3..7b22d107 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -2,7 +2,8 @@ #' meaning in a regular expression #' #' This functions has been adapted from `Hmisc::escapeRegex()` -#' @param string a character vector +#' @param string (`string`)\cr +#' A character vector. #' @export #' @family other_helpers .escape_regex <- function(string) { @@ -12,16 +13,14 @@ ) } - - #' Remove backticks around variable names #' -#' @param x a character vector to be cleaned -#' @param variable_names list of variable names, -#' could be obtained with -#' [model_list_variables(only_variable = TRUE)][model_list_variables()] -#' to properly take into account interaction only terms/variables -#' +#' @param x (`string`)\cr +#' A character vector to be cleaned. +#' @param variable_names (`string`)\cr +#' Optional vector of variable names, could be obtained with +#' [model_list_variables(only_variable = TRUE)][model_list_variables()], +#' to properly take into account interaction only terms/variables. #' @export #' @family other_helpers .clean_backticks <- function(x, variable_names = x) { diff --git a/R/marginal_tidiers.R b/R/marginal_tidiers.R index 29c903d4..0ba1725d 100644 --- a/R/marginal_tidiers.R +++ b/R/marginal_tidiers.R @@ -21,11 +21,13 @@ #' @note When applying `margins::margins()`, custom contrasts are ignored. #' Treatment contrasts (`stats::contr.treatment()`) are applied to all #' categorical variables. Interactions are also ignored. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to `margins::margins()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to `margins::margins()`. #' @family marginal_tieders #' @seealso `margins::margins()` #' @export @@ -78,11 +80,13 @@ tidy_margins <- function(x, conf.int = TRUE, conf.level = 0.95, ...) { #' @note #' If the model contains interactions, `effects::allEffects()` will return #' marginal predictions for the different levels of the interactions. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to `effects::allEffects()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to `effects::allEffects()`. #' @family marginal_tieders #' @seealso `effects::allEffects()` #' @export @@ -189,11 +193,13 @@ effpoly_to_df <- function(x) { #' @note #' By default, `ggeffects::ggpredict()` estimates marginal predictions for each #' individual variable, regardless of eventual interactions. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to `ggeffects::ggpredict()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to `ggeffects::ggpredict()`. #' @family marginal_tieders #' @seealso `ggeffects::ggpredict()` #' @export @@ -258,12 +264,14 @@ tidy_ggpredict <- function(x, conf.int = TRUE, conf.level = .95, ...) { #' `marginaleffects::avg_slopes()`. #' #' For more information, see `vignette("marginal_tidiers", "broom.helpers")`. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to -#' `marginaleffects::avg_slopes()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to +#' `marginaleffects::avg_slopes()`. #' @family marginal_tieders #' @seealso `marginaleffects::avg_slopes()` #' @export @@ -344,12 +352,14 @@ tidy_avg_slopes <- function(x, conf.int = TRUE, conf.level = 0.95, ...) { #' #' See also `tidy_marginal_contrasts()` for taking into account interactions. #' For more information, see `vignette("marginal_tidiers", "broom.helpers")`. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to -#' `marginaleffects::avg_comparisons()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to +#' `marginaleffects::avg_comparisons()`. #' @family marginal_tieders #' @seealso `marginaleffects::avg_comparisons()` #' @export @@ -436,12 +446,14 @@ tidy_avg_comparisons <- function(x, conf.int = TRUE, conf.level = 0.95, ...) { #' are defined only for categorical variables. #' #' For more information, see `vignette("marginal_tidiers", "broom.helpers")`. -#' @param x a model -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to -#' `marginaleffects::marginal_means()` +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to +#' `marginaleffects::marginal_means()`. #' @family marginal_tieders #' @seealso `marginaleffects::marginal_means()` #' @export @@ -551,16 +563,19 @@ tidy_marginal_means <- function(x, conf.int = TRUE, conf.level = 0.95, ...) { #' plots that could be combined with `patchwork::wrap_plots()` (see examples). #' #' For more information, see `vignette("marginal_tidiers", "broom.helpers")`. -#' @param x a model -#' @param variables_list a list whose elements will be sequentially passed to +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param variables_list (`list` or `string`)\cr +#' A list whose elements will be sequentially passed to #' `variables` in `marginaleffects::avg_predictions()` (see details below); #' alternatively, it could also be the string `"auto"` (default) or -#' `"no_interaction"` -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to -#' `marginaleffects::avg_predictions()` +#' `"no_interaction"`. +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to +#' `marginaleffects::avg_predictions()`. #' @family marginal_tieders #' @seealso `marginaleffects::avg_predictions()` #' @export @@ -692,11 +707,15 @@ tidy_marginal_predictions <- function(x, variables_list = "auto", } #' @export -#' @param model a model -#' @param interactions should combinations of variables corresponding to +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param interactions (`logical`)\cr +#' Should combinations of variables corresponding to #' interactions be returned? -#' @param categorical default value for categorical variables -#' @param continuous default value for continuous variables +#' @param categorical ([`predictor values`][marginaleffects::predictions()])\cr +#' Default values for categorical variables. +#' @param continuous ([`predictor values`][marginaleffects::predictions()])\cr +#' Default values for continuous variables. #' @rdname tidy_marginal_predictions variables_to_predict <- function(model, interactions = TRUE, categorical = unique, @@ -910,16 +929,19 @@ plot_marginal_predictions <- function(x, variables_list = "auto", #' see the help file of `marginaleffects::avg_comparisons()`. #' #' For more information, see `vignette("marginal_tidiers", "broom.helpers")`. -#' @param x a model -#' @param variables_list a list whose elements will be sequentially passed to +#' @param x (a model object, e.g. `glm`)\cr +#' A model to be tidied. +#' @param variables_list (`list` or `string`)\cr +#' A list whose elements will be sequentially passed to #' `variables` in `marginaleffects::avg_comparisons()` (see details below); #' alternatively, it could also be the string `"auto"` (default), `"cross"` or #' `"no_interaction"` -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level the confidence level to use for the confidence interval -#' @param ... additional parameters passed to -#' `marginaleffects::avg_comparisons()` +#' @param conf.int (`logical`)\cr +#' Whether or not to include a confidence interval in the tidied output. +#' @param conf.level (`numeric`)\cr +#' The confidence level to use for the confidence interval (between `0` ans `1`). +#' @param ... Additional parameters passed to +#' `marginaleffects::avg_comparisons()`. #' @family marginal_tieders #' @seealso `marginaleffects::avg_comparisons()`, `tidy_avg_comparisons()` #' @export @@ -1094,16 +1116,22 @@ tidy_marginal_contrasts <- function(x, variables_list = "auto", } #' @export -#' @param model a model -#' @param interactions should combinations of variables corresponding to -#' interactions be returned? -#' @param cross if `interaction` is `TRUE`, should "cross-contrasts" be +#' @param x (a model object, e.g. `glm`)\cr +#' A model. +#' @param interactions (`logical`)\cr +#' Should combinations of variables corresponding to interactions be returned? +#' @param cross (`logical`)\cr +#' If `interaction` is `TRUE`, should "cross-contrasts" be #' computed? (if `FALSE`, only the last term of an interaction is passed to #' `variable` and the other terms are passed to `by`) -#' @param var_categorical default `variable` value for categorical variables -#' @param var_continuous default `variable` value for continuous variables -#' @param by_categorical default `by` value for categorical variables -#' @param by_continuous default `by` value for continuous variables +#' @param var_categorical ([`predictor values`][marginaleffects::comparisons()])\cr +#' Default `variable` value for categorical variables. +#' @param var_continuous ([`predictor values`][marginaleffects::comparisons()])\cr +#' Default `variable` value for continuous variables. +#' @param by_categorical ([`predictor values`][marginaleffects::comparisons()])\cr +#' Default `by` value for categorical variables. +#' @param by_continuous ([`predictor values`][marginaleffects::comparisons()])\cr +#' Default `by` value for continuous variables. #' @rdname tidy_marginal_contrasts variables_to_contrast <- function(model, interactions = TRUE, diff --git a/R/model_compute_terms_contributions.R b/R/model_compute_terms_contributions.R index ebf7908a..52cbc510 100644 --- a/R/model_compute_terms_contributions.R +++ b/R/model_compute_terms_contributions.R @@ -9,7 +9,8 @@ #' @details #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examplesIf interactive() diff --git a/R/model_get_assign.R b/R/model_get_assign.R index f7b88abb..2d6461bc 100644 --- a/R/model_get_assign.R +++ b/R/model_get_assign.R @@ -3,7 +3,8 @@ #' Return the assign attribute attached to the object returned by #' [stats::model.matrix()]. #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @seealso [stats::model.matrix()] diff --git a/R/model_get_coefficients_type.R b/R/model_get_coefficients_type.R index 5838c785..adc1ab99 100644 --- a/R/model_get_coefficients_type.R +++ b/R/model_get_coefficients_type.R @@ -3,7 +3,8 @@ #' Indicate the type of coefficient among "generic", "logistic", #' "poisson", "relative_risk" or "prop_hazard". #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_contrasts.R b/R/model_get_contrasts.R index 7fb3dcbe..77ce26ef 100644 --- a/R/model_get_contrasts.R +++ b/R/model_get_contrasts.R @@ -1,6 +1,7 @@ #' Get contrasts used in the model #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_model.R b/R/model_get_model.R index f4be320f..21b67a43 100644 --- a/R/model_get_model.R +++ b/R/model_get_model.R @@ -4,7 +4,8 @@ #' model objects that store the proper object internally (e.g. mice models). #' This function extracts that model object in those cases. #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_model_frame.R b/R/model_get_model_frame.R index 654de74c..e05538f9 100644 --- a/R/model_get_model_frame.R +++ b/R/model_get_model_frame.R @@ -6,7 +6,8 @@ #' with the same data structure or `NULL` if it is not possible #' to compute model frame from `model`. #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @seealso [stats::model.frame()] diff --git a/R/model_get_model_matrix.R b/R/model_get_model_matrix.R index 0868520f..7618ab4b 100644 --- a/R/model_get_model_matrix.R +++ b/R/model_get_model_matrix.R @@ -5,8 +5,9 @@ #' `model_get_model_matrix()` will always return an object #' with the same structure as [stats::model.matrix.default()]. #' -#' @param model a model object -#' @param ... additional arguments passed to [stats::model.matrix()] +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. +#' @param ... Additional arguments passed to [stats::model.matrix()]. #' @export #' @family model_helpers #' @seealso [stats::model.matrix()] diff --git a/R/model_get_n.R b/R/model_get_n.R index 18c54fde..10e159b5 100644 --- a/R/model_get_n.R +++ b/R/model_get_n.R @@ -20,7 +20,8 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_nlevels.R b/R/model_get_nlevels.R index eb2e745c..fc73e54d 100644 --- a/R/model_get_nlevels.R +++ b/R/model_get_nlevels.R @@ -1,6 +1,7 @@ #' Get the number of levels for each factor used in `xlevels` #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @return a tibble with two columns: `"variable"` and `"var_nlevels"` #' @export #' @family model_helpers diff --git a/R/model_get_offset.R b/R/model_get_offset.R index 9acee422..de167960 100644 --- a/R/model_get_offset.R +++ b/R/model_get_offset.R @@ -2,7 +2,8 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_pairwise_contrasts.R b/R/model_get_pairwise_contrasts.R index dfd0cdf7..c76d88d0 100644 --- a/R/model_get_pairwise_contrasts.R +++ b/R/model_get_pairwise_contrasts.R @@ -2,15 +2,20 @@ #' #' It is computed with [emmeans::emmeans()]. #' -#' @param model a model object -#' @param variables names of variables to add pairwise contrasts -#' @param pairwise_reverse determines whether to use `"pairwise"` (if `TRUE`) -#' or `"revpairwise"` (if `FALSE`), see [emmeans::contrast()] +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. +#' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr +#' Variables to add pairwise contrasts. +#' @param pairwise_reverse (`logical`)\cr +#' Determines whether to use `"pairwise"` (if `TRUE`) +#' or `"revpairwise"` (if `FALSE`), see [emmeans::contrast()]. #' @param contrasts_adjust optional adjustment method when computing contrasts, #' see [emmeans::contrast()] (if `NULL`, use `emmeans` default) -#' @param conf.level level of confidence for confidence intervals -#' @param emmeans_args list of additional parameter to pass to -#' [emmeans::emmeans()] when computing pairwise contrasts +#' @param conf.level (`numeric`)\cr +#' Level of confidence for confidence intervals (default: 95%). +#' @param emmeans_args (`logical`)\cr +#' List of additional parameter to pass to +#' [emmeans::emmeans()] when computing pairwise contrasts. #' @details #' `r lifecycle::badge("experimental")` #' For `pscl::zeroinfl()` and `pscl::hurdle()` models, pairwise contrasts are diff --git a/R/model_get_response.R b/R/model_get_response.R index 93dea815..d342c6c7 100644 --- a/R/model_get_response.R +++ b/R/model_get_response.R @@ -2,7 +2,8 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_response_variable.R b/R/model_get_response_variable.R index 3b16b5dd..0e14129d 100644 --- a/R/model_get_response_variable.R +++ b/R/model_get_response_variable.R @@ -1,6 +1,7 @@ #' Get the name of the response variable #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_get_terms.R b/R/model_get_terms.R index 9668c62a..cdf64be1 100644 --- a/R/model_get_terms.R +++ b/R/model_get_terms.R @@ -3,7 +3,8 @@ #' Return the result of [stats::terms()] applied to the model #' or `NULL` if it is not possible to get terms from `model`. #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @seealso [stats::terms()] diff --git a/R/model_get_weights.R b/R/model_get_weights.R index 8d2fd709..b5c36f64 100644 --- a/R/model_get_weights.R +++ b/R/model_get_weights.R @@ -2,7 +2,8 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @note #' For class `svrepglm` objects (GLM on a survey object with replicate weights), #' it will return the original sampling weights of the data, not the replicate diff --git a/R/model_get_xlevels.R b/R/model_get_xlevels.R index f39d02f2..317e4c63 100644 --- a/R/model_get_xlevels.R +++ b/R/model_get_xlevels.R @@ -1,6 +1,7 @@ #' Get xlevels used in the model #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_identify_variables.R b/R/model_identify_variables.R index c0ba242e..1ddfbb7a 100644 --- a/R/model_identify_variables.R +++ b/R/model_identify_variables.R @@ -1,7 +1,8 @@ #' Identify for each coefficient of a model the corresponding variable #' #' It will also identify interaction terms and intercept(s). -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @return #' A tibble with four columns: #' * `term`: coefficients of the model diff --git a/R/model_list_contrasts.R b/R/model_list_contrasts.R index 1f443fbd..e45b95df 100644 --- a/R/model_list_contrasts.R +++ b/R/model_list_contrasts.R @@ -1,6 +1,7 @@ #' List contrasts used by a model #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @return #' A tibble with three columns: #' * `variable`: variable name diff --git a/R/model_list_higher_order_variables.R b/R/model_list_higher_order_variables.R index b5360ac4..5d63e778 100644 --- a/R/model_list_higher_order_variables.R +++ b/R/model_list_higher_order_variables.R @@ -1,6 +1,7 @@ #' List higher order variables of a model #' -#' @param model a model object +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. #' @export #' @family model_helpers #' @examples diff --git a/R/model_list_terms_levels.R b/R/model_list_terms_levels.R index 20302d0e..ea83fb00 100644 --- a/R/model_list_terms_levels.R +++ b/R/model_list_terms_levels.R @@ -4,12 +4,16 @@ #' SAS, sum or successive differences contrasts (cf. [MASS::contr.sdif()]), and #' categorical variables with no contrast. #' -#' @param model a model object -#' @param label_pattern a [glue pattern][glue::glue()] for term labels (see examples) -#' @param variable_labels an optional named list or named vector of +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. +#' @param label_pattern ([`glue pattern`][glue::glue()])\cr +#' A [glue pattern][glue::glue()] for term labels (see examples). +#' @param variable_labels (`list` or `string`)\cr +#' An optional named list or named vector of #' custom variable labels passed to [model_list_variables()] -#' @param sdif_term_level for successive differences contrasts, how should term -#' levels be named? `"diff"` for `"B - A"` (default), `"ratio"` for `"B / A"` +#' @param sdif_term_level (`string`)\cr +#' For successive differences contrasts, how should term +#' levels be named? `"diff"` for `"B - A"` (default), `"ratio"` for `"B / A"`. #' @return #' A tibble with ten columns: #' * `variable`: variable diff --git a/R/model_list_variables.R b/R/model_list_variables.R index 758d8694..357d496f 100644 --- a/R/model_list_variables.R +++ b/R/model_list_variables.R @@ -2,12 +2,15 @@ #' #' Including variables used only in an interaction. #' -#' @param model a model object -#' @param labels an optional named list or named vector of -#' custom variable labels -#' @param only_variable if `TRUE`, will return only "variable" -#' column -#' @param add_var_type if `TRUE`, add `var_nlevels` and `var_type` columns +#' @param x (a model object, e.g. `glm`)\cr +#' A model object. +#' @param labels (`list` or `string`)\cr +#' An optional named list or named vector of +#' custom variable labels. +#' @param only_variable (`logical`)\cr +#' If `TRUE`, will return only "variable" column. +#' @param add_var_type (`logical`)\cr +#' If `TRUE`, add `var_nlevels` and `var_type` columns. #' @return #' A tibble with three columns: #' * `variable`: the corresponding variable diff --git a/R/scope_tidy.R b/R/scope_tidy.R index 3538f06f..8bb4f9ea 100644 --- a/R/scope_tidy.R +++ b/R/scope_tidy.R @@ -11,10 +11,12 @@ #' Note: attributes are prefixed with `"gtsummary."` to be compatible with #' selectors provided by `{gtsummary}`. #' -#' @param x a tidy tibble, with a `"variable"` column, as returned by -#' `tidy_identify_variables ()` -#' @param data an optional data frame the attributes will be added to -#' @return a data frame +#' @param x (`data.frame`)\cr +#' A tidy tibble, with a `"variable"` column, as returned by +#' [`tidy_identify_variables ()`]. +#' @param data (`data.frame`)\cr +#' An optional data frame the attributes will be added to. +#' @return A data frame. #' @export #' @examples #' mod <- lm(Sepal.Length ~ Sepal.Width * Species, data = iris) diff --git a/R/select_helpers.R b/R/select_helpers.R index cf228374..f5f1dc82 100644 --- a/R/select_helpers.R +++ b/R/select_helpers.R @@ -14,16 +14,17 @@ #' (see `vignette("broom_mixed_intro", package = "broom.mixed")`) #' @name select_helpers #' @rdname select_helpers -#' @param dichotomous logical indicating whether to include dichotomous -#' variables, default is `TRUE` -#' @param contrasts_type type of contrast to select. When `NULL`, all variables with a -#' contrast will be selected. Default is `NULL`. Select among contrast types -#' `c("treatment", "sum", "poly", "helmert", "sdif", "other")` -#' @param continuous2 (for compatibility with `{gtsummary}`) logical indicating -#' whether to include continuous2 variables, default is `TRUE`, see -#' [`gtsummary::all_continuous2()`] +#' @param dichotomous (`logical`)\cr +#' Whether to include dichotomous variables, default is `TRUE`. +#' @param contrasts_type (`string`)\cr +#' Type of contrast to select. When `NULL`, all variables with a +#' contrast will be selected. Default is `NULL`. Select among contrast types +#' `c("treatment", "sum", "poly", "helmert", "sdif", "other")`. +#' @param continuous2 (`logical`)\cr +#' Whether to include continuous2 variables, default is `TRUE`. +#' For compatibility with `{gtsummary}`), see [`gtsummary::all_continuous2()`]. #' -#' @return A character vector of column names selected +#' @return A character vector of column names selected. #' @seealso [scope_tidy()] #' @examplesIf interactive() #' glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) |> diff --git a/R/tidy_add_coefficients_type.R b/R/tidy_add_coefficients_type.R index a1ebfd23..0a6ddaaf 100644 --- a/R/tidy_add_coefficients_type.R +++ b/R/tidy_add_coefficients_type.R @@ -5,11 +5,13 @@ #' as attributes to `x` (respectively #' named `coefficients_type` and `coefficients_label`). #' -#' @param x a tidy tibble -#' @param exponentiate logical indicating whether or not to exponentiate the -#' coefficient estimates. It should be consistent with the original call to -#' [broom::tidy()] -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param exponentiate (`logical`)\cr +#' Whether or not to exponentiate the coefficient estimates. It should be +#' consistent with the original call to [broom::tidy()]. +#' @param model (a model object, e.g. `glm`)\cr +#' The corresponding model, if not attached to `x`. #' @export #' @family tidy_helpers #' @examples diff --git a/R/tidy_add_contrasts.R b/R/tidy_add_contrasts.R index 003849e7..08ab4df1 100644 --- a/R/tidy_add_contrasts.R +++ b/R/tidy_add_contrasts.R @@ -8,9 +8,12 @@ #' If the `variable` column is not yet available in `x`, #' [tidy_identify_variables()] will be automatically applied. #' -#' @param x a tidy tibble -#' @param model the corresponding model, if not attached to `x` -#' @param quiet logical argument whether broom.helpers should not return a message +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param model (a model object, e.g. `glm`)\cr +#' The corresponding model, if not attached to `x`. +#' @param quiet (`logical`)\cr +#' Whether broom.helpers should not return a message #' when `tidy_disambiguate_terms()` was already applied #' @export #' @family tidy_helpers diff --git a/R/tidy_add_estimate_to_reference_rows.R b/R/tidy_add_estimate_to_reference_rows.R index 1b723f3f..aad4b125 100644 --- a/R/tidy_add_estimate_to_reference_rows.R +++ b/R/tidy_add_estimate_to_reference_rows.R @@ -21,13 +21,16 @@ #' If the `reference_row` column is not yet available in `x`, #' [tidy_add_reference_rows()] will be automatically applied. #' -#' @param x a tidy tibble -#' @param exponentiate logical indicating whether or not to exponentiate the -#' coefficient estimates. It should be consistent with the original call to -#' [broom::tidy()] -#' @param conf.level confidence level, by default use the value indicated -#' previously in [tidy_and_attach()], used only for sum contrasts -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param exponentiate (`logical`)\cr +#' Whether or not to exponentiate the coefficient estimates. It should be +#' consistent with the original call to [broom::tidy()] +#' @param conf.level (`numeric`)\cr +#' Confidence level, by default use the value indicated +#' previously in [tidy_and_attach()], used only for sum contrasts. +#' @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 diff --git a/R/tidy_add_n.R b/R/tidy_add_n.R index 5f1ac007..4b23b756 100644 --- a/R/tidy_add_n.R +++ b/R/tidy_add_n.R @@ -57,8 +57,10 @@ #' (`N_ind`), of events (`N_event`) and of exposure time (`Exposure`) are #' stored as attributes of the returned tibble. #' -#' @param x a tidy tibble -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param model (a model object, e.g. `glm`)\cr +#' The corresponding model, if not attached to `x`. #' @export #' @family tidy_helpers #' @examplesIf interactive() diff --git a/R/tidy_add_term_labels.R b/R/tidy_add_term_labels.R index 75e3bde1..ae0be7e9 100644 --- a/R/tidy_add_term_labels.R +++ b/R/tidy_add_term_labels.R @@ -16,14 +16,17 @@ #' #' It is possible to pass a custom label for any term in `labels`, #' including interaction terms. -#' @param x a tidy tibble -#' @param labels an optional named list or named vector of -#' custom term labels -#' @param interaction_sep separator for interaction terms -#' @param categorical_terms_pattern a [glue pattern][glue::glue()] for -#' labels of categorical terms with treatment or sum contrasts -#' (see examples and [model_list_terms_levels()]) -#' @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 (`list` or `string`)\cr +#' An optional named list or named vector of custom term labels. +#' @param interaction_sep (`string`)\cr +#' Separator for interaction terms. +#' @param categorical_terms_pattern ([`glue pattern`][glue::glue()])\cr +#' A [glue pattern][glue::glue()] for labels of categorical terms with treatment +#' or sum contrasts (see examples and [model_list_terms_levels()]). +#' @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 diff --git a/R/tidy_and_attach.R b/R/tidy_and_attach.R index 421b0132..ef315eff 100644 --- a/R/tidy_and_attach.R +++ b/R/tidy_and_attach.R @@ -9,20 +9,14 @@ #' #' Use `tidy_get_model()` to get the model attached to the tibble and #' `tidy_detach_model()` to remove the attribute containing the model. -#' @param model a model to be attached/tidied -#' @param x a tibble of model terms -#' @param tidy_fun option to specify a custom tidier function -#' @param conf.int logical indicating whether or not to include a confidence -#' interval in the tidied output -#' @param conf.level level of confidence for confidence intervals (default: 95%) -#' @param exponentiate logical indicating whether or not to exponentiate the -#' coefficient estimates. This is typical for logistic, Poisson and Cox models, -#' but a bad idea if there is no log or logit link; defaults to `FALSE` -#' @param model_matrix_attr logical indicating whether model frame and model -#' matrix should be added as attributes of `model` (respectively named -#' `"model_frame"` and `"model_matrix"`) and passed through -#' @param .attributes named list of additional attributes to be attached to `x` -#' @param ... other arguments passed to `tidy_fun()` +#' @inheritParams tidy_plus_plus +#' @param model_matrix_attr (`logical`)\cr +#' Whether model frame and model matrix should be added as attributes of +#' `model` (respectively named `"model_frame"` and `"model_matrix"`) and +#' passed through +#' @param .attributes (`list`)\cr +#' Named list of additional attributes to be attached to `x`. +#' @param ... Other arguments passed to `tidy_fun()`. #' @family tidy_helpers #' @examples #' mod <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) diff --git a/R/tidy_disambiguate_terms.R b/R/tidy_disambiguate_terms.R index 8a57705d..a4eb01c0 100644 --- a/R/tidy_disambiguate_terms.R +++ b/R/tidy_disambiguate_terms.R @@ -8,9 +8,12 @@ #' is kept in a new column `original_term`. #' #' -#' @param x a tidy tibble -#' @param sep character, separator added between group name and term -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param sep (`string`)\cr +#' Separator added between group name and term. +#' @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 diff --git a/R/tidy_identify_variables.R b/R/tidy_identify_variables.R index 47780519..ec1d128d 100644 --- a/R/tidy_identify_variables.R +++ b/R/tidy_identify_variables.R @@ -19,8 +19,10 @@ #' #' For dichotomous and categorical variables, `var_nlevels` corresponds to the number #' of original levels in the corresponding variables. -#' @param x a tidy tibble -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param model (a model object, e.g. `glm`)\cr +#' The corresponding model, if not attached to `x`. #' @inheritParams tidy_plus_plus #' @export #' @seealso [model_identify_variables()] diff --git a/R/tidy_plus_plus.R b/R/tidy_plus_plus.R index 7b56540e..255984eb 100644 --- a/R/tidy_plus_plus.R +++ b/R/tidy_plus_plus.R @@ -38,7 +38,7 @@ #' A named list or a named vector of custom term labels. #' @param interaction_sep (`string`)\cr #' Separator for interaction terms. -#' @param categorical_terms_pattern (`string`)\cr +#' @param categorical_terms_pattern ([`glue pattern`][glue::glue()])\cr #' A [glue pattern][glue::glue()] for labels of categorical terms with treatment #' or sum contrasts (see [model_list_terms_levels()]). #' @param disambiguate_terms (`logical`)\cr diff --git a/R/tidy_remove_intercept.R b/R/tidy_remove_intercept.R index 0691020a..46cfd5e0 100644 --- a/R/tidy_remove_intercept.R +++ b/R/tidy_remove_intercept.R @@ -5,8 +5,10 @@ #' @details #' If the `variable` column is not yet available in `x`, #' [tidy_identify_variables()] will be automatically applied. -#' @param x a tidy tibble -#' @param model the corresponding model, if not attached to `x` +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. +#' @param model (a model object, e.g. `glm`)\cr +#' The corresponding model, if not attached to `x`. #' @export #' @family tidy_helpers #' @examples diff --git a/man/assert_package.Rd b/man/assert_package.Rd index b6e48495..28f4fe9f 100644 --- a/man/assert_package.Rd +++ b/man/assert_package.Rd @@ -21,22 +21,28 @@ .get_min_version_required(pkg, pkg_search = "broom.helpers") } \arguments{ -\item{pkg}{Package required} +\item{pkg}{(\code{string})\cr +Name of the required package.} -\item{fn}{Calling function from the user perspective. Used to write +\item{fn}{(\code{string})\cr +Name of the calling function from the user perspective. Used to write informative error messages.} -\item{pkg_search}{the package the function will search for a minimum +\item{pkg_search}{(\code{string})\cr +Name of the package the function will search for a minimum required version from.} -\item{boolean}{logical indicating whether to return a \code{TRUE}/\code{FALSE}, rather +\item{boolean}{(\code{logical})\cr +Whether to return a \code{TRUE}/\code{FALSE}, rather than error when package/package version not available. Default is \code{FALSE}, which will return an error if \code{pkg} is not installed.} -\item{remove_duplicates}{if several versions of a package are installed, +\item{remove_duplicates}{(\code{logical})\cr +If several versions of a package are installed, should only the first one be returned?} -\item{lib.loc}{location of \code{R} library trees to search through, see +\item{lib.loc}{(\code{string})\cr +Location of \code{R} library trees to search through, see \code{utils::installed.packages()}.} } \value{ diff --git a/man/dot-clean_backticks.Rd b/man/dot-clean_backticks.Rd index 1b66196f..73d3c92b 100644 --- a/man/dot-clean_backticks.Rd +++ b/man/dot-clean_backticks.Rd @@ -7,12 +7,13 @@ .clean_backticks(x, variable_names = x) } \arguments{ -\item{x}{a character vector to be cleaned} +\item{x}{(\code{string})\cr +A character vector to be cleaned.} -\item{variable_names}{list of variable names, -could be obtained with -\link[=model_list_variables]{model_list_variables(only_variable = TRUE)} -to properly take into account interaction only terms/variables} +\item{variable_names}{(\code{string})\cr +Optional vector of variable names, could be obtained with +\link[=model_list_variables]{model_list_variables(only_variable = TRUE)}, +to properly take into account interaction only terms/variables.} } \description{ Remove backticks around variable names diff --git a/man/dot-escape_regex.Rd b/man/dot-escape_regex.Rd index b62959db..9c39cd2e 100644 --- a/man/dot-escape_regex.Rd +++ b/man/dot-escape_regex.Rd @@ -8,7 +8,8 @@ meaning in a regular expression} .escape_regex(string) } \arguments{ -\item{string}{a character vector} +\item{string}{(\code{string})\cr +A character vector.} } \description{ This functions has been adapted from \code{Hmisc::escapeRegex()} diff --git a/man/model_compute_terms_contributions.Rd b/man/model_compute_terms_contributions.Rd index 87a8a0e3..6ea60a62 100644 --- a/man/model_compute_terms_contributions.Rd +++ b/man/model_compute_terms_contributions.Rd @@ -10,7 +10,8 @@ model_compute_terms_contributions(model) \method{model_compute_terms_contributions}{default}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Used for \code{\link[=model_get_n]{model_get_n()}}. For each row and term, equal 1 if this row should diff --git a/man/model_get_assign.Rd b/man/model_get_assign.Rd index a90db138..c44806c9 100644 --- a/man/model_get_assign.Rd +++ b/man/model_get_assign.Rd @@ -16,7 +16,8 @@ model_get_assign(model) \method{model_get_assign}{model_fit}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Return the assign attribute attached to the object returned by diff --git a/man/model_get_coefficients_type.Rd b/man/model_get_coefficients_type.Rd index ce7177b3..31683807 100644 --- a/man/model_get_coefficients_type.Rd +++ b/man/model_get_coefficients_type.Rd @@ -64,7 +64,8 @@ model_get_coefficients_type(model) \method{model_get_coefficients_type}{LORgee}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Indicate the type of coefficient among "generic", "logistic", diff --git a/man/model_get_contrasts.Rd b/man/model_get_contrasts.Rd index 8b9d276d..3e8c01a3 100644 --- a/man/model_get_contrasts.Rd +++ b/man/model_get_contrasts.Rd @@ -19,7 +19,8 @@ model_get_contrasts(model) \method{model_get_contrasts}{betareg}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Get contrasts used in the model diff --git a/man/model_get_model.Rd b/man/model_get_model.Rd index 522d4219..57e07949 100644 --- a/man/model_get_model.Rd +++ b/man/model_get_model.Rd @@ -13,7 +13,8 @@ model_get_model(model) \method{model_get_model}{mira}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Most model objects are proper R model objects. There are, however, some diff --git a/man/model_get_model_frame.Rd b/man/model_get_model_frame.Rd index 58756460..15e8743e 100644 --- a/man/model_get_model_frame.Rd +++ b/man/model_get_model_frame.Rd @@ -25,7 +25,8 @@ model_get_model_frame(model) \method{model_get_model_frame}{fixest}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ The structure of the object returned by \code{\link[stats:model.frame]{stats::model.frame()}} diff --git a/man/model_get_model_matrix.Rd b/man/model_get_model_matrix.Rd index add4917e..d900e342 100644 --- a/man/model_get_model_matrix.Rd +++ b/man/model_get_model_matrix.Rd @@ -46,9 +46,10 @@ model_get_model_matrix(model, ...) \method{model_get_terms}{cch}(model, ...) } \arguments{ -\item{model}{a model object} +\item{...}{Additional arguments passed to \code{\link[stats:model.matrix]{stats::model.matrix()}}.} -\item{...}{additional arguments passed to \code{\link[stats:model.matrix]{stats::model.matrix()}}} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ The structure of the object returned by \code{\link[stats:model.matrix]{stats::model.matrix()}} diff --git a/man/model_get_n.Rd b/man/model_get_n.Rd index c0e3d9cd..07351a33 100644 --- a/man/model_get_n.Rd +++ b/man/model_get_n.Rd @@ -34,7 +34,8 @@ model_get_n(model) \method{model_get_n}{tidycrr}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ For binomial and multinomial logistic models, will also return diff --git a/man/model_get_nlevels.Rd b/man/model_get_nlevels.Rd index 4c6ecebf..5694f2cb 100644 --- a/man/model_get_nlevels.Rd +++ b/man/model_get_nlevels.Rd @@ -10,7 +10,8 @@ model_get_nlevels(model) \method{model_get_nlevels}{default}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \value{ a tibble with two columns: \code{"variable"} and \code{"var_nlevels"} diff --git a/man/model_get_offset.Rd b/man/model_get_offset.Rd index 65a21c18..42643ee7 100644 --- a/man/model_get_offset.Rd +++ b/man/model_get_offset.Rd @@ -10,7 +10,8 @@ model_get_offset(model) \method{model_get_offset}{default}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ This function does not cover \code{lavaan} models (\code{NULL} is returned). diff --git a/man/model_get_pairwise_contrasts.Rd b/man/model_get_pairwise_contrasts.Rd index 294b82cb..3df9ec39 100644 --- a/man/model_get_pairwise_contrasts.Rd +++ b/man/model_get_pairwise_contrasts.Rd @@ -14,20 +14,25 @@ model_get_pairwise_contrasts( ) } \arguments{ -\item{model}{a model object} +\item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr +Variables to add pairwise contrasts.} -\item{variables}{names of variables to add pairwise contrasts} - -\item{pairwise_reverse}{determines whether to use \code{"pairwise"} (if \code{TRUE}) -or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}} +\item{pairwise_reverse}{(\code{logical})\cr +Determines whether to use \code{"pairwise"} (if \code{TRUE}) +or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}.} \item{contrasts_adjust}{optional adjustment method when computing contrasts, see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default)} -\item{conf.level}{level of confidence for confidence intervals} +\item{conf.level}{(\code{numeric})\cr +Level of confidence for confidence intervals (default: 95\%).} + +\item{emmeans_args}{(\code{logical})\cr +List of additional parameter to pass to +\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts.} -\item{emmeans_args}{list of additional parameter to pass to -\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ It is computed with \code{\link[emmeans:emmeans]{emmeans::emmeans()}}. diff --git a/man/model_get_response.Rd b/man/model_get_response.Rd index 7f73b8f2..93765d07 100644 --- a/man/model_get_response.Rd +++ b/man/model_get_response.Rd @@ -19,7 +19,8 @@ model_get_response(model) \method{model_get_response}{model_fit}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ This function does not cover \code{lavaan} models (\code{NULL} is returned). diff --git a/man/model_get_response_variable.Rd b/man/model_get_response_variable.Rd index c705d342..42b9a0c8 100644 --- a/man/model_get_response_variable.Rd +++ b/man/model_get_response_variable.Rd @@ -10,7 +10,8 @@ model_get_response_variable(model) \method{model_get_response_variable}{default}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Get the name of the response variable diff --git a/man/model_get_terms.Rd b/man/model_get_terms.Rd index 62dbcd3b..748e3378 100644 --- a/man/model_get_terms.Rd +++ b/man/model_get_terms.Rd @@ -24,7 +24,8 @@ model_get_terms(model) \method{model_get_terms}{betareg}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Return the result of \code{\link[stats:terms]{stats::terms()}} applied to the model diff --git a/man/model_get_weights.Rd b/man/model_get_weights.Rd index c3009277..5b68c1d3 100644 --- a/man/model_get_weights.Rd +++ b/man/model_get_weights.Rd @@ -19,7 +19,8 @@ model_get_weights(model) \method{model_get_weights}{model_fit}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ This function does not cover \code{lavaan} models (\code{NULL} is returned). diff --git a/man/model_get_xlevels.Rd b/man/model_get_xlevels.Rd index 0f194756..d92bc3a6 100644 --- a/man/model_get_xlevels.Rd +++ b/man/model_get_xlevels.Rd @@ -31,7 +31,8 @@ model_get_xlevels(model) \method{model_get_xlevels}{model_fit}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ Get xlevels used in the model diff --git a/man/model_identify_variables.Rd b/man/model_identify_variables.Rd index e6b28662..0bfb41dd 100644 --- a/man/model_identify_variables.Rd +++ b/man/model_identify_variables.Rd @@ -31,7 +31,8 @@ model_identify_variables(model) \method{model_identify_variables}{logitr}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \value{ A tibble with four columns: diff --git a/man/model_list_contrasts.Rd b/man/model_list_contrasts.Rd index 6c798c67..6abd2661 100644 --- a/man/model_list_contrasts.Rd +++ b/man/model_list_contrasts.Rd @@ -10,7 +10,8 @@ model_list_contrasts(model) \method{model_list_contrasts}{default}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \value{ A tibble with three columns: diff --git a/man/model_list_higher_order_variables.Rd b/man/model_list_higher_order_variables.Rd index 6ea88031..07fdbbe2 100644 --- a/man/model_list_higher_order_variables.Rd +++ b/man/model_list_higher_order_variables.Rd @@ -10,7 +10,8 @@ model_list_higher_order_variables(model) \method{model_list_higher_order_variables}{default}(model) } \arguments{ -\item{model}{a model object} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \description{ List higher order variables of a model diff --git a/man/model_list_terms_levels.Rd b/man/model_list_terms_levels.Rd index a55470bd..00b45908 100644 --- a/man/model_list_terms_levels.Rd +++ b/man/model_list_terms_levels.Rd @@ -20,15 +20,19 @@ model_list_terms_levels( ) } \arguments{ -\item{model}{a model object} +\item{label_pattern}{(\code{\link[glue:glue]{glue pattern}})\cr +A \link[glue:glue]{glue pattern} for term labels (see examples).} -\item{label_pattern}{a \link[glue:glue]{glue pattern} for term labels (see examples)} - -\item{variable_labels}{an optional named list or named vector of +\item{variable_labels}{(\code{list} or \code{string})\cr +An optional named list or named vector of custom variable labels passed to \code{\link[=model_list_variables]{model_list_variables()}}} -\item{sdif_term_level}{for successive differences contrasts, how should term -levels be named? \code{"diff"} for \code{"B - A"} (default), \code{"ratio"} for \code{"B / A"}} +\item{sdif_term_level}{(\code{string})\cr +For successive differences contrasts, how should term +levels be named? \code{"diff"} for \code{"B - A"} (default), \code{"ratio"} for \code{"B / A"}.} + +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \value{ A tibble with ten columns: diff --git a/man/model_list_variables.Rd b/man/model_list_variables.Rd index 07e02370..0e1376dc 100644 --- a/man/model_list_variables.Rd +++ b/man/model_list_variables.Rd @@ -36,15 +36,18 @@ model_list_variables( ) } \arguments{ -\item{model}{a model object} +\item{labels}{(\code{list} or \code{string})\cr +An optional named list or named vector of +custom variable labels.} -\item{labels}{an optional named list or named vector of -custom variable labels} +\item{only_variable}{(\code{logical})\cr +If \code{TRUE}, will return only "variable" column.} -\item{only_variable}{if \code{TRUE}, will return only "variable" -column} +\item{add_var_type}{(\code{logical})\cr +If \code{TRUE}, add \code{var_nlevels} and \code{var_type} columns.} -\item{add_var_type}{if \code{TRUE}, add \code{var_nlevels} and \code{var_type} columns} +\item{x}{(a model object, e.g. \code{glm})\cr +A model object.} } \value{ A tibble with three columns: diff --git a/man/scope_tidy.Rd b/man/scope_tidy.Rd index dc4e166e..0c02dae6 100644 --- a/man/scope_tidy.Rd +++ b/man/scope_tidy.Rd @@ -7,13 +7,15 @@ scope_tidy(x, data = NULL) } \arguments{ -\item{x}{a tidy tibble, with a \code{"variable"} column, as returned by -\code{tidy_identify_variables ()}} +\item{x}{(\code{data.frame})\cr +A tidy tibble, with a \code{"variable"} column, as returned by +\code{\link[=tidy_identify_variables ]{tidy_identify_variables ()}}.} -\item{data}{an optional data frame the attributes will be added to} +\item{data}{(\code{data.frame})\cr +An optional data frame the attributes will be added to.} } \value{ -a data frame +A data frame. } \description{ This function uses the information from a model tidy tibble to generate diff --git a/man/select_helpers.Rd b/man/select_helpers.Rd index 0e95e345..7897464c 100644 --- a/man/select_helpers.Rd +++ b/man/select_helpers.Rd @@ -31,19 +31,20 @@ all_contrasts( ) } \arguments{ -\item{continuous2}{(for compatibility with \code{{gtsummary}}) logical indicating -whether to include continuous2 variables, default is \code{TRUE}, see -\code{\link[gtsummary:select_helpers]{gtsummary::all_continuous2()}}} +\item{continuous2}{(\code{logical})\cr +Whether to include continuous2 variables, default is \code{TRUE}. +For compatibility with \code{{gtsummary}}), see \code{\link[gtsummary:select_helpers]{gtsummary::all_continuous2()}}.} -\item{dichotomous}{logical indicating whether to include dichotomous -variables, default is \code{TRUE}} +\item{dichotomous}{(\code{logical})\cr +Whether to include dichotomous variables, default is \code{TRUE}.} -\item{contrasts_type}{type of contrast to select. When \code{NULL}, all variables with a -contrast will be selected. Default is \code{NULL}. Select among contrast types -\code{c("treatment", "sum", "poly", "helmert", "sdif", "other")}} +\item{contrasts_type}{(\code{string})\cr +Type of contrast to select. When \code{NULL}, all variables with a +contrast will be selected. Default is \code{NULL}. Select among contrast types +\code{c("treatment", "sum", "poly", "helmert", "sdif", "other")}.} } \value{ -A character vector of column names selected +A character vector of column names selected. } \description{ Set of functions to supplement the \emph{tidyselect} set of diff --git a/man/seq_range.Rd b/man/seq_range.Rd index 397b69f1..723b0ff7 100644 --- a/man/seq_range.Rd +++ b/man/seq_range.Rd @@ -7,9 +7,11 @@ seq_range(x, length.out = 25) } \arguments{ -\item{x}{a numeric vector} +\item{x}{(\code{numeric})\cr +A numeric vector.} -\item{length.out}{desired length of the sequence} +\item{length.out}{(\code{integer})\cr +Desired length of the sequence (a positive integer).} } \value{ a numeric vector diff --git a/man/tidy_add_coefficients_type.Rd b/man/tidy_add_coefficients_type.Rd index 214fd474..9dbb459c 100644 --- a/man/tidy_add_coefficients_type.Rd +++ b/man/tidy_add_coefficients_type.Rd @@ -11,13 +11,15 @@ tidy_add_coefficients_type( ) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{exponentiate}{logical indicating whether or not to exponentiate the -coefficient estimates. It should be consistent with the original call to -\code{\link[broom:reexports]{broom::tidy()}}} +\item{exponentiate}{(\code{logical})\cr +Whether or not to exponentiate the coefficient estimates. It should be +consistent with the original call to \code{\link[broom:reexports]{broom::tidy()}}.} -\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}.} } \description{ Add the type of coefficients ("generic", "logistic", "poisson", diff --git a/man/tidy_add_contrasts.Rd b/man/tidy_add_contrasts.Rd index 7cf09c69..5ede20d2 100644 --- a/man/tidy_add_contrasts.Rd +++ b/man/tidy_add_contrasts.Rd @@ -7,11 +7,14 @@ tidy_add_contrasts(x, model = tidy_get_model(x), quiet = FALSE) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\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}{logical argument whether broom.helpers should not return a message +\item{quiet}{(\code{logical})\cr +Whether broom.helpers should not return a message when \code{tidy_disambiguate_terms()} was already applied} } \description{ diff --git a/man/tidy_add_estimate_to_reference_rows.Rd b/man/tidy_add_estimate_to_reference_rows.Rd index c957b8ec..6e53d157 100644 --- a/man/tidy_add_estimate_to_reference_rows.Rd +++ b/man/tidy_add_estimate_to_reference_rows.Rd @@ -13,16 +13,19 @@ tidy_add_estimate_to_reference_rows( ) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{exponentiate}{logical indicating whether or not to exponentiate the -coefficient estimates. It should be consistent with the original call to -\code{\link[broom:reexports]{broom::tidy()}}} +\item{exponentiate}{(\code{logical})\cr +Whether or not to exponentiate the coefficient estimates. It should be +consistent with the original call to \code{\link[broom:reexports]{broom::tidy()}}} -\item{conf.level}{confidence level, by default use the value indicated -previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}, used only for sum contrasts} +\item{conf.level}{(\code{numeric})\cr +Confidence level, by default use the value indicated +previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}, used only for sum contrasts.} -\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 diff --git a/man/tidy_add_n.Rd b/man/tidy_add_n.Rd index 1b3c63a0..01e9b64e 100644 --- a/man/tidy_add_n.Rd +++ b/man/tidy_add_n.Rd @@ -7,9 +7,11 @@ tidy_add_n(x, model = tidy_get_model(x)) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\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}.} } \description{ Add the number of observations in a new column \code{n_obs}, taking into account any diff --git a/man/tidy_add_term_labels.Rd b/man/tidy_add_term_labels.Rd index 3c167384..d904e865 100644 --- a/man/tidy_add_term_labels.Rd +++ b/man/tidy_add_term_labels.Rd @@ -15,18 +15,21 @@ tidy_add_term_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 term labels} +\item{labels}{(\code{list} or \code{string})\cr +An optional named list or named vector of custom term labels.} -\item{interaction_sep}{separator for interaction terms} +\item{interaction_sep}{(\code{string})\cr +Separator for interaction terms.} -\item{categorical_terms_pattern}{a \link[glue:glue]{glue pattern} for -labels of categorical terms with treatment or sum contrasts -(see examples and \code{\link[=model_list_terms_levels]{model_list_terms_levels()}})} +\item{categorical_terms_pattern}{(\code{\link[glue:glue]{glue pattern}})\cr +A \link[glue:glue]{glue pattern} for labels of categorical terms with treatment +or sum contrasts (see examples and \code{\link[=model_list_terms_levels]{model_list_terms_levels()}}).} -\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 diff --git a/man/tidy_all_effects.Rd b/man/tidy_all_effects.Rd index 9e4373ad..c0433606 100644 --- a/man/tidy_all_effects.Rd +++ b/man/tidy_all_effects.Rd @@ -7,14 +7,16 @@ tidy_all_effects(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to \code{effects::allEffects()}} +\item{...}{Additional parameters passed to \code{effects::allEffects()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_attach_model.Rd b/man/tidy_attach_model.Rd index c3a0551f..cecbf1ee 100644 --- a/man/tidy_attach_model.Rd +++ b/man/tidy_attach_model.Rd @@ -24,28 +24,32 @@ tidy_get_model(x) tidy_detach_model(x) } \arguments{ -\item{x}{a tibble of model terms} +\item{model}{(a model object, e.g. \code{glm})\cr +A model to be attached/tidied.} -\item{model}{a model to be attached/tidied} +\item{.attributes}{(\code{list})\cr +Named list of additional attributes to be attached to \code{x}.} -\item{.attributes}{named list of additional attributes to be attached to \code{x}} +\item{tidy_fun}{(\code{function})\cr +Option to specify a custom tidier function.} -\item{tidy_fun}{option to specify a custom tidier function} +\item{conf.int}{(\code{logical})\cr +Should confidence intervals be computed? (see \code{\link[broom:reexports]{broom::tidy()}})} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.level}{(\code{numeric})\cr +Level of confidence for confidence intervals (default: 95\%).} -\item{conf.level}{level of confidence for confidence intervals (default: 95\%)} +\item{exponentiate}{(\code{logical})\cr +Whether or not to exponentiate the coefficient estimates. +This is typical for logistic, Poisson and Cox models, +but a bad idea if there is no log or logit link; defaults to \code{FALSE}.} -\item{exponentiate}{logical indicating whether or not to exponentiate the -coefficient estimates. This is typical for logistic, Poisson and Cox models, -but a bad idea if there is no log or logit link; defaults to \code{FALSE}} +\item{model_matrix_attr}{(\code{logical})\cr +Whether model frame and model matrix should be added as attributes of +\code{model} (respectively named \code{"model_frame"} and \code{"model_matrix"}) and +passed through} -\item{model_matrix_attr}{logical indicating whether model frame and model -matrix should be added as attributes of \code{model} (respectively named -\code{"model_frame"} and \code{"model_matrix"}) and passed through} - -\item{...}{other arguments passed to \code{tidy_fun()}} +\item{...}{Other arguments passed to \code{tidy_fun()}.} } \description{ To facilitate the use of broom helpers with pipe, it is recommended to diff --git a/man/tidy_avg_comparisons.Rd b/man/tidy_avg_comparisons.Rd index e2cc917a..bc22bc5f 100644 --- a/man/tidy_avg_comparisons.Rd +++ b/man/tidy_avg_comparisons.Rd @@ -7,15 +7,17 @@ tidy_avg_comparisons(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to -\code{marginaleffects::avg_comparisons()}} +\item{...}{Additional parameters passed to +\code{marginaleffects::avg_comparisons()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_avg_slopes.Rd b/man/tidy_avg_slopes.Rd index 0fce5980..707c12fb 100644 --- a/man/tidy_avg_slopes.Rd +++ b/man/tidy_avg_slopes.Rd @@ -7,15 +7,17 @@ tidy_avg_slopes(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to -\code{marginaleffects::avg_slopes()}} +\item{...}{Additional parameters passed to +\code{marginaleffects::avg_slopes()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_broom.Rd b/man/tidy_broom.Rd index 29f13c08..68d354ea 100644 --- a/man/tidy_broom.Rd +++ b/man/tidy_broom.Rd @@ -7,9 +7,10 @@ tidy_broom(x, ...) } \arguments{ -\item{x}{a model to tidy} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{...}{additional parameters passed to \code{broom::tidy()}} +\item{...}{Additional parameters passed to \code{broom::tidy()}.} } \description{ Tidy with \code{broom::tidy()} and checks that all arguments are used diff --git a/man/tidy_disambiguate_terms.Rd b/man/tidy_disambiguate_terms.Rd index 65711dd9..31f78165 100644 --- a/man/tidy_disambiguate_terms.Rd +++ b/man/tidy_disambiguate_terms.Rd @@ -7,11 +7,14 @@ tidy_disambiguate_terms(x, sep = ".", model = tidy_get_model(x), quiet = FALSE) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\item{sep}{character, separator added between group name and term} +\item{sep}{(\code{string})\cr +Separator added between group name and term.} -\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 diff --git a/man/tidy_ggpredict.Rd b/man/tidy_ggpredict.Rd index d7f3449a..552915b3 100644 --- a/man/tidy_ggpredict.Rd +++ b/man/tidy_ggpredict.Rd @@ -7,14 +7,16 @@ tidy_ggpredict(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to \code{ggeffects::ggpredict()}} +\item{...}{Additional parameters passed to \code{ggeffects::ggpredict()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_identify_variables.Rd b/man/tidy_identify_variables.Rd index 1b74192b..525c6240 100644 --- a/man/tidy_identify_variables.Rd +++ b/man/tidy_identify_variables.Rd @@ -7,9 +7,11 @@ tidy_identify_variables(x, model = tidy_get_model(x), quiet = FALSE) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\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 diff --git a/man/tidy_marginal_contrasts.Rd b/man/tidy_marginal_contrasts.Rd index c265577d..53d1f345 100644 --- a/man/tidy_marginal_contrasts.Rd +++ b/man/tidy_marginal_contrasts.Rd @@ -24,37 +24,43 @@ variables_to_contrast( ) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model.} -\item{variables_list}{a list whose elements will be sequentially passed to +\item{variables_list}{(\code{list} or \code{string})\cr +A list whose elements will be sequentially passed to \code{variables} in \code{marginaleffects::avg_comparisons()} (see details below); alternatively, it could also be the string \code{"auto"} (default), \code{"cross"} or \code{"no_interaction"}} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to -\code{marginaleffects::avg_comparisons()}} +\item{...}{Additional parameters passed to +\code{marginaleffects::avg_comparisons()}.} -\item{model}{a model} +\item{interactions}{(\code{logical})\cr +Should combinations of variables corresponding to interactions be returned?} -\item{interactions}{should combinations of variables corresponding to -interactions be returned?} - -\item{cross}{if \code{interaction} is \code{TRUE}, should "cross-contrasts" be +\item{cross}{(\code{logical})\cr +If \code{interaction} is \code{TRUE}, should "cross-contrasts" be computed? (if \code{FALSE}, only the last term of an interaction is passed to \code{variable} and the other terms are passed to \code{by})} -\item{var_categorical}{default \code{variable} value for categorical variables} +\item{var_categorical}{(\code{\link[marginaleffects:comparisons]{predictor values}})\cr +Default \code{variable} value for categorical variables.} -\item{var_continuous}{default \code{variable} value for continuous variables} +\item{var_continuous}{(\code{\link[marginaleffects:comparisons]{predictor values}})\cr +Default \code{variable} value for continuous variables.} -\item{by_categorical}{default \code{by} value for categorical variables} +\item{by_categorical}{(\code{\link[marginaleffects:comparisons]{predictor values}})\cr +Default \code{by} value for categorical variables.} -\item{by_continuous}{default \code{by} value for continuous variables} +\item{by_continuous}{(\code{\link[marginaleffects:comparisons]{predictor values}})\cr +Default \code{by} value for continuous variables.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_marginal_means.Rd b/man/tidy_marginal_means.Rd index ef97dfcb..87260560 100644 --- a/man/tidy_marginal_means.Rd +++ b/man/tidy_marginal_means.Rd @@ -7,15 +7,17 @@ tidy_marginal_means(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to -\code{marginaleffects::marginal_means()}} +\item{...}{Additional parameters passed to +\code{marginaleffects::marginal_means()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/tidy_marginal_predictions.Rd b/man/tidy_marginal_predictions.Rd index 27466555..5325aa7a 100644 --- a/man/tidy_marginal_predictions.Rd +++ b/man/tidy_marginal_predictions.Rd @@ -24,29 +24,33 @@ variables_to_predict( plot_marginal_predictions(x, variables_list = "auto", conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{variables_list}{a list whose elements will be sequentially passed to +\item{variables_list}{(\code{list} or \code{string})\cr +A list whose elements will be sequentially passed to \code{variables} in \code{marginaleffects::avg_predictions()} (see details below); alternatively, it could also be the string \code{"auto"} (default) or -\code{"no_interaction"}} +\code{"no_interaction"}.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to -\code{marginaleffects::avg_predictions()}} +\item{...}{Additional parameters passed to +\code{marginaleffects::avg_predictions()}.} -\item{model}{a model} - -\item{interactions}{should combinations of variables corresponding to +\item{interactions}{(\code{logical})\cr +Should combinations of variables corresponding to interactions be returned?} -\item{categorical}{default value for categorical variables} +\item{categorical}{(\code{\link[marginaleffects:predictions]{predictor values}})\cr +Default values for categorical variables.} -\item{continuous}{default value for continuous variables} +\item{continuous}{(\code{\link[marginaleffects:predictions]{predictor values}})\cr +Default values for continuous variables.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_margins.Rd b/man/tidy_margins.Rd index dd7324bc..822fc575 100644 --- a/man/tidy_margins.Rd +++ b/man/tidy_margins.Rd @@ -7,14 +7,16 @@ tidy_margins(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to \code{margins::margins()}} +\item{...}{Additional parameters passed to \code{margins::margins()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} diff --git a/man/tidy_multgee.Rd b/man/tidy_multgee.Rd index 32cb51df..294c82e4 100644 --- a/man/tidy_multgee.Rd +++ b/man/tidy_multgee.Rd @@ -7,14 +7,16 @@ tidy_multgee(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a \code{multgee::nomLORgee()} or a \code{multgee::ordLORgee()} model} +\item{x}{(\code{LORgee})\cr +A \code{multgee::nomLORgee()} or a \code{multgee::ordLORgee()} model.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to \code{parameters::model_parameters()}} +\item{...}{Additional parameters passed to \code{parameters::model_parameters()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/tidy_parameters.Rd b/man/tidy_parameters.Rd index 8685ece1..d9c34fff 100644 --- a/man/tidy_parameters.Rd +++ b/man/tidy_parameters.Rd @@ -7,14 +7,16 @@ tidy_parameters(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to \code{\link[parameters:model_parameters]{parameters::model_parameters()}}} +\item{...}{Additional parameters passed to \code{\link[parameters:model_parameters]{parameters::model_parameters()}}.} } \description{ Use \code{\link[parameters:model_parameters]{parameters::model_parameters()}} to tidy a model and apply diff --git a/man/tidy_plus_plus.Rd b/man/tidy_plus_plus.Rd index f8ce35e1..2f05300c 100644 --- a/man/tidy_plus_plus.Rd +++ b/man/tidy_plus_plus.Rd @@ -69,7 +69,7 @@ A named list or a named vector of custom term labels.} \item{interaction_sep}{(\code{string})\cr Separator for interaction terms.} -\item{categorical_terms_pattern}{(\code{string})\cr +\item{categorical_terms_pattern}{(\code{\link[glue:glue]{glue pattern}})\cr A \link[glue:glue]{glue pattern} for labels of categorical terms with treatment or sum contrasts (see \code{\link[=model_list_terms_levels]{model_list_terms_levels()}}).} diff --git a/man/tidy_remove_intercept.Rd b/man/tidy_remove_intercept.Rd index 4de3ed9f..b037e97d 100644 --- a/man/tidy_remove_intercept.Rd +++ b/man/tidy_remove_intercept.Rd @@ -7,9 +7,11 @@ tidy_remove_intercept(x, model = tidy_get_model(x)) } \arguments{ -\item{x}{a tidy tibble} +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} -\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}.} } \description{ Will remove terms where \code{var_type == "intercept"}. diff --git a/man/tidy_with_broom_or_parameters.Rd b/man/tidy_with_broom_or_parameters.Rd index a1055a7b..400241bd 100644 --- a/man/tidy_with_broom_or_parameters.Rd +++ b/man/tidy_with_broom_or_parameters.Rd @@ -7,15 +7,17 @@ tidy_with_broom_or_parameters(x, conf.int = TRUE, conf.level = 0.95, ...) } \arguments{ -\item{x}{a model} +\item{x}{(a model object, e.g. \code{glm})\cr +A model to be tidied.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{...}{additional parameters passed to \code{broom::tidy()} or -\code{parameters::model_parameters()}} +\item{...}{Additional parameters passed to \code{broom::tidy()} or +\code{parameters::model_parameters()}.} } \description{ Try to tidy a model with \code{broom::tidy()}. If it fails, will try to tidy the diff --git a/man/tidy_zeroinfl.Rd b/man/tidy_zeroinfl.Rd index acd6ae9c..0def1620 100644 --- a/man/tidy_zeroinfl.Rd +++ b/man/tidy_zeroinfl.Rd @@ -7,17 +7,19 @@ tidy_zeroinfl(x, conf.int = TRUE, conf.level = 0.95, component = NULL, ...) } \arguments{ -\item{x}{a \code{pscl::zeroinfl()} or a \code{pscl::hurdle()} model} +\item{x}{(\code{zeroinfl} or \code{hurdle})\cr +A \code{pscl::zeroinfl()} or a \code{pscl::hurdle()} model.} -\item{conf.int}{logical indicating whether or not to include a confidence -interval in the tidied output} +\item{conf.int}{(\code{logical})\cr +Whether or not to include a confidence interval in the tidied output.} -\item{conf.level}{the confidence level to use for the confidence interval} +\item{conf.level}{(\code{numeric})\cr +The confidence level to use for the confidence interval (between \code{0} ans \code{1}).} -\item{component}{\code{NULL} or one of \code{"all"}, \code{"conditional"}, \code{"zi"}, or -\code{"zero_inflated"}} +\item{component}{(\code{string})\cr +\code{NULL} or one of \code{"all"}, \code{"conditional"}, \code{"zi"}, or \code{"zero_inflated"}.} -\item{...}{additional parameters passed to \code{parameters::model_parameters()}} +\item{...}{Additional parameters passed to \code{parameters::model_parameters()}.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} From 44974563aeecadf74ad67ff4d790c531d26e848b Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 17:28:53 +0200 Subject: [PATCH 15/16] oups --- R/model_compute_terms_contributions.R | 2 +- R/model_get_assign.R | 2 +- R/model_get_coefficients_type.R | 2 +- R/model_get_contrasts.R | 2 +- R/model_get_model.R | 2 +- R/model_get_model_frame.R | 2 +- R/model_get_model_matrix.R | 2 +- R/model_get_n.R | 2 +- R/model_get_nlevels.R | 2 +- R/model_get_offset.R | 2 +- R/model_get_pairwise_contrasts.R | 2 +- R/model_get_response.R | 2 +- R/model_get_response_variable.R | 2 +- R/model_get_terms.R | 2 +- R/model_get_weights.R | 2 +- R/model_get_xlevels.R | 2 +- R/model_identify_variables.R | 2 +- R/model_list_contrasts.R | 2 +- R/model_list_higher_order_variables.R | 2 +- R/model_list_terms_levels.R | 2 +- R/model_list_variables.R | 2 +- R/scope_tidy.R | 2 +- R/tidy_and_attach.R | 2 ++ man/model_compute_terms_contributions.Rd | 2 +- man/model_get_assign.Rd | 2 +- man/model_get_coefficients_type.Rd | 2 +- man/model_get_contrasts.Rd | 2 +- man/model_get_model.Rd | 2 +- man/model_get_model_frame.Rd | 2 +- man/model_get_model_matrix.Rd | 6 +++--- man/model_get_n.Rd | 2 +- man/model_get_nlevels.Rd | 2 +- man/model_get_offset.Rd | 2 +- man/model_get_pairwise_contrasts.Rd | 6 +++--- man/model_get_response.Rd | 2 +- man/model_get_response_variable.Rd | 2 +- man/model_get_terms.Rd | 2 +- man/model_get_weights.Rd | 2 +- man/model_get_xlevels.Rd | 2 +- man/model_identify_variables.Rd | 2 +- man/model_list_contrasts.Rd | 2 +- man/model_list_higher_order_variables.Rd | 2 +- man/model_list_terms_levels.Rd | 6 +++--- man/model_list_variables.Rd | 6 +++--- man/scope_tidy.Rd | 2 +- man/tidy_attach_model.Rd | 3 +++ 46 files changed, 57 insertions(+), 52 deletions(-) diff --git a/R/model_compute_terms_contributions.R b/R/model_compute_terms_contributions.R index 52cbc510..b9f7cd84 100644 --- a/R/model_compute_terms_contributions.R +++ b/R/model_compute_terms_contributions.R @@ -9,7 +9,7 @@ #' @details #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_assign.R b/R/model_get_assign.R index 2d6461bc..ecaaa5a9 100644 --- a/R/model_get_assign.R +++ b/R/model_get_assign.R @@ -3,7 +3,7 @@ #' Return the assign attribute attached to the object returned by #' [stats::model.matrix()]. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_coefficients_type.R b/R/model_get_coefficients_type.R index adc1ab99..32d0de2b 100644 --- a/R/model_get_coefficients_type.R +++ b/R/model_get_coefficients_type.R @@ -3,7 +3,7 @@ #' Indicate the type of coefficient among "generic", "logistic", #' "poisson", "relative_risk" or "prop_hazard". #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_contrasts.R b/R/model_get_contrasts.R index 77ce26ef..5d7367fc 100644 --- a/R/model_get_contrasts.R +++ b/R/model_get_contrasts.R @@ -1,6 +1,6 @@ #' Get contrasts used in the model #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_model.R b/R/model_get_model.R index 21b67a43..0a235645 100644 --- a/R/model_get_model.R +++ b/R/model_get_model.R @@ -4,7 +4,7 @@ #' model objects that store the proper object internally (e.g. mice models). #' This function extracts that model object in those cases. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_model_frame.R b/R/model_get_model_frame.R index e05538f9..9503923c 100644 --- a/R/model_get_model_frame.R +++ b/R/model_get_model_frame.R @@ -6,7 +6,7 @@ #' with the same data structure or `NULL` if it is not possible #' to compute model frame from `model`. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_model_matrix.R b/R/model_get_model_matrix.R index 7618ab4b..75b70fb7 100644 --- a/R/model_get_model_matrix.R +++ b/R/model_get_model_matrix.R @@ -5,7 +5,7 @@ #' `model_get_model_matrix()` will always return an object #' with the same structure as [stats::model.matrix.default()]. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @param ... Additional arguments passed to [stats::model.matrix()]. #' @export diff --git a/R/model_get_n.R b/R/model_get_n.R index 10e159b5..7e2d6297 100644 --- a/R/model_get_n.R +++ b/R/model_get_n.R @@ -20,7 +20,7 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_nlevels.R b/R/model_get_nlevels.R index fc73e54d..7bf3cec3 100644 --- a/R/model_get_nlevels.R +++ b/R/model_get_nlevels.R @@ -1,6 +1,6 @@ #' Get the number of levels for each factor used in `xlevels` #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @return a tibble with two columns: `"variable"` and `"var_nlevels"` #' @export diff --git a/R/model_get_offset.R b/R/model_get_offset.R index de167960..73663e18 100644 --- a/R/model_get_offset.R +++ b/R/model_get_offset.R @@ -2,7 +2,7 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_pairwise_contrasts.R b/R/model_get_pairwise_contrasts.R index c76d88d0..a9a9f658 100644 --- a/R/model_get_pairwise_contrasts.R +++ b/R/model_get_pairwise_contrasts.R @@ -2,7 +2,7 @@ #' #' It is computed with [emmeans::emmeans()]. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' Variables to add pairwise contrasts. diff --git a/R/model_get_response.R b/R/model_get_response.R index d342c6c7..1098e24a 100644 --- a/R/model_get_response.R +++ b/R/model_get_response.R @@ -2,7 +2,7 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_response_variable.R b/R/model_get_response_variable.R index 0e14129d..f6c0574b 100644 --- a/R/model_get_response_variable.R +++ b/R/model_get_response_variable.R @@ -1,6 +1,6 @@ #' Get the name of the response variable #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_terms.R b/R/model_get_terms.R index cdf64be1..84ba9fd1 100644 --- a/R/model_get_terms.R +++ b/R/model_get_terms.R @@ -3,7 +3,7 @@ #' Return the result of [stats::terms()] applied to the model #' or `NULL` if it is not possible to get terms from `model`. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_get_weights.R b/R/model_get_weights.R index b5c36f64..5907a9e5 100644 --- a/R/model_get_weights.R +++ b/R/model_get_weights.R @@ -2,7 +2,7 @@ #' #' This function does not cover `lavaan` models (`NULL` is returned). #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @note #' For class `svrepglm` objects (GLM on a survey object with replicate weights), diff --git a/R/model_get_xlevels.R b/R/model_get_xlevels.R index 317e4c63..ceddf9dc 100644 --- a/R/model_get_xlevels.R +++ b/R/model_get_xlevels.R @@ -1,6 +1,6 @@ #' Get xlevels used in the model #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_identify_variables.R b/R/model_identify_variables.R index 1ddfbb7a..b1664613 100644 --- a/R/model_identify_variables.R +++ b/R/model_identify_variables.R @@ -1,7 +1,7 @@ #' Identify for each coefficient of a model the corresponding variable #' #' It will also identify interaction terms and intercept(s). -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @return #' A tibble with four columns: diff --git a/R/model_list_contrasts.R b/R/model_list_contrasts.R index e45b95df..c3cb8459 100644 --- a/R/model_list_contrasts.R +++ b/R/model_list_contrasts.R @@ -1,6 +1,6 @@ #' List contrasts used by a model #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @return #' A tibble with three columns: diff --git a/R/model_list_higher_order_variables.R b/R/model_list_higher_order_variables.R index 5d63e778..2158cb38 100644 --- a/R/model_list_higher_order_variables.R +++ b/R/model_list_higher_order_variables.R @@ -1,6 +1,6 @@ #' List higher order variables of a model #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @export #' @family model_helpers diff --git a/R/model_list_terms_levels.R b/R/model_list_terms_levels.R index ea83fb00..23cbad91 100644 --- a/R/model_list_terms_levels.R +++ b/R/model_list_terms_levels.R @@ -4,7 +4,7 @@ #' SAS, sum or successive differences contrasts (cf. [MASS::contr.sdif()]), and #' categorical variables with no contrast. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @param label_pattern ([`glue pattern`][glue::glue()])\cr #' A [glue pattern][glue::glue()] for term labels (see examples). diff --git a/R/model_list_variables.R b/R/model_list_variables.R index 357d496f..18fa3fdd 100644 --- a/R/model_list_variables.R +++ b/R/model_list_variables.R @@ -2,7 +2,7 @@ #' #' Including variables used only in an interaction. #' -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model object. #' @param labels (`list` or `string`)\cr #' An optional named list or named vector of diff --git a/R/scope_tidy.R b/R/scope_tidy.R index 8bb4f9ea..b75fc9d1 100644 --- a/R/scope_tidy.R +++ b/R/scope_tidy.R @@ -13,7 +13,7 @@ #' #' @param x (`data.frame`)\cr #' A tidy tibble, with a `"variable"` column, as returned by -#' [`tidy_identify_variables ()`]. +#' [`tidy_identify_variables()`]. #' @param data (`data.frame`)\cr #' An optional data frame the attributes will be added to. #' @return A data frame. diff --git a/R/tidy_and_attach.R b/R/tidy_and_attach.R index ef315eff..c58c4441 100644 --- a/R/tidy_and_attach.R +++ b/R/tidy_and_attach.R @@ -10,6 +10,8 @@ #' Use `tidy_get_model()` to get the model attached to the tibble and #' `tidy_detach_model()` to remove the attribute containing the model. #' @inheritParams tidy_plus_plus +#' @param x (`data.frame`)\cr +#' A tidy tibble as produced by `tidy_*()` functions. #' @param model_matrix_attr (`logical`)\cr #' Whether model frame and model matrix should be added as attributes of #' `model` (respectively named `"model_frame"` and `"model_matrix"`) and diff --git a/man/model_compute_terms_contributions.Rd b/man/model_compute_terms_contributions.Rd index 6ea60a62..d4fee298 100644 --- a/man/model_compute_terms_contributions.Rd +++ b/man/model_compute_terms_contributions.Rd @@ -10,7 +10,7 @@ model_compute_terms_contributions(model) \method{model_compute_terms_contributions}{default}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_assign.Rd b/man/model_get_assign.Rd index c44806c9..4e8db668 100644 --- a/man/model_get_assign.Rd +++ b/man/model_get_assign.Rd @@ -16,7 +16,7 @@ model_get_assign(model) \method{model_get_assign}{model_fit}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_coefficients_type.Rd b/man/model_get_coefficients_type.Rd index 31683807..4f7affec 100644 --- a/man/model_get_coefficients_type.Rd +++ b/man/model_get_coefficients_type.Rd @@ -64,7 +64,7 @@ model_get_coefficients_type(model) \method{model_get_coefficients_type}{LORgee}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_contrasts.Rd b/man/model_get_contrasts.Rd index 3e8c01a3..61256529 100644 --- a/man/model_get_contrasts.Rd +++ b/man/model_get_contrasts.Rd @@ -19,7 +19,7 @@ model_get_contrasts(model) \method{model_get_contrasts}{betareg}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_model.Rd b/man/model_get_model.Rd index 57e07949..6a7a8681 100644 --- a/man/model_get_model.Rd +++ b/man/model_get_model.Rd @@ -13,7 +13,7 @@ model_get_model(model) \method{model_get_model}{mira}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_model_frame.Rd b/man/model_get_model_frame.Rd index 15e8743e..6771f7dd 100644 --- a/man/model_get_model_frame.Rd +++ b/man/model_get_model_frame.Rd @@ -25,7 +25,7 @@ model_get_model_frame(model) \method{model_get_model_frame}{fixest}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_model_matrix.Rd b/man/model_get_model_matrix.Rd index d900e342..c3b25c10 100644 --- a/man/model_get_model_matrix.Rd +++ b/man/model_get_model_matrix.Rd @@ -46,10 +46,10 @@ model_get_model_matrix(model, ...) \method{model_get_terms}{cch}(model, ...) } \arguments{ -\item{...}{Additional arguments passed to \code{\link[stats:model.matrix]{stats::model.matrix()}}.} - -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} + +\item{...}{Additional arguments passed to \code{\link[stats:model.matrix]{stats::model.matrix()}}.} } \description{ The structure of the object returned by \code{\link[stats:model.matrix]{stats::model.matrix()}} diff --git a/man/model_get_n.Rd b/man/model_get_n.Rd index 07351a33..429ed6ac 100644 --- a/man/model_get_n.Rd +++ b/man/model_get_n.Rd @@ -34,7 +34,7 @@ model_get_n(model) \method{model_get_n}{tidycrr}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_nlevels.Rd b/man/model_get_nlevels.Rd index 5694f2cb..f25db42d 100644 --- a/man/model_get_nlevels.Rd +++ b/man/model_get_nlevels.Rd @@ -10,7 +10,7 @@ model_get_nlevels(model) \method{model_get_nlevels}{default}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \value{ diff --git a/man/model_get_offset.Rd b/man/model_get_offset.Rd index 42643ee7..ae1c9445 100644 --- a/man/model_get_offset.Rd +++ b/man/model_get_offset.Rd @@ -10,7 +10,7 @@ model_get_offset(model) \method{model_get_offset}{default}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_pairwise_contrasts.Rd b/man/model_get_pairwise_contrasts.Rd index 3df9ec39..fb2d175d 100644 --- a/man/model_get_pairwise_contrasts.Rd +++ b/man/model_get_pairwise_contrasts.Rd @@ -14,6 +14,9 @@ model_get_pairwise_contrasts( ) } \arguments{ +\item{model}{(a model object, e.g. \code{glm})\cr +A model object.} + \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr Variables to add pairwise contrasts.} @@ -30,9 +33,6 @@ Level of confidence for confidence intervals (default: 95\%).} \item{emmeans_args}{(\code{logical})\cr List of additional parameter to pass to \code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts.} - -\item{x}{(a model object, e.g. \code{glm})\cr -A model object.} } \description{ It is computed with \code{\link[emmeans:emmeans]{emmeans::emmeans()}}. diff --git a/man/model_get_response.Rd b/man/model_get_response.Rd index 93765d07..8fa07cec 100644 --- a/man/model_get_response.Rd +++ b/man/model_get_response.Rd @@ -19,7 +19,7 @@ model_get_response(model) \method{model_get_response}{model_fit}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_response_variable.Rd b/man/model_get_response_variable.Rd index 42b9a0c8..1734d362 100644 --- a/man/model_get_response_variable.Rd +++ b/man/model_get_response_variable.Rd @@ -10,7 +10,7 @@ model_get_response_variable(model) \method{model_get_response_variable}{default}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_terms.Rd b/man/model_get_terms.Rd index 748e3378..f5caf80a 100644 --- a/man/model_get_terms.Rd +++ b/man/model_get_terms.Rd @@ -24,7 +24,7 @@ model_get_terms(model) \method{model_get_terms}{betareg}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_weights.Rd b/man/model_get_weights.Rd index 5b68c1d3..8de20cfe 100644 --- a/man/model_get_weights.Rd +++ b/man/model_get_weights.Rd @@ -19,7 +19,7 @@ model_get_weights(model) \method{model_get_weights}{model_fit}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_get_xlevels.Rd b/man/model_get_xlevels.Rd index d92bc3a6..494df97e 100644 --- a/man/model_get_xlevels.Rd +++ b/man/model_get_xlevels.Rd @@ -31,7 +31,7 @@ model_get_xlevels(model) \method{model_get_xlevels}{model_fit}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_identify_variables.Rd b/man/model_identify_variables.Rd index 0bfb41dd..dbf1d46c 100644 --- a/man/model_identify_variables.Rd +++ b/man/model_identify_variables.Rd @@ -31,7 +31,7 @@ model_identify_variables(model) \method{model_identify_variables}{logitr}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \value{ diff --git a/man/model_list_contrasts.Rd b/man/model_list_contrasts.Rd index 6abd2661..6f0e5455 100644 --- a/man/model_list_contrasts.Rd +++ b/man/model_list_contrasts.Rd @@ -10,7 +10,7 @@ model_list_contrasts(model) \method{model_list_contrasts}{default}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \value{ diff --git a/man/model_list_higher_order_variables.Rd b/man/model_list_higher_order_variables.Rd index 07fdbbe2..fdda8848 100644 --- a/man/model_list_higher_order_variables.Rd +++ b/man/model_list_higher_order_variables.Rd @@ -10,7 +10,7 @@ model_list_higher_order_variables(model) \method{model_list_higher_order_variables}{default}(model) } \arguments{ -\item{x}{(a model object, e.g. \code{glm})\cr +\item{model}{(a model object, e.g. \code{glm})\cr A model object.} } \description{ diff --git a/man/model_list_terms_levels.Rd b/man/model_list_terms_levels.Rd index 00b45908..5330481c 100644 --- a/man/model_list_terms_levels.Rd +++ b/man/model_list_terms_levels.Rd @@ -20,6 +20,9 @@ model_list_terms_levels( ) } \arguments{ +\item{model}{(a model object, e.g. \code{glm})\cr +A model object.} + \item{label_pattern}{(\code{\link[glue:glue]{glue pattern}})\cr A \link[glue:glue]{glue pattern} for term labels (see examples).} @@ -30,9 +33,6 @@ custom variable labels passed to \code{\link[=model_list_variables]{model_list_v \item{sdif_term_level}{(\code{string})\cr For successive differences contrasts, how should term levels be named? \code{"diff"} for \code{"B - A"} (default), \code{"ratio"} for \code{"B / A"}.} - -\item{x}{(a model object, e.g. \code{glm})\cr -A model object.} } \value{ A tibble with ten columns: diff --git a/man/model_list_variables.Rd b/man/model_list_variables.Rd index 0e1376dc..41c2949e 100644 --- a/man/model_list_variables.Rd +++ b/man/model_list_variables.Rd @@ -36,6 +36,9 @@ model_list_variables( ) } \arguments{ +\item{model}{(a model object, e.g. \code{glm})\cr +A model object.} + \item{labels}{(\code{list} or \code{string})\cr An optional named list or named vector of custom variable labels.} @@ -45,9 +48,6 @@ If \code{TRUE}, will return only "variable" column.} \item{add_var_type}{(\code{logical})\cr If \code{TRUE}, add \code{var_nlevels} and \code{var_type} columns.} - -\item{x}{(a model object, e.g. \code{glm})\cr -A model object.} } \value{ A tibble with three columns: diff --git a/man/scope_tidy.Rd b/man/scope_tidy.Rd index 0c02dae6..0ec99a41 100644 --- a/man/scope_tidy.Rd +++ b/man/scope_tidy.Rd @@ -9,7 +9,7 @@ scope_tidy(x, data = NULL) \arguments{ \item{x}{(\code{data.frame})\cr A tidy tibble, with a \code{"variable"} column, as returned by -\code{\link[=tidy_identify_variables ]{tidy_identify_variables ()}}.} +\code{\link[=tidy_identify_variables]{tidy_identify_variables()}}.} \item{data}{(\code{data.frame})\cr An optional data frame the attributes will be added to.} diff --git a/man/tidy_attach_model.Rd b/man/tidy_attach_model.Rd index cecbf1ee..271fcc2f 100644 --- a/man/tidy_attach_model.Rd +++ b/man/tidy_attach_model.Rd @@ -24,6 +24,9 @@ tidy_get_model(x) tidy_detach_model(x) } \arguments{ +\item{x}{(\code{data.frame})\cr +A tidy tibble as produced by \verb{tidy_*()} functions.} + \item{model}{(a model object, e.g. \code{glm})\cr A model to be attached/tidied.} From 43b60be15f916e78f6c0871ae158675bc9a3b1dd Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 23 Aug 2024 17:41:37 +0200 Subject: [PATCH 16/16] doc fixes --- R/marginal_tidiers.R | 6 +++--- man/tidy_marginal_contrasts.Rd | 5 ++++- man/tidy_marginal_predictions.Rd | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/marginal_tidiers.R b/R/marginal_tidiers.R index 0ba1725d..75b27abf 100644 --- a/R/marginal_tidiers.R +++ b/R/marginal_tidiers.R @@ -707,8 +707,8 @@ tidy_marginal_predictions <- function(x, variables_list = "auto", } #' @export -#' @param x (a model object, e.g. `glm`)\cr -#' A model to be tidied. +#' @param model (a model object, e.g. `glm`)\cr +#' A model. #' @param interactions (`logical`)\cr #' Should combinations of variables corresponding to #' interactions be returned? @@ -1116,7 +1116,7 @@ tidy_marginal_contrasts <- function(x, variables_list = "auto", } #' @export -#' @param x (a model object, e.g. `glm`)\cr +#' @param model (a model object, e.g. `glm`)\cr #' A model. #' @param interactions (`logical`)\cr #' Should combinations of variables corresponding to interactions be returned? diff --git a/man/tidy_marginal_contrasts.Rd b/man/tidy_marginal_contrasts.Rd index 53d1f345..8c627a42 100644 --- a/man/tidy_marginal_contrasts.Rd +++ b/man/tidy_marginal_contrasts.Rd @@ -25,7 +25,7 @@ variables_to_contrast( } \arguments{ \item{x}{(a model object, e.g. \code{glm})\cr -A model.} +A model to be tidied.} \item{variables_list}{(\code{list} or \code{string})\cr A list whose elements will be sequentially passed to @@ -42,6 +42,9 @@ The confidence level to use for the confidence interval (between \code{0} ans \c \item{...}{Additional parameters passed to \code{marginaleffects::avg_comparisons()}.} +\item{model}{(a model object, e.g. \code{glm})\cr +A model.} + \item{interactions}{(\code{logical})\cr Should combinations of variables corresponding to interactions be returned?} diff --git a/man/tidy_marginal_predictions.Rd b/man/tidy_marginal_predictions.Rd index 5325aa7a..25762745 100644 --- a/man/tidy_marginal_predictions.Rd +++ b/man/tidy_marginal_predictions.Rd @@ -42,6 +42,9 @@ The confidence level to use for the confidence interval (between \code{0} ans \c \item{...}{Additional parameters passed to \code{marginaleffects::avg_predictions()}.} +\item{model}{(a model object, e.g. \code{glm})\cr +A model.} + \item{interactions}{(\code{logical})\cr Should combinations of variables corresponding to interactions be returned?}