Skip to content

Commit

Permalink
test: fix erros and warnings related to as_flextable
Browse files Browse the repository at this point in the history
  • Loading branch information
atusy committed Sep 19, 2023
1 parent 12e7a33 commit df2fc0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 48 deletions.
2 changes: 1 addition & 1 deletion R/as-flextable.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ as_flextable.grouped_df <- function(
x %>%
dplyr::ungroup() %>%
flextable::as_grouped_data(g) %>%
as_flextable(...)
flextable::as_flextable(...)
)
}

Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ drop_na <- function(x) {
last <- function(x) {
x[[length(x)]]
}

.Deprecated <- function(...) {
if (!getOption("ftExtra.ignore.deprecation", FALSE)) base::.Deprecated(...)
}
54 changes: 9 additions & 45 deletions tests/testthat/test-as-flextable.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
x <- tibble::as_tibble(iris[c(1, 2, 51, 52), c(5, 1)])

test_that("flextable.data.frame", {
expect_identical(flextable(x), flextable::flextable(x))
expect_identical(
flextable(x, with_blanks("Species", "Sepal.Length")),
flextable::flextable(
x,
col_keys = c("Species", "..after1", "..before1", "Sepal.Length")
)
)
})


test_that("as.flextable.grouped_df", {
options(ftExtra.ignore.deprecation = TRUE)
d <- dplyr::group_by(x, .data$Species)
f <- flextable::as_grouped_data(x, "Species")

expect_identical(flextable(d), as_flextable(f))
expect_identical(as_flextable(d), as_flextable(f))

expect_identical(
flextable(d, groups_to = "merged"),
as_flextable(d, groups_to = "merged"),
x %>%
flextable::flextable() %>%
flextable::merge_v("Species") %>%
flextable::theme_vanilla()
)

expect_identical(
flextable(d, groups_to = "merged", col_keys = with_blanks("Species")),
x %>%
flextable::flextable(
col_keys = c("Species", "..after1", "Sepal.Length")
) %>%
flextable::merge_v("Species") %>%
flextable::theme_vanilla()
)

expect_identical(
flextable(d, groups_to = "asis"),
as_flextable(d, groups_to = "asis"),
flextable::flextable(x)
)
})
Expand All @@ -50,10 +29,10 @@ test_that("flextable.grouped_df multi groups", {
dplyr::group_by(am, cyl, mpg)
f <- flextable::as_grouped_data(x, groups = c("am", "cyl", "mpg"))

expect_identical(flextable(d), as_flextable(f))
expect_identical(as_flextable(d), as_flextable(f))

expect_identical(
flextable(d, groups_to = "merged"),
as_flextable(d, groups_to = "merged"),
x %>%
dplyr::relocate(am, cyl, mpg) %>%
flextable::flextable() %>%
Expand All @@ -62,7 +41,7 @@ test_that("flextable.grouped_df multi groups", {
)

expect_identical(
flextable(d, groups_to = "merged", groups_arrange = TRUE),
as_flextable(d, groups_to = "merged", groups_arrange = TRUE),
x %>%
dplyr::relocate(am, cyl, mpg) %>%
dplyr::arrange(am, cyl, mpg) %>%
Expand All @@ -72,30 +51,15 @@ test_that("flextable.grouped_df multi groups", {
)

expect_identical(
flextable(d, groups_to = "merged", groups_pos = "asis"),
as_flextable(d, groups_to = "merged", groups_pos = "asis"),
x %>%
flextable::flextable() %>%
flextable::merge_v(c("am", "cyl", "mpg")) %>%
flextable::theme_vanilla()
)

expect_identical(
flextable(
d,
groups_to = "merged",
col_keys = with_blanks(tidyselect::starts_with("m"))
),
x %>%
dplyr::relocate(am, cyl, mpg) %>%
flextable::flextable(
col_keys = c("am", "cyl", "mpg", "..after1", "model", "..after2", "disp")
) %>%
flextable::merge_v(c("am", "cyl", "mpg")) %>%
flextable::theme_vanilla()
)

expect_identical(
flextable(d, groups_to = "asis"),
as_flextable(d, groups_to = "asis"),
flextable::flextable(x)
)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-header-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ test_that("merge_header", {
expect_identical(merge_header(ft, FALSE), ft)
})

test_that("separate-header", {
test_that("split-header", {
expect_identical(
d %>% flextable() %>% separate_header(),
d %>% flextable() %>% split_header(),
ft %>% flextable::theme_booktabs() %>% flextable::fix_border_issues()
)
})
Expand Down

0 comments on commit df2fc0d

Please sign in to comment.