Skip to content

Commit 6947246

Browse files
authored
Hot fix for page number bug (#290)
Closes #288
1 parent 06f8a1f commit 6947246

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

R/pagination.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ paginate_to_mpfs <- function(obj,
10921092
return(mpfs)
10931093
}
10941094

1095-
if (!is.null(page_num) && (length(prov_footer(obj)) == 0 || !grepl(page_num, prov_footer(obj), perl = TRUE))) {
1095+
if (!is.null(page_num) && (length(prov_footer(obj)) == 0 || !any(grepl(page_num, prov_footer(obj), fixed = TRUE)))) {
10961096
# Only adding a line for pagination -> lpp - 1 would have worked too
10971097
prov_footer(obj) <- c(prov_footer(obj), page_num)
10981098
}

tests/testthat/test-exporters.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ test_that("export_as_txt maintains horizontal separator from table", {
151151
expect_equal(out, paste0(rep("=", nchar(out)), collapse = ""))
152152
})
153153

154+
test_that("export_as_txt works with prov footer and page numbers", {
155+
dfmf <- basic_matrix_form(mtcars)
156+
prov_footer(dfmf) <- c("my", "prov", "footer")
157+
158+
set_default_page_number("page {i} of {n}")
159+
expect_silent(res <- export_as_txt(dfmf, paginate = TRUE, cpp = 60))
160+
set_default_page_number(NULL)
161+
162+
expect_true(grepl("page 1 of 2", res))
163+
expect_true(grepl("page 2 of 2", res))
164+
})
165+
154166
test_that("export_as_pdf works", {
155167
# Enhancing coverage -> modified copy from rtables
156168
bmf <- basic_matrix_form(mtcars)

0 commit comments

Comments
 (0)