Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions R/table_rows.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,13 @@ paginate_rows <- function(data, cell_h_mat, resolved_cols, group_vars,
identical(data[[gv]][last_in_page], data[[gv]][i])
}, logical(1L)))
if (same_group) {
rlang::warn(sprintf(
paste0("Row %d belongs to a group that spans more than one page. ",
"A '(continued)' marker will be added at the boundary."), i
))
rlang::warn(
sprintf(
paste0("Row %d belongs to a group that spans more than one page. ",
"A '(continued)' marker will be added at the boundary."), i
),
class = "writetfl_warning_group_spans_pages"
)
}
}

Expand Down
3 changes: 3 additions & 0 deletions design/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ paginate_rows(data, cell_h_mat, resolved_cols, group_vars,
overflow is detected, the previously committed (cur_rows, committed_rh)
pair is flushed — committed_rh captures the orphan-correct heights for
the row that landed alone at the page boundary.
A group split across the boundary signals an rlang warning of class
`writetfl_warning_group_spans_pages` (the page already carries the
continuation marker); callers that expect it match the class, not the text.
```

---
Expand Down
18 changes: 18 additions & 0 deletions design/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2318,3 +2318,21 @@ captions and `Page i of n`, specification overrides and layout arguments,
opened, per-file return value, path rules, failure policy, `workers` argument
checks, and parallel equivalence, cluster ownership and failure collection when
the installed package is under test).

---

## D-55: The page-break warning for a split group has a class

**Decision:** `paginate_rows()` signals the warning that a group spans more than
one page (the "belongs to a group that spans more than one page" message) with
the condition class `writetfl_warning_group_spans_pages`, alongside the
existing `writetfl_error_*` classes. The message text is unchanged.

**Motivation:** The page already carries a "(continued)" marker, so a caller that
writes grouped listings (a listing with a subject per group routinely runs a
subject over a page break) treats the warning as routine and silences it. With no
class, the only handle is the message text, so any rewording silently stops the
silencing and nothing fails. A class is a stable handle.

**Tests:** `tests/testthat/test-tfl_table.R` (the warning has the class, and an
export that splits a group signals only that class).
51 changes: 51 additions & 0 deletions tests/testthat/test-tfl_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,57 @@ test_that("paginate_rows warns when a group spans multiple pages", {
expect_true(any(grepl("continued", warns)))
})

test_that("the split-group warning has the writetfl_warning_group_spans_pages class", {
data <- data.frame(grp = rep("A", 5), val = 1:5, stringsAsFactors = FALSE)
gdf <- dplyr::group_by(data, grp)
cell_h_mat <- matrix(1, nrow = 5, ncol = 2L)
resolved_cols <- list(
list(col = "grp", is_group_col = TRUE),
list(col = "val", is_group_col = FALSE)
)
seen <- new.env(parent = emptyenv())
seen$classes <- list()
withCallingHandlers(
paginate_rows(gdf, cell_h_mat, resolved_cols,
group_vars = "grp",
cont_row_h = 0.2, header_row_h = 0.5,
content_height_in = 3,
row_cont_msg = "(continued)", group_rule = FALSE),
warning = function(w) {
seen$classes[[length(seen$classes) + 1L]] <- class(w)
invokeRestart("muffleWarning")
}
)
expect_gt(length(seen$classes), 0L)
for (cls in seen$classes) {
expect_true("writetfl_warning_group_spans_pages" %in% cls)
}
})

test_that("export_tfl of a grouped table that splits a group signals only the classed warning", {
f <- tempfile(fileext = ".pdf")
on.exit(unlink(f))
df <- data.frame(grp = rep(c("A", "B"), each = 30), val = 1:60, stringsAsFactors = FALSE)
tbl <- tfl_table(dplyr::group_by(df, grp))
seen <- new.env(parent = emptyenv())
seen$split <- 0L
seen$other <- 0L
withCallingHandlers(
export_tfl(tbl, file = f, pg_height = 5),
warning = function(w) {
if (inherits(w, "writetfl_warning_group_spans_pages")) {
seen$split <- seen$split + 1L
} else {
seen$other <- seen$other + 1L
}
invokeRestart("muffleWarning")
}
)
expect_gt(seen$split, 0L)
expect_equal(seen$other, 0L)
expect_true(file.exists(f))
})

# ---------------------------------------------------------------------------
# compute_table_content_area() — internal
# ---------------------------------------------------------------------------
Expand Down
Loading