LukasWallrich / timesaveR

R package to quickly perform data analysis and reporting tasks that might otherwise be time intensive
https://lukaswallrich.github.io/timesaveR
GNU General Public License v3.0
5 stars 1 forks source link

pairwise_t_tests - better error with only 1 grou[p #9

Closed LukasWallrich closed 1 month ago

LukasWallrich commented 5 months ago

This is not clear

library(tidyverse)
library(timesaveR)
#> Note re timesaveR: Many functions in this package are alpha-versions - please treat results with care and report bugs and desired features.

df <- mtcars %>% filter(cyl == 6)

pairwise_t_tests(df, mpg ~ cyl)
#> Error in utils::combn(., 2): n < m

Created on 2024-05-17 with reprex v2.0.2

LukasWallrich commented 4 months ago

Relatedly, NA values in cond lead to unclear errors - na.rm should be offered, and clear failure produced if FALSE.

> iris$Species[30] <- NA
> iris %>%  timesaveR::pairwise_t_tests(Sepal.Length, Species)
Error in `map()`:
ℹ In index: 1.
ℹ With name: 1.
Caused by error in `t.test.formula()`:
! grouping factor must have exactly 2 levels
Run `rlang::last_trace()` to see where the error occurred.
LukasWallrich commented 4 months ago

dbl+lbl data also leads to unclear error - convert to factor or clearer error:

Error in `map()`:
ℹ In index: 1.
ℹ With name: 1.
Caused by error in `dplyr::arrange()`:
ℹ In argument: `..1 = cond == x[1]`.
Caused by error in `vec_equal()`:
! Can't combine `..1` <character> and `..2` <double>.
Run `rlang::last_trace()` to see where the error occurred.