-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest-forestplot.group_df.R
More file actions
79 lines (71 loc) · 2.83 KB
/
test-forestplot.group_df.R
File metadata and controls
79 lines (71 loc) · 2.83 KB
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
library("testthat")
data("HRQoL")
test_that("Basic", {
out <- HRQoL |>
sapply(\(x) data.frame(x) |> tibble::rownames_to_column(),
simplify = FALSE) |>
dplyr::bind_rows(.id = "Country") |>
dplyr::group_by(Country) |>
forestplot(mean = coef,
lower = lower,
upper = upper,
labeltext = rowname,
fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI),
boxsize = .25, # We set the box size to better visualize the type
line.margin = .1, # We need to add this to avoid crowding
clip = c(-.125, 0.075),
col = fpColors(box = c("blue", "darkred")),
xticks = c(-.1, -0.05, 0, .05),
xlab = "EQ-5D index"
)
expect_equivalent(out$estimates[,1,],
lapply(HRQoL, \(x) x[,"coef"]) |> (\(args) do.call(cbind, args = args))())
})
test_that("Basic add header", {
out <- HRQoL |>
sapply(\(x) data.frame(x) |> tibble::rownames_to_column(),
simplify = FALSE) |>
dplyr::bind_rows(.id = "Country") |>
dplyr::group_by(Country) |>
forestplot(mean = coef,
lower = lower,
upper = upper,
labeltext = rowname,
fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI),
boxsize = .25, # We set the box size to better visualize the type
line.margin = .1, # We need to add this to avoid crowding
clip = c(-.125, 0.075),
col = fpColors(box = c("blue", "darkred")),
xticks = c(-.1, -0.05, 0, .05),
xlab = "EQ-5D index"
) |>
fp_add_header("A header")
expect_equivalent(out$labels[[1]][[1]],
"A header")
})
test_that("How to handle missing rows when group_by have different names", {
out <- HRQoL |>
sapply(\(x) data.frame(x) |> tibble::rownames_to_column(),
simplify = FALSE) |>
dplyr::bind_rows(.id = "Country") |>
dplyr::filter(Country == "Sweden" | rowname != "Males vs Female") |>
dplyr::group_by(Country) |>
forestplot(mean = coef,
lower = lower,
upper = upper,
labeltext = rowname,
legend = c("Sweden", "Denmark"),
fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI),
boxsize = .25, # We set the box size to better visualize the type
line.margin = .1, # We need to add this to avoid crowding
clip = c(-.125, 0.075),
col = fpColors(box = c("blue", "darkred")),
xticks = c(-.1, -0.05, 0, .05),
xlab = "EQ-5D index"
)
expect_equivalent(out$estimates[,1,1],
HRQoL[[1]][,"coef"])
expect_scalar_na(out$estimates[1,1,2])
expect_equivalent(out$estimates[2:4,1,2],
HRQoL[[2]][2:4,"coef"])
})