-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started adding unit tests for stat_fmt_tb
- Loading branch information
1 parent
b22df0d
commit c6d8e3c
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
context("stat_fmt_tb") | ||
|
||
test_that("stat_fmt_tb", { | ||
#data frame to test with | ||
|
||
#results of using function | ||
|
||
#expected result via another method | ||
|
||
#expect_equal(result, expected) | ||
|
||
#other expect methods | ||
|
||
#code from github | ||
my.df <- | ||
tibble::tibble( | ||
x = c(1, 2), | ||
y = c(0, 4), | ||
group = c("A", "B"), | ||
tbs = list(a = tibble::tibble(Xa = 1:6, Y = rep(c("x", "y"), 3)), | ||
b = tibble::tibble(Xb = 1:3, Y = "x")) | ||
) | ||
|
||
result <- ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb() + | ||
expand_limits(x = c(0,3), y = c(-2, 6)) | ||
expect_s3_class(result, "ggplot") | ||
|
||
result <- ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb() + | ||
expand_limits(x = c(0,3), y = c(-2, 6)) | ||
result <- ggplot2::layer_data(result,2) | ||
result <- result[ ,c("x","y")] | ||
expected <- data.frame(x = c(0,3), y = c(-2,6)) | ||
expect_identical(result, expected) | ||
|
||
# Hide column names, diplay row names | ||
result2 <- ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb(table.colnames = FALSE, | ||
table.rownames = TRUE) | ||
ggplot2::layer_data(result2, 1) %>% colnames() | ||
ggplot2::layer_data(result2, 1) %>% rownames() | ||
|
||
# Use a theme for the table | ||
ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb(table.theme = ttheme_gtlight) + | ||
expand_limits(x = c(0,3), y = c(-2, 6)) | ||
|
||
# selection and renaming by column position | ||
ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb(tb.vars = c(value = 1, group = 2), | ||
tb.rows = 1:3) + | ||
expand_limits(x = c(0,3), y = c(-2, 6)) | ||
|
||
# selection, reordering and renaming by column position | ||
ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb(tb.vars = c(group = 2, value = 1), | ||
tb.rows = 1:3) + | ||
expand_limits(x = c(0,3), y = c(-2, 6)) | ||
|
||
# selection and renaming, using partial matching to column name | ||
ggplot(my.df, aes(x, y, label = tbs)) + | ||
stat_fmt_tb(tb.vars = c(value = "X", group = "Y"), | ||
tb.rows = 1:3) + | ||
expand_limits(x = c(0,3), y = c(-2, 6)) | ||
}) |