From 5089e293c4d694b0b26412d2e4b465dbab9d4487 Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Mon, 7 Oct 2024 19:14:56 +0200 Subject: [PATCH] compatibility with R 4.1 --- DESCRIPTION | 2 +- NEWS.md | 1 + R/model_identify_variables.R | 11 +++++------ R/model_list_variables.R | 25 ++++++++++++------------- man/model_identify_variables.Rd | 11 +++++------ man/model_list_variables.Rd | 25 ++++++++++++------------- tests/testthat/test-add_term_labels.R | 7 +++---- 7 files changed, 39 insertions(+), 43 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2446123d..deb45db9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ License: GPL (>= 3) URL: https://larmarange.github.io/broom.helpers/, https://github.com/larmarange/broom.helpers BugReports: https://github.com/larmarange/broom.helpers/issues Depends: - R (>= 4.2) + R (>= 4.1) Imports: broom (>= 0.8), cards, diff --git a/NEWS.md b/NEWS.md index 9a7954b2..65a2afc3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ - variable labels are now returned by `model_list_variables()` for `svycoxph` models (#275) +- compatibility with R version 4.1 minimum (#276) # broom.helpers 1.17.0 diff --git a/R/model_identify_variables.R b/R/model_identify_variables.R index b1664613..3d950d14 100644 --- a/R/model_identify_variables.R +++ b/R/model_identify_variables.R @@ -26,12 +26,11 @@ #' ) |> #' model_identify_variables() #' -#' iris |> -#' lm( -#' Sepal.Length ~ poly(Sepal.Width, 2) + Species, -#' data = _, -#' contrasts = list(Species = contr.sum) -#' ) |> +#' lm( +#' Sepal.Length ~ poly(Sepal.Width, 2) + Species, +#' data = iris, +#' contrasts = list(Species = contr.sum) +#' ) |> #' model_identify_variables() model_identify_variables <- function(model) { UseMethod("model_identify_variables") diff --git a/R/model_list_variables.R b/R/model_list_variables.R index 18fa3fdd..e9ff0efa 100644 --- a/R/model_list_variables.R +++ b/R/model_list_variables.R @@ -40,20 +40,19 @@ #' ) |> #' model_list_variables() #' -#' iris |> -#' lm( -#' Sepal.Length ~ poly(Sepal.Width, 2) + Species, -#' data = _, -#' contrasts = list(Species = contr.sum) -#' ) |> -#' model_list_variables() -#' -#' glm( -#' response ~ poly(age, 3) + stage + grade * trt, -#' na.omit(gtsummary::trial), -#' family = binomial, +#' lm( +#' Sepal.Length ~ poly(Sepal.Width, 2) + Species, +#' data = iris, +#' contrasts = list(Species = contr.sum) #' ) |> -#' model_list_variables() +#' model_list_variables() +#' +#' glm( +#' response ~ poly(age, 3) + stage + grade * trt, +#' na.omit(gtsummary::trial), +#' family = binomial, +#' ) |> +#' model_list_variables() #' } model_list_variables <- function(model, labels = NULL, only_variable = FALSE, add_var_type = FALSE) { diff --git a/man/model_identify_variables.Rd b/man/model_identify_variables.Rd index dbf1d46c..0c333a93 100644 --- a/man/model_identify_variables.Rd +++ b/man/model_identify_variables.Rd @@ -60,12 +60,11 @@ glm( ) |> model_identify_variables() -iris |> - lm( - Sepal.Length ~ poly(Sepal.Width, 2) + Species, - data = _, - contrasts = list(Species = contr.sum) - ) |> +lm( + Sepal.Length ~ poly(Sepal.Width, 2) + Species, + data = iris, + contrasts = list(Species = contr.sum) +) |> model_identify_variables() } \seealso{ diff --git a/man/model_list_variables.Rd b/man/model_list_variables.Rd index 41c2949e..84623e62 100644 --- a/man/model_list_variables.Rd +++ b/man/model_list_variables.Rd @@ -84,20 +84,19 @@ if (.assert_package("gtsummary", boolean = TRUE)) { ) |> model_list_variables() - iris |> - lm( - Sepal.Length ~ poly(Sepal.Width, 2) + Species, - data = _, - contrasts = list(Species = contr.sum) - ) |> - model_list_variables() - - glm( - response ~ poly(age, 3) + stage + grade * trt, - na.omit(gtsummary::trial), - family = binomial, +lm( + Sepal.Length ~ poly(Sepal.Width, 2) + Species, + data = iris, + contrasts = list(Species = contr.sum) ) |> - model_list_variables() + model_list_variables() + +glm( + response ~ poly(age, 3) + stage + grade * trt, + na.omit(gtsummary::trial), + family = binomial, +) |> + model_list_variables() } \dontshow{\}) # examplesIf} } diff --git a/tests/testthat/test-add_term_labels.R b/tests/testthat/test-add_term_labels.R index 54abf9bd..252dde02 100644 --- a/tests/testthat/test-add_term_labels.R +++ b/tests/testthat/test-add_term_labels.R @@ -254,11 +254,10 @@ test_that("tidy_add_term_labels() works with variables having non standard name" ) ) - res <- gtsummary::trial |> - dplyr::select(response, `age at dx` = age, `drug type` = trt) |> - lm( + res <- lm( response ~ `age at dx` + `drug type`, - data = _ + data = gtsummary::trial |> + dplyr::select(response, `age at dx` = age, `drug type` = trt) ) |> tidy_and_attach() |> tidy_add_variable_labels(list(`age at dx` = "AGGGGGGGE")) |>