From dc274ebd6d4692c19f116fcf85629f754ea2a2bc Mon Sep 17 00:00:00 2001 From: Joseph Larmarange Date: Fri, 14 Oct 2022 17:26:19 +0200 Subject: [PATCH] simplify test for execution time --- R/ggcoef_model.R | 93 +++++++++++++++++++++++---------------------- man/ggcoef_model.Rd | 92 +++++++++++++++++++++++--------------------- 2 files changed, 96 insertions(+), 89 deletions(-) diff --git a/R/ggcoef_model.R b/R/ggcoef_model.R index baf1484..a7e25da 100644 --- a/R/ggcoef_model.R +++ b/R/ggcoef_model.R @@ -27,51 +27,11 @@ #' @param ... parameters passed to [ggcoef_plot()] #' @return A `ggplot2` plot or a `tibble` if `return_data = TRUE`. #' @export -#' @examplesIf requireNamespace("reshape") -#' \donttest{ -#' data(tips, package = "reshape") -#' mod_simple <- lm(tip ~ day + time + total_bill, data = tips) -#' ggcoef_model(mod_simple) -#' -#' # custom variable labels -#' # you can use the labelled package to define variable labels -#' # before computing model -#' if (requireNamespace("labelled")) { -#' tips_labelled <- tips %>% -#' labelled::set_variable_labels( -#' day = "Day of the week", -#' time = "Lunch or Dinner", -#' total_bill = "Bill's total" -#' ) -#' mod_labelled <- lm(tip ~ day + time + total_bill, data = tips_labelled) -#' ggcoef_model(mod_labelled) -#' } -#' -#' # you can provide custom variable labels with 'variable_labels' -#' ggcoef_model( -#' mod_simple, -#' variable_labels = c( -#' day = "Week day", -#' time = "Time (lunch or dinner ?)", -#' total_bill = "Total of the bill" -#' ) -#' ) -#' # if labels are too long, you can use 'facet_labeller' to wrap them -#' ggcoef_model( -#' mod_simple, -#' variable_labels = c( -#' day = "Week day", -#' time = "Time (lunch or dinner ?)", -#' total_bill = "Total of the bill" -#' ), -#' facet_labeller = ggplot2::label_wrap_gen(10) -#' ) -#' -#' # do not display variable facets but add colour guide -#' ggcoef_model(mod_simple, facet_row = NULL, colour_guide = TRUE) -#' } -#' #' @examples +#' mod <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) +#' ggcoef_model(mod) +#' +#' \donttest{ #' # a logistic regression example #' d_titanic <- as.data.frame(Titanic) #' d_titanic$Survived <- factor(d_titanic$Survived, c("No", "Yes")) @@ -85,7 +45,6 @@ #' # use 'exponentiate = TRUE' to get the Odds Ratio #' ggcoef_model(mod_titanic, exponentiate = TRUE) #' -#' \donttest{ #' # display intercepts #' ggcoef_model(mod_titanic, exponentiate = TRUE, intercept = TRUE) #' @@ -141,6 +100,50 @@ #' ggcoef_model(mod2) #' } #' } +#' @examplesIf requireNamespace("reshape") +#' +#' \donttest{ +#' data(tips, package = "reshape") +#' mod_simple <- lm(tip ~ day + time + total_bill, data = tips) +#' ggcoef_model(mod_simple) +#' +#' # custom variable labels +#' # you can use the labelled package to define variable labels +#' # before computing model +#' if (requireNamespace("labelled")) { +#' tips_labelled <- tips %>% +#' labelled::set_variable_labels( +#' day = "Day of the week", +#' time = "Lunch or Dinner", +#' total_bill = "Bill's total" +#' ) +#' mod_labelled <- lm(tip ~ day + time + total_bill, data = tips_labelled) +#' ggcoef_model(mod_labelled) +#' } +#' +#' # you can provide custom variable labels with 'variable_labels' +#' ggcoef_model( +#' mod_simple, +#' variable_labels = c( +#' day = "Week day", +#' time = "Time (lunch or dinner ?)", +#' total_bill = "Total of the bill" +#' ) +#' ) +#' # if labels are too long, you can use 'facet_labeller' to wrap them +#' ggcoef_model( +#' mod_simple, +#' variable_labels = c( +#' day = "Week day", +#' time = "Time (lunch or dinner ?)", +#' total_bill = "Total of the bill" +#' ), +#' facet_labeller = ggplot2::label_wrap_gen(10) +#' ) +#' +#' # do not display variable facets but add colour guide +#' ggcoef_model(mod_simple, facet_row = NULL, colour_guide = TRUE) +#' } ggcoef_model <- function( model, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, diff --git a/man/ggcoef_model.Rd b/man/ggcoef_model.Rd index d113cfd..b9f1d71 100644 --- a/man/ggcoef_model.Rd +++ b/man/ggcoef_model.Rd @@ -255,50 +255,10 @@ multinomial logistic regressions performed with \code{\link[nnet:multinom]{nnet: }} \examples{ -\dontshow{if (requireNamespace("reshape")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -\donttest{ -data(tips, package = "reshape") -mod_simple <- lm(tip ~ day + time + total_bill, data = tips) -ggcoef_model(mod_simple) +mod <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) +ggcoef_model(mod) -# custom variable labels -# you can use the labelled package to define variable labels -# before computing model -if (requireNamespace("labelled")) { - tips_labelled <- tips \%>\% - labelled::set_variable_labels( - day = "Day of the week", - time = "Lunch or Dinner", - total_bill = "Bill's total" - ) - mod_labelled <- lm(tip ~ day + time + total_bill, data = tips_labelled) - ggcoef_model(mod_labelled) -} - -# you can provide custom variable labels with 'variable_labels' -ggcoef_model( - mod_simple, - variable_labels = c( - day = "Week day", - time = "Time (lunch or dinner ?)", - total_bill = "Total of the bill" - ) -) -# if labels are too long, you can use 'facet_labeller' to wrap them -ggcoef_model( - mod_simple, - variable_labels = c( - day = "Week day", - time = "Time (lunch or dinner ?)", - total_bill = "Total of the bill" - ), - facet_labeller = ggplot2::label_wrap_gen(10) -) - -# do not display variable facets but add colour guide -ggcoef_model(mod_simple, facet_row = NULL, colour_guide = TRUE) -} -\dontshow{\}) # examplesIf} +\donttest{ # a logistic regression example d_titanic <- as.data.frame(Titanic) d_titanic$Survived <- factor(d_titanic$Survived, c("No", "Yes")) @@ -312,7 +272,6 @@ mod_titanic <- glm( # use 'exponentiate = TRUE' to get the Odds Ratio ggcoef_model(mod_titanic, exponentiate = TRUE) -\donttest{ # display intercepts ggcoef_model(mod_titanic, exponentiate = TRUE, intercept = TRUE) @@ -368,6 +327,51 @@ if (requireNamespace("emmeans")) { ggcoef_model(mod2) } } +\dontshow{if (requireNamespace("reshape")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} + +\donttest{ +data(tips, package = "reshape") +mod_simple <- lm(tip ~ day + time + total_bill, data = tips) +ggcoef_model(mod_simple) + +# custom variable labels +# you can use the labelled package to define variable labels +# before computing model +if (requireNamespace("labelled")) { + tips_labelled <- tips \%>\% + labelled::set_variable_labels( + day = "Day of the week", + time = "Lunch or Dinner", + total_bill = "Bill's total" + ) + mod_labelled <- lm(tip ~ day + time + total_bill, data = tips_labelled) + ggcoef_model(mod_labelled) +} + +# you can provide custom variable labels with 'variable_labels' +ggcoef_model( + mod_simple, + variable_labels = c( + day = "Week day", + time = "Time (lunch or dinner ?)", + total_bill = "Total of the bill" + ) +) +# if labels are too long, you can use 'facet_labeller' to wrap them +ggcoef_model( + mod_simple, + variable_labels = c( + day = "Week day", + time = "Time (lunch or dinner ?)", + total_bill = "Total of the bill" + ), + facet_labeller = ggplot2::label_wrap_gen(10) +) + +# do not display variable facets but add colour guide +ggcoef_model(mod_simple, facet_row = NULL, colour_guide = TRUE) +} +\dontshow{\}) # examplesIf} \donttest{ # Use ggcoef_compare() for comparing several models on the same plot