Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 3, 2024
1 parent ce578d5 commit 2bd8cd0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/testthat/test-data_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,20 @@ test_that("data_summary, inside functions", {
expect_equal(out1$MW, out2$MW, tolerance = 1e-4)
expect_equal(out1$MW, out3$MW, tolerance = 1e-4)
})


test_that("data_summary, expression as variable", {
data(mtcars)
a <- "MW = mean(mpg)"
b <- "SD = sd(mpg)"
out <- data_summary(mtcars, a, by = c("am", "gear"))
expect_named(out, c("am", "gear", "MW"))
expect_equal(out$MW, aggregate(mtcars["mpg"], list(mtcars$am, mtcars$gear), mean)$mpg, tolerance = 1e-4)
expect_error(
data_summary(mtcars, a, b, by = c("am", "gear")),
regex = "You cannot mix"
)
out <- data_summary(mtcars, c(a, b), by = c("am", "gear"))
expect_named(out, c("am", "gear", "MW", "SD"))
expect_equal(out$SD, aggregate(mtcars["mpg"], list(mtcars$am, mtcars$gear), sd)$mpg, tolerance = 1e-4)
})

0 comments on commit 2bd8cd0

Please sign in to comment.