This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
/
test-generics.R
89 lines (73 loc) 路 2.38 KB
/
test-generics.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
context("generics work")
# `tidy()` works ------------------------------------------------------
testthat::test_that(
desc = "`tidy()` works",
code = {
library(lme4)
set.seed(123)
# broom.mixed
lmm.mod <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
testthat::expect_equal(
broomExtra::tidy(lmm.mod), broom.mixed::tidy(lmm.mod)
)
# broom
lm.mod <- lm(Reaction ~ Days, sleepstudy)
testthat::expect_equal(broomExtra::tidy(lm.mod), broom::tidy(lm.mod))
# unsupported
x <- c(2, 2:4, 4, 4, 5, 5, 7, 7, 7)
y <- c(1:6, 5:4, 3:1)
suppressWarnings(appr <- stats::approx(x, y, xout = x))
suppressWarnings(testthat::expect_is(broomExtra::tidy(appr), "tbl_df"))
# dataframes
suppressWarnings(
testthat::expect_is(
broomExtra::tidy(dplyr::group_by(iris, Species)),
"tbl_df"
)
)
# testthat::expect_equal(dim(broomExtra::tidy(mtcars)), c(32L, 12L))
# testthat::expect_identical(names(broomExtra::tidy(mtcars))[1], "rownames")
testthat::expect_null(broomExtra::tidy(list(1, c("x", "y"))), NULL)
}
)
# `glance()` works ------------------------------------------------------
testthat::test_that(
desc = "`glance()` works",
code = {
library(lme4)
set.seed(123)
# broom.mixed
lmm.mod <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
testthat::expect_equal(
broomExtra::glance(lmm.mod), broom.mixed::glance(lmm.mod)
)
# broom
lm.mod <- lm(Reaction ~ Days, sleepstudy)
testthat::expect_equal(broomExtra::glance(lm.mod), broom::glance(lm.mod))
# unsupported
x <- c(2, 2:4, 4, 4, 5, 5, 7, 7, 7)
y <- c(1:6, 5:4, 3:1)
suppressWarnings(appr <- stats::approx(x, y, xout = x))
testthat::expect_null(broomExtra::glance(appr))
}
)
# `augment()` works ------------------------------------------------------
testthat::test_that(
desc = "`augment()` works",
code = {
library(lme4)
set.seed(123)
# broom.mixed
lmm.mod <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
testthat::expect_equal(
broomExtra::augment(lmm.mod), broom.mixed::augment(lmm.mod)
)
# broom
lm.mod <- lm(Reaction ~ Days, sleepstudy)
testthat::expect_equal(broomExtra::augment(lm.mod), broom::augment(lm.mod))
# unsupported
testthat::expect_null(
broomExtra::augment(stats::anova(stats::lm(wt ~ am, mtcars)))
)
}
)