diff --git a/R/pairwise_comparisons.R b/R/pairwise_comparisons.R index bf6deb02..553e3ae7 100644 --- a/R/pairwise_comparisons.R +++ b/R/pairwise_comparisons.R @@ -187,7 +187,7 @@ pairwise_comparisons <- function(data, } if (type != "robust") { - df <- suppressWarnings(exec( + df_pair <- suppressWarnings(exec( .f, # Dunn, Games-Howell, Student's t-test x = y_vec, @@ -216,7 +216,7 @@ pairwise_comparisons <- function(data, .f.args <- list(y = quote(y_vec), groups = quote(x_vec), blocks = quote(g_vec)) } - df <- eval(call2(.ns = .ns, .fn = .fn, tr = tr, !!!.f.args)) %>% tidy_model_parameters() + df_pair <- eval(call2(.ns = .ns, .fn = .fn, tr = tr, !!!.f.args)) %>% tidy_model_parameters() test <- "Yuen's trimmed means" } @@ -227,8 +227,8 @@ pairwise_comparisons <- function(data, df_tidy <- map_dfr( # creating a list of data frames with subsections of data .x = map2( - .x = as.character(df$group1), - .y = as.character(df$group2), + .x = as.character(df_pair$group1), + .y = as.character(df_pair$group2), .f = function(a, b) droplevels(filter(data, {{ x }} %in% c(a, b))) ), .f = ~ two_sample_test( @@ -244,18 +244,18 @@ pairwise_comparisons <- function(data, mutate(expression = glue("list(log[e]*(BF['01'])=='{format_value(-log(bf10), k)}')")) %>% mutate(test = "Student's t") - df <- bind_cols(select(df, group1, group2), df_tidy) + df_pair <- bind_cols(select(df_pair, group1, group2), df_tidy) } # expression formatting ---------------------------------- - df %<>% + df_pair %<>% mutate(across(where(is.factor), ~ as.character())) %>% arrange(group1, group2) %>% select(group1, group2, everything()) if (type != "bayes") { - df %<>% + df_pair %<>% mutate( p.value = stats::p.adjust(p = p.value, method = p.adjust.method), p.adjust.method = p_adjust_text(p.adjust.method), @@ -269,7 +269,7 @@ pairwise_comparisons <- function(data, ) } - select(df, everything(), -matches("p.adjustment|^method$")) %>% + select(df_pair, everything(), -matches("p.adjustment|^method$")) %>% .glue_to_expression() } diff --git a/tests/testthat/test-long_to_wide_converter.R b/tests/testthat/test-long_to_wide_converter.R index 85747cc0..0c8afe2e 100644 --- a/tests/testthat/test-long_to_wide_converter.R +++ b/tests/testthat/test-long_to_wide_converter.R @@ -107,7 +107,7 @@ test_that( test_that( desc = "with .rowid - without NA", code = { - df <- structure( + df_original <- structure( list( score = c(90, 90, 72.5, 45), condition = structure(c(1L, 2L, 2L, 1L), .Label = c("4", "5"), class = "factor"), @@ -117,18 +117,16 @@ test_that( class = c("tbl_df", "tbl", "data.frame") ) - df1 <- arrange(df, id) + df_arranged <- arrange(df_original, id) expect_identical( - long_to_wide_converter(df1, condition, score), - long_to_wide_converter(df, condition, score, id) + long_to_wide_converter(df_arranged, condition, score), + long_to_wide_converter(df_original, condition, score, id) ) expect_identical( - long_to_wide_converter(df1, condition, score, spread = FALSE) %>% - arrange(.rowid), - long_to_wide_converter(df, condition, score, id, spread = FALSE) %>% - arrange(.rowid) + arrange(long_to_wide_converter(df_arranged, condition, score, spread = FALSE), .rowid), + arrange(long_to_wide_converter(df_original, condition, score, id, spread = FALSE), .rowid) ) } ) @@ -139,21 +137,17 @@ test_that( test_that( desc = "with .rowid - with NA", code = { - df <- bugs_long - df1 <- arrange(bugs_long, subject) + df_original <- bugs_long + df_arranged <- arrange(bugs_long, subject) expect_identical( - long_to_wide_converter(df1, condition, desire) %>% - select(-.rowid), - long_to_wide_converter(df, condition, desire, subject) %>% - select(-.rowid) + select(long_to_wide_converter(df_arranged, condition, desire), -.rowid), + select(long_to_wide_converter(df_original, condition, desire, subject), -.rowid) ) expect_identical( - long_to_wide_converter(df1, condition, desire, spread = FALSE) %>% - select(-.rowid), - long_to_wide_converter(df, condition, desire, subject, spread = FALSE) %>% - select(-.rowid) + select(long_to_wide_converter(df_arranged, condition, desire, spread = FALSE), -.rowid), + select(long_to_wide_converter(df_original, condition, desire, subject, spread = FALSE), -.rowid) ) } )