Skip to content

Commit

Permalink
Fix more lints (#884)
Browse files Browse the repository at this point in the history
* Avoid unnecessary conditionals

* Update ggbarstats.R

* change linter config

* Update ggpiestats_ggbarstats_helpers.R
  • Loading branch information
IndrajeetPatil authored Sep 22, 2023
1 parent f1b785a commit 8cd6875
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint-changed-files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
commented_code_linter = NULL,
cyclocomp_linter(25L),
extraction_operator_linter = NULL,
if_not_else_linter(exceptions = character(0L)),
implicit_integer_linter = NULL,
library_call_linter = NULL,
line_length_linter(120L),
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
commented_code_linter = NULL,
cyclocomp_linter(25L),
extraction_operator_linter = NULL,
if_not_else_linter(exceptions = character(0L)),
implicit_integer_linter = NULL,
library_call_linter = NULL,
line_length_linter(120L),
Expand Down
1 change: 1 addition & 0 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters: linters_with_defaults(
commented_code_linter = NULL,
cyclocomp_linter(25L),
extraction_operator_linter = NULL,
if_not_else_linter(exceptions = character(0L)),
implicit_integer_linter = NULL,
library_call_linter = NULL,
line_length_linter(120L),
Expand Down
4 changes: 2 additions & 2 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)
if (!is.null(subtitle_df)) subtitle <- subtitle_df$expression[[1L]]
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")
if (!is.null(caption_df)) caption <- caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
}
}

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 <- if (!is.null(subtitle_df)) subtitle_df$expression[[1L]]
subtitle <- extract_expression(subtitle_df)

if (type == "parametric" && bf.message) {
caption_df <- .eval_f(.f, !!!.f.args, type = "bayes")
caption <- if (!is.null(caption_df)) caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
}
}

Expand Down
6 changes: 2 additions & 4 deletions R/ggdotplotstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ ggdotplotstats <- function(data,
bf.prior = bf.prior
)

# subtitle with statistical results
subtitle_df <- .eval_f(one_sample_test, !!!.f.args, type = type)
subtitle <- if (!is.null(subtitle_df)) subtitle_df$expression[[1L]]
subtitle <- extract_expression(subtitle_df)

# BF message
if (type == "parametric" && bf.message) {
caption_df <- .eval_f(one_sample_test, !!!.f.args, type = "bayes")
caption <- if (!is.null(caption_df)) caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
}
}

Expand Down
4 changes: 2 additions & 2 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 <- if (!is.null(subtitle_df)) subtitle_df$expression[[1L]]
subtitle <- extract_expression(subtitle_df)

# BF message
if (type == "parametric" && bf.message) {
caption_df <- .eval_f(one_sample_test, !!!.f.args, type = "bayes")
caption <- if (!is.null(caption_df)) caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
}
}

Expand Down
6 changes: 3 additions & 3 deletions R/ggpiestats.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ggpiestats <- function(data,
x_levels <- nlevels(data %>% pull({{ x }}))
y_levels <- ifelse(test == "one.way", 0L, nlevels(data %>% pull({{ y }})))

# TODO: one-way table in `BayesFactor`
# TODO: one-way table in `BayesFactor` (richarddmorey/BayesFactor#159)
if (test == "two.way" && y_levels == 1L) bf.message <- FALSE

# faceting is possible only if both vars have more than one level
Expand All @@ -138,12 +138,12 @@ ggpiestats <- function(data,
)

subtitle_df <- .eval_f(contingency_table, !!!.f.args, type = type)
if (!is.null(subtitle_df)) subtitle <- subtitle_df$expression[[1L]]
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")
if (!is.null(caption_df)) caption <- caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
}
}

Expand Down
6 changes: 3 additions & 3 deletions R/ggpiestats_ggbarstats_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ onesample_data <- function(data, x, y, k = 2L, ...) {
error = function(e) NULL
)

if (!is.null(result)) {
as_tibble(insight::standardize_names(result, style = "broom"))
} else {
if (is.null(result)) {
tibble(
statistic = NA_real_, p.value = NA_real_, df = NA_real_,
method = "Chi-squared test for given probabilities"
)
} else {
as_tibble(insight::standardize_names(result, style = "broom"))
}
}

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 <- if (!is.null(subtitle_df)) subtitle_df$expression[[1L]]
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 <- if (!is.null(caption_df)) caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
}
}

Expand Down
6 changes: 3 additions & 3 deletions R/ggwithinstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ ggwithinstats <- function(data,
# test to run; depends on the no. of levels of the independent variable
test <- ifelse(nlevels(data %>% pull({{ x }})) < 3L, "t", "anova")

if (results.subtitle && insight::check_if_installed("afex")) {
if (results.subtitle) {
.f.args <- list(
data = data,
x = as_string(x),
Expand All @@ -151,13 +151,13 @@ ggwithinstats <- function(data,
# styler: off
.f <- .f_switch(test)
subtitle_df <- .eval_f(.f, !!!.f.args, type = type)
subtitle <- if (!is.null(subtitle_df)) subtitle_df$expression[[1L]]
subtitle <- extract_expression(subtitle_df)
# styler: on

if (type == "parametric" && bf.message) {
# styler: off
caption_df <- .eval_f(.f, !!!.f.args, type = "bayes")
caption <- if (!is.null(caption_df)) caption_df$expression[[1L]]
caption <- extract_expression(caption_df)
# styler: on
}
}
Expand Down
3 changes: 3 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@
error = function(e) NULL
)
}

#' @noRd
extract_expression <- function(data) purrr::pluck(data, "expression", 1L, .default = NULL)
2 changes: 1 addition & 1 deletion data-raw/Titanic_full.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Titanic_full <-
tibble::rowid_to_column(var = "id") |>
dplyr::mutate(dplyr::across(dplyr::vars("id"), ~ as.factor(.x))) |>
split(f = .$id) |>
purrr::map_dfr(.f = ~ tidyr::uncount(.x, n)) |>
purrr::map_dfr(tidyr::uncount, n) |>
dplyr::mutate(dplyr::across(dplyr::vars("id"), ~ as.numeric(as.character(.x)))) |>
dplyr::mutate(dplyr::across(where(is.character), ~ droplevels(as.factor(.x)))) |>
dplyr::select(-n, -id) |>
Expand Down

0 comments on commit 8cd6875

Please sign in to comment.