From 71cc1148c9d31afaa3fe91b4c189c243aa81ab97 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 21 Nov 2023 23:40:50 +0100 Subject: [PATCH] fix regression and remaining lints --- R/helpers_easystats.R | 12 +++++------- R/one_sample_test.R | 2 +- R/tidy_model_expressions.R | 16 ++++++++-------- man/tidy_model_expressions.Rd | 8 ++++---- tests/testthat/test-contingency_table.R | 4 ++-- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/R/helpers_easystats.R b/R/helpers_easystats.R index 37e7a6db..b127dd5b 100644 --- a/R/helpers_easystats.R +++ b/R/helpers_easystats.R @@ -55,11 +55,9 @@ tidy_model_parameters <- function(model, ...) { #' tidy_model_effectsize(df) #' @noRd tidy_model_effectsize <- function(data, ...) { - bind_cols( - data %>% - mutate(effectsize = stats::na.omit(effectsize::get_effectsize_label(colnames(.)))) %>% - standardize_names(style = "broom") %>% - select(-contains("term")), - rename_with(as_tibble(data %@% "ci_method"), ~ paste0("conf.", .x)) - ) + data %>% + mutate(effectsize = stats::na.omit(effectsize::get_effectsize_label(colnames(.)))) %>% + standardize_names(style = "broom") %>% + select(-contains("term")) %>% + bind_cols(rename_with(as_tibble(data %@% "ci_method"), ~ paste0("conf.", .x))) } diff --git a/R/one_sample_test.R b/R/one_sample_test.R index f1c4de81..023a270b 100644 --- a/R/one_sample_test.R +++ b/R/one_sample_test.R @@ -45,7 +45,7 @@ one_sample_test <- function(data, effsize.type = "g", ...) { type <- stats_type_switch(type) - x_vec <- stats::na.omit(data %>% pull({{ x }})) + x_vec <- stats::na.omit(pull(data, {{ x }})) # parametric --------------------------------------- diff --git a/R/tidy_model_expressions.R b/R/tidy_model_expressions.R index e3e55404..a294fb9e 100644 --- a/R/tidy_model_expressions.R +++ b/R/tidy_model_expressions.R @@ -26,12 +26,12 @@ #' library(statsExpressions) #' #' # extract a tidy data frame -#' df_expr <- tidy_model_parameters(lm(wt ~ am * cyl, mtcars)) +#' df <- tidy_model_parameters(lm(wt ~ am * cyl, mtcars)) #' #' # create a column containing expression; the expression will depend on `statistic` -#' tidy_model_expressions(df_expr, statistic = "t") -#' tidy_model_expressions(df_expr, statistic = "z") -#' tidy_model_expressions(df_expr, statistic = "chi") +#' tidy_model_expressions(df, statistic = "t") +#' tidy_model_expressions(df, statistic = "z") +#' tidy_model_expressions(df, statistic = "chi") #' @export tidy_model_expressions <- function(data, statistic = NULL, @@ -61,8 +61,8 @@ tidy_model_expressions <- function(data, if (statistic == "t") { df_expr %<>% mutate( expression = case_when( - df_expr.error %in% c("NA", "Inf") ~ glue("list({es.text}=='{estimate}', italic(t)=='{statistic}', italic(p)=='{p.value}')"), - .default = glue("list({es.text}=='{estimate}', italic(t)('{df_expr.error}')=='{statistic}', italic(p)=='{p.value}')") + df.error %in% c("NA", "Inf") ~ glue("list({es.text}=='{estimate}', italic(t)=='{statistic}', italic(p)=='{p.value}')"), + .default = glue("list({es.text}=='{estimate}', italic(t)('{df.error}')=='{statistic}', italic(p)=='{p.value}')") ) ) } @@ -76,7 +76,7 @@ tidy_model_expressions <- function(data, # chi^2-statistic ----------------------------- if (statistic == "c") { - df_expr %<>% mutate(expression = glue("list({es.text}=='{estimate}', italic(chi)^2*('{df_expr.error}')=='{statistic}', italic(p)=='{p.value}')")) + df_expr %<>% mutate(expression = glue("list({es.text}=='{estimate}', italic(chi)^2*('{df.error}')=='{statistic}', italic(p)=='{p.value}')")) } # f-statistic --------------------------------- @@ -85,7 +85,7 @@ tidy_model_expressions <- function(data, if (effsize.type == "eta") es.text <- list(quote(widehat(italic(eta)[p]^2))) if (effsize.type == "omega") es.text <- list(quote(widehat(italic(omega)[p]^2))) - df_expr %<>% mutate(expression = glue("list({es.text}=='{estimate}', italic(F)('{df_expr}', '{df_expr.error}')=='{statistic}', italic(p)=='{p.value}')")) + df_expr %<>% mutate(expression = glue("list({es.text}=='{estimate}', italic(F)('{df}', '{df.error}')=='{statistic}', italic(p)=='{p.value}')")) } # nolint end diff --git a/man/tidy_model_expressions.Rd b/man/tidy_model_expressions.Rd index a342fba9..a924ba90 100644 --- a/man/tidy_model_expressions.Rd +++ b/man/tidy_model_expressions.Rd @@ -47,11 +47,11 @@ set.seed(123) library(statsExpressions) # extract a tidy data frame -df_expr <- tidy_model_parameters(lm(wt ~ am * cyl, mtcars)) +df <- tidy_model_parameters(lm(wt ~ am * cyl, mtcars)) # create a column containing expression; the expression will depend on `statistic` -tidy_model_expressions(df_expr, statistic = "t") -tidy_model_expressions(df_expr, statistic = "z") -tidy_model_expressions(df_expr, statistic = "chi") +tidy_model_expressions(df, statistic = "t") +tidy_model_expressions(df, statistic = "z") +tidy_model_expressions(df, statistic = "chi") \dontshow{\}) # examplesIf} } diff --git a/tests/testthat/test-contingency_table.R b/tests/testthat/test-contingency_table.R index 404f98f0..350fef59 100644 --- a/tests/testthat/test-contingency_table.R +++ b/tests/testthat/test-contingency_table.R @@ -16,7 +16,7 @@ test_that( expect_snapshot(select(df1, -expression)) expect_snapshot(df1[["expression"]]) - + set.seed(123) df2 <- contingency_table( data = as.data.frame(Titanic), @@ -121,7 +121,7 @@ test_that( expect_snapshot(select(df1, -expression)) expect_snapshot(df1[["expression"]]) - + set.seed(123) df2 <- contingency_table( data = as.data.frame(Titanic),