From f751ee9895e011130a3a7c50f07903dd381bfefe Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Tue, 5 Jul 2022 19:00:12 +0200 Subject: [PATCH] reducing time of examples --- R/model_compute_terms_contributions.R | 2 +- R/select_helpers.R | 2 +- R/tidy_add_header_rows.R | 2 +- R/tidy_add_n.R | 2 +- R/tidy_add_reference_rows.R | 2 +- R/tidy_add_term_labels.R | 2 +- R/tidy_plus_plus.R | 63 ++++++++++++----------- man/model_compute_terms_contributions.Rd | 2 + man/select_helpers.Rd | 2 + man/tidy_add_header_rows.Rd | 2 +- man/tidy_add_n.Rd | 2 + man/tidy_add_reference_rows.Rd | 2 +- man/tidy_add_term_labels.Rd | 2 + man/tidy_plus_plus.Rd | 65 ++++++++++++------------ 14 files changed, 81 insertions(+), 71 deletions(-) diff --git a/R/model_compute_terms_contributions.R b/R/model_compute_terms_contributions.R index c2fe96b9..4863cfa7 100644 --- a/R/model_compute_terms_contributions.R +++ b/R/model_compute_terms_contributions.R @@ -12,7 +12,7 @@ #' @param model a model object #' @export #' @family model_helpers -#' @examples +#' @examplesIf interactive() #' mod <- lm(Sepal.Length ~ Sepal.Width, iris) #' mod %>% model_compute_terms_contributions() #' diff --git a/R/select_helpers.R b/R/select_helpers.R index cfadab86..84a8a713 100644 --- a/R/select_helpers.R +++ b/R/select_helpers.R @@ -21,7 +21,7 @@ #' `c("treatment", "sum", "poly", "helmert", "other")` #' #' @return A character vector of column names selected -#' @examples +#' @examplesIf interactive() #' glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) %>% #' tidy_plus_plus(exponentiate = TRUE, include = all_categorical()) #' diff --git a/R/tidy_add_header_rows.R b/R/tidy_add_header_rows.R index 385e1adb..8c6fd247 100644 --- a/R/tidy_add_header_rows.R +++ b/R/tidy_add_header_rows.R @@ -27,7 +27,7 @@ #' @inheritParams tidy_plus_plus #' @export #' @family tidy_helpers -#' @examplesIf .assert_package("gtsummary", boolean = TRUE) +#' @examplesIf .assert_package("gtsummary", boolean = TRUE) & interactive() #' df <- Titanic %>% #' dplyr::as_tibble() %>% #' dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) diff --git a/R/tidy_add_n.R b/R/tidy_add_n.R index 790a9b73..8efaaf23 100644 --- a/R/tidy_add_n.R +++ b/R/tidy_add_n.R @@ -60,7 +60,7 @@ #' @param model the corresponding model, if not attached to `x` #' @export #' @family tidy_helpers -#' @examples +#' @examplesIf interactive() #' lm(Petal.Length ~ ., data = iris) %>% #' tidy_and_attach() %>% #' tidy_add_n() diff --git a/R/tidy_add_reference_rows.R b/R/tidy_add_reference_rows.R index 5ed44ee0..d6790156 100644 --- a/R/tidy_add_reference_rows.R +++ b/R/tidy_add_reference_rows.R @@ -27,7 +27,7 @@ #' @inheritParams tidy_plus_plus #' @export #' @family tidy_helpers -#' @examplesIf .assert_package("gtsummary", boolean = TRUE) +#' @examplesIf .assert_package("gtsummary", boolean = TRUE) & interactive() #' df <- Titanic %>% #' dplyr::as_tibble() %>% #' dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) diff --git a/R/tidy_add_term_labels.R b/R/tidy_add_term_labels.R index 5e8aa72a..d6d8b9e9 100644 --- a/R/tidy_add_term_labels.R +++ b/R/tidy_add_term_labels.R @@ -27,7 +27,7 @@ #' @inheritParams tidy_plus_plus #' @export #' @family tidy_helpers -#' @examples +#' @examplesIf interactive() #' df <- Titanic %>% #' dplyr::as_tibble() %>% #' dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) %>% diff --git a/R/tidy_plus_plus.R b/R/tidy_plus_plus.R index c7b65d52..5ec848f1 100644 --- a/R/tidy_plus_plus.R +++ b/R/tidy_plus_plus.R @@ -63,39 +63,40 @@ #' Class = "Passenger's class", #' Sex = "Gender" #' ) +#' if (interactive()) { +#' ex2 <- glm( +#' Survived ~ Class + Age * Sex, +#' data = df, weights = df$n, +#' family = binomial +#' ) %>% +#' tidy_plus_plus( +#' exponentiate = TRUE, +#' add_reference_rows = FALSE, +#' categorical_terms_pattern = "{level} / {reference_level}", +#' add_n = TRUE +#' ) +#' ex2 #' -#' ex2 <- glm( -#' Survived ~ Class + Age * Sex, -#' data = df, weights = df$n, -#' family = binomial -#' ) %>% -#' tidy_plus_plus( -#' exponentiate = TRUE, -#' add_reference_rows = FALSE, -#' categorical_terms_pattern = "{level} / {reference_level}", -#' add_n = TRUE -#' ) -#' ex2 -#' -#' ex3 <- -#' glm( -#' response ~ poly(age, 3) + stage + grade * trt, -#' na.omit(gtsummary::trial), -#' family = binomial, -#' contrasts = list( -#' stage = contr.treatment(4, base = 3), -#' grade = contr.sum +#' ex3 <- +#' glm( +#' response ~ poly(age, 3) + stage + grade * trt, +#' na.omit(gtsummary::trial), +#' family = binomial, +#' contrasts = list( +#' stage = contr.treatment(4, base = 3), +#' grade = contr.sum +#' ) +#' ) %>% +#' tidy_plus_plus( +#' exponentiate = TRUE, +#' variable_labels = c(age = "Age (in years)"), +#' add_header_rows = TRUE, +#' show_single_row = all_dichotomous(), +#' term_labels = c("poly(age, 3)3" = "Cubic age"), +#' keep_model = TRUE #' ) -#' ) %>% -#' tidy_plus_plus( -#' exponentiate = TRUE, -#' variable_labels = c(age = "Age (in years)"), -#' add_header_rows = TRUE, -#' show_single_row = all_dichotomous(), -#' term_labels = c("poly(age, 3)3" = "Cubic age"), -#' keep_model = TRUE -#' ) -#' ex3 +#' ex3 +#' } #' @export tidy_plus_plus <- function( model, diff --git a/man/model_compute_terms_contributions.Rd b/man/model_compute_terms_contributions.Rd index 4c187188..dba588e5 100644 --- a/man/model_compute_terms_contributions.Rd +++ b/man/model_compute_terms_contributions.Rd @@ -21,6 +21,7 @@ be taken into account in the estimate of the number of observations, This function does not cover \code{lavaan} models (\code{NULL} is returned). } \examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mod <- lm(Sepal.Length ~ Sepal.Width, iris) mod \%>\% model_compute_terms_contributions() @@ -62,6 +63,7 @@ d <- dplyr::as_tibble(Titanic) \%>\% ) mod <- glm(cbind(n_survived, n_dead) ~ Class * Age + Sex, data = d, family = binomial) mod \%>\% model_compute_terms_contributions() +\dontshow{\}) # examplesIf} } \seealso{ Other model_helpers: diff --git a/man/select_helpers.Rd b/man/select_helpers.Rd index 9f6c0643..e9dfe118 100644 --- a/man/select_helpers.Rd +++ b/man/select_helpers.Rd @@ -56,6 +56,7 @@ values from a mixed model } } \examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) \%>\% tidy_plus_plus(exponentiate = TRUE, include = all_categorical()) @@ -65,4 +66,5 @@ glm(response ~ age + trt + grade + stage, contrasts = list(trt = contr.SAS, grade = contr.sum, stage = contr.poly)) \%>\% tidy_plus_plus(exponentiate = TRUE, include = all_contrasts(c("treatment", "sum"))) +\dontshow{\}) # examplesIf} } diff --git a/man/tidy_add_header_rows.Rd b/man/tidy_add_header_rows.Rd index 6501618c..948e3705 100644 --- a/man/tidy_add_header_rows.Rd +++ b/man/tidy_add_header_rows.Rd @@ -51,7 +51,7 @@ If the \code{label} column is not yet available in \code{x}, \code{\link[=tidy_add_term_labels]{tidy_add_term_labels()}} will be automatically applied. } \examples{ -\dontshow{if (.assert_package("gtsummary", boolean = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (.assert_package("gtsummary", boolean = TRUE) & interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} df <- Titanic \%>\% dplyr::as_tibble() \%>\% dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) diff --git a/man/tidy_add_n.Rd b/man/tidy_add_n.Rd index 149eace0..45c4881a 100644 --- a/man/tidy_add_n.Rd +++ b/man/tidy_add_n.Rd @@ -70,6 +70,7 @@ of exposure time (\code{Exposure}) are stored as attributes of the returned tibble. } \examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(Petal.Length ~ ., data = iris) \%>\% tidy_and_attach() \%>\% tidy_add_n() @@ -119,6 +120,7 @@ glm( ) \%>\% tidy_and_attach() \%>\% tidy_add_n() +\dontshow{\}) # examplesIf} } \seealso{ Other tidy_helpers: diff --git a/man/tidy_add_reference_rows.Rd b/man/tidy_add_reference_rows.Rd index e87e8d05..fefb341a 100644 --- a/man/tidy_add_reference_rows.Rd +++ b/man/tidy_add_reference_rows.Rd @@ -47,7 +47,7 @@ rather than before. Similarly, it is better to apply \code{tidy_add_reference_rows()} before \code{\link[=tidy_add_n]{tidy_add_n()}}. } \examples{ -\dontshow{if (.assert_package("gtsummary", boolean = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (.assert_package("gtsummary", boolean = TRUE) & interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} df <- Titanic \%>\% dplyr::as_tibble() \%>\% dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) diff --git a/man/tidy_add_term_labels.Rd b/man/tidy_add_term_labels.Rd index e50d6ebc..3787954a 100644 --- a/man/tidy_add_term_labels.Rd +++ b/man/tidy_add_term_labels.Rd @@ -55,6 +55,7 @@ It is possible to pass a custom label for any term in \code{labels}, including interaction terms. } \examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} df <- Titanic \%>\% dplyr::as_tibble() \%>\% dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) \%>\% @@ -74,6 +75,7 @@ mod \%>\% interaction_sep = " x ", categorical_terms_pattern = "{level} / {reference_level}" ) +\dontshow{\}) # examplesIf} } \seealso{ Other tidy_helpers: diff --git a/man/tidy_plus_plus.Rd b/man/tidy_plus_plus.Rd index 1e6c967d..d5686750 100644 --- a/man/tidy_plus_plus.Rd +++ b/man/tidy_plus_plus.Rd @@ -121,39 +121,40 @@ df <- Titanic \%>\% Class = "Passenger's class", Sex = "Gender" ) - -ex2 <- glm( - Survived ~ Class + Age * Sex, - data = df, weights = df$n, - family = binomial -) \%>\% - tidy_plus_plus( - exponentiate = TRUE, - add_reference_rows = FALSE, - categorical_terms_pattern = "{level} / {reference_level}", - add_n = TRUE - ) -ex2 - -ex3 <- - glm( - response ~ poly(age, 3) + stage + grade * trt, - na.omit(gtsummary::trial), - family = binomial, - contrasts = list( - stage = contr.treatment(4, base = 3), - grade = contr.sum - ) +if (interactive()) { + ex2 <- glm( + Survived ~ Class + Age * Sex, + data = df, weights = df$n, + family = binomial ) \%>\% - tidy_plus_plus( - exponentiate = TRUE, - variable_labels = c(age = "Age (in years)"), - add_header_rows = TRUE, - show_single_row = all_dichotomous(), - term_labels = c("poly(age, 3)3" = "Cubic age"), - keep_model = TRUE - ) -ex3 + tidy_plus_plus( + exponentiate = TRUE, + add_reference_rows = FALSE, + categorical_terms_pattern = "{level} / {reference_level}", + add_n = TRUE + ) + ex2 + + ex3 <- + glm( + response ~ poly(age, 3) + stage + grade * trt, + na.omit(gtsummary::trial), + family = binomial, + contrasts = list( + stage = contr.treatment(4, base = 3), + grade = contr.sum + ) + ) \%>\% + tidy_plus_plus( + exponentiate = TRUE, + variable_labels = c(age = "Age (in years)"), + add_header_rows = TRUE, + show_single_row = all_dichotomous(), + term_labels = c("poly(age, 3)3" = "Cubic age"), + keep_model = TRUE + ) + ex3 +} \dontshow{\}) # examplesIf} } \seealso{