Skip to content

Commit

Permalink
YAGNI grouped_list helper
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Sep 24, 2023
1 parent 3aa18d2 commit d662145
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 30 deletions.
6 changes: 3 additions & 3 deletions R/ggbarstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ ggbarstats <- function(data,
)

subtitle_df <- .eval_f(contingency_table, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

# Bayes Factor caption
if (type != "bayes" && bf.message && isFALSE(paired)) {
caption_df <- .eval_f(contingency_table, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand All @@ -130,7 +130,7 @@ ggbarstats <- function(data,
plotBar <- ggplot(descriptive_df, aes({{ y }}, perc, fill = {{ x }})) +
geom_bar(stat = "identity", position = "fill", color = "black") +
scale_y_continuous(
labels = function(x) paste0(x * 100L, "%"),
labels = ~ insight::format_percent(., digits = 0L),
breaks = seq(from = 0.0, to = 1.0, by = 0.10),
minor_breaks = seq(from = 0.05, to = 0.95, by = 0.10)
) +
Expand Down
4 changes: 2 additions & 2 deletions R/ggbetweenstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ ggbetweenstats <- function(data,

.f <- .f_switch(test)
subtitle_df <- .eval_f(.f, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

if (type == "parametric" && bf.message) {
caption_df <- .eval_f(.f, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand Down
6 changes: 3 additions & 3 deletions R/ggcoefstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ ggcoefstats <- function(x,

if (!is.null(glance_df) && all(c("AIC", "BIC") %in% names(glance_df))) {
glance_df %<>% mutate(expression = list(parse(text = glue("list(AIC=='{format_value(AIC, 0L)}', BIC=='{format_value(BIC, 0L)}')"))))
caption <- extract_expression(glance_df)
caption <- .extract_expression(glance_df)
}

# meta analysis -------------------------
Expand All @@ -249,12 +249,12 @@ ggcoefstats <- function(x,

# frequentist
subtitle_df <- meta_analysis(tidy_df, type = meta.type, k = k)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

# Bayesian
if (meta.type == "parametric" && bf.message) {
caption_df <- suppressWarnings(meta_analysis(tidy_df, type = "bayes", k = k))
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand Down
4 changes: 2 additions & 2 deletions R/ggdotplotstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ ggdotplotstats <- function(data,
)

subtitle_df <- .eval_f(one_sample_test, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

if (type == "parametric" && bf.message) {
caption_df <- .eval_f(one_sample_test, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand Down
6 changes: 3 additions & 3 deletions R/gghistostats.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ gghistostats <- function(data,

# subtitle with statistical results
subtitle_df <- .eval_f(one_sample_test, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

# BF message
if (type == "parametric" && bf.message) {
caption_df <- .eval_f(one_sample_test, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand All @@ -131,7 +131,7 @@ gghistostats <- function(data,
scale_y_continuous(
sec.axis = sec_axis(
trans = ~ . / nrow(data),
labels = function(x) paste0(x * 100, "%"),
labels = function(x) insight::format_percent(x, digits = 0L),
name = "proportion"
)
) +
Expand Down
4 changes: 2 additions & 2 deletions R/ggpiestats.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ ggpiestats <- function(data,
)

subtitle_df <- .eval_f(contingency_table, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

# Bayes Factor caption
if (type != "bayes" && bf.message && isFALSE(paired)) {
caption_df <- .eval_f(contingency_table, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand Down
4 changes: 2 additions & 2 deletions R/ggscatterstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ ggscatterstats <- function(data,
)

subtitle_df <- .eval_f(corr_test, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)

# BF message for null hypothesis support
if (type == "parametric" && bf.message) {
caption_df <- .eval_f(corr_test, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
}
}

Expand Down
4 changes: 2 additions & 2 deletions R/ggwithinstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ ggwithinstats <- function(data,
# styler: off
.f <- .f_switch(test)
subtitle_df <- .eval_f(.f, !!!.f.args, type = type)
subtitle <- extract_expression(subtitle_df)
subtitle <- .extract_expression(subtitle_df)
# styler: on

if (type == "parametric" && bf.message) {
# styler: off
caption_df <- .eval_f(.f, !!!.f.args, type = "bayes")
caption <- extract_expression(caption_df)
caption <- .extract_expression(caption_df)
# styler: on
}
}
Expand Down
13 changes: 4 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
#' @examplesIf identical(Sys.getenv("NOT_CRAN"), "true")
#' ggstatsplot:::.grouped_list(ggplot2::msleep, grouping.var = vore)
#' @keywords internal
.grouped_list <- function(data, grouping.var = NULL) {
data <- as_tibble(data)

if (quo_is_null(enquo(grouping.var))) {
return(data)
}

split(data, f = new_formula(NULL, enquo(grouping.var)), drop = TRUE) %>%
.grouped_list <- function(data, grouping.var) {
as_tibble(data) %>%
split(f = new_formula(NULL, enquo(grouping.var)), drop = TRUE) %>%
list(data = ., title = names(.))
}

Expand Down Expand Up @@ -65,4 +60,4 @@


#' @noRd
extract_expression <- function(data) purrr::pluck(data, "expression", 1L, .default = NULL)
.extract_expression <- function(data) purrr::pluck(data, "expression", 1L, .default = NULL)
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
},
"SystemRequirements": null
},
"fileSize": "9389.014KB",
"fileSize": "9422.075KB",
"citation": [
{
"@type": "ScholarlyArticle",
Expand Down
2 changes: 1 addition & 1 deletion man/dot-grouped_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d662145

Please sign in to comment.