Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved relevant decoration expansion into formatters for rlistings fix #813

Closed
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
### New Features
* Added `top_level_section_div` for `basic_table` to set section dividers for top level rows.

### Bug Fixes
* Fixed `rlistings` decoration (e.g. titles and footers) expansion when there are new lines. Moved relevant handling from `rtables`' `matrix_form` function to `formatters`' dedicated `mform_handle_newlines` function.

## rtables 0.6.6
### New Features
* Removed `ref_group` reordering in column splits so not to change the order.
Expand Down
32 changes: 2 additions & 30 deletions R/tt_toString.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,12 @@ setMethod(
if (disp_ccounts(obj)) {
hdr_fmt_blank[nrow(hdr_fmt_blank), ] <- c("", rep(colcount_format(obj), ncol(obj)))
}
## if(disp_ccounts(obj)) {
## formats <- rbind(matrix("", nrow = nrow(header_content$body) - 1L,
## ncol = ncol(header_content$body)),

## formats_strings)
## } else {
## formats <- rbind(header_content$body, formats_strings)
## }

formats <- rbind(hdr_fmt_blank, formats_strings)

spans <- rbind(header_content$span, body_spans)
row.names(spans) <- NULL

## unused??? space <- matrix(rep(0, length(body)), nrow = nrow(body))
aligns <- rbind(
matrix(rep("center", length(header_content$body)),
nrow = nrow(header_content$body)
Expand All @@ -262,10 +254,6 @@ setMethod(

aligns[, 1] <- "left" # row names and topleft (still needed for topleft)

## if (any(apply(body, c(1, 2), function(x) grepl("\n", x, fixed = TRUE))))
## stop("no \\n allowed at the moment")


nr_header <- nrow(header_content$body)
if (indent_rownames) {
body[, 1] <- indent_string(body[, 1], c(rep(0, nr_header), sr$indent),
Expand Down Expand Up @@ -296,23 +284,7 @@ setMethod(
nrow = nrow(body),
ncol = ncol(body)
)
# Solve \n in titles
if (any(grepl("\n", all_titles(obj)))) {
if (any(grepl("\n", main_title(obj)))) {
tmp_title_vec <- .quick_handle_nl(main_title(obj))
main_title(obj) <- tmp_title_vec[1]
subtitles(obj) <- c(tmp_title_vec[-1], .quick_handle_nl(subtitles(obj)))
} else {
subtitles(obj) <- .quick_handle_nl(subtitles(obj))
}
}

# Solve \n in footers
main_footer(obj) <- .quick_handle_nl(main_footer(obj))
prov_footer(obj) <- .quick_handle_nl(prov_footer(obj))

# xxx \n in page titles are not working atm (I think)
# ref_fnotes <- strsplit(get_formatted_fnotes(obj), "\n", fixed = TRUE)

ref_fnotes <- get_formatted_fnotes(obj) # pagination will not count extra lines coming from here
pag_titles <- page_titles(obj)

Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/setup-fakedata.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ tt_for_wrap <- tt_to_test_wrapping()
tt_to_test_newline_chars <- function() {
set.seed(1)
DM_trick <- DM %>%
mutate(ARM = "ARM \n\nA\n") %>%
mutate(ARM2 = sample(c("TWO\nwords\n ", "A wo\n\nrd\n\n"),
replace = TRUE, nrow(DM)
)) # last \n is eaten up if no empty space
Expand All @@ -198,12 +199,13 @@ tt_to_test_newline_chars <- function() {
split_label = "m\nannaggia\nsda\n",
label_pos = "visible"
) %>%
split_cols_by("ARM") %>%
split_cols_by("ARM2", split_label = "sda") %>%
analyze("BMRKR1", na_str = "asd\nasd") %>%
build_table(DM_trick)

main_footer(tbl) <- c("This", "is\na\n\nweird one\n")
prov_footer(tbl) <- c("This", "is\na\n\nweird one\n")
main_footer(tbl) <- c("main_footer: This", "is\na\n\nweird one\n")
prov_footer(tbl) <- c("prov_footer: This", "is\na\n\nweird one\n")
fnotes_at_path(tbl, rowpath = row_paths(tbl)[[6]]) <- c("a fancy footnote\ncrazy\n", "ahahha")
top_left(tbl) <- c("\na", "b\nd\n\n", "c\n\n") # last \n is eaten up if empty line everywhere
main_title(tbl) <- "why not\nalso here\n"
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ test_that("Support for newline characters in all the parts", {
"",
"---------------------------------",
" ",
" ARM ",
" ",
" ",
"a ",
"a A ",
"b A wo",
"d TWO ",
"c words rd ",
Expand Down Expand Up @@ -660,13 +660,13 @@ test_that("Support for newline characters in all the parts", {
"{2} - ahahha",
"---------------------------------",
"",
"This",
"main_footer: This",
"is",
"a",
"",
"weird one",
"",
"This",
"prov_footer: This",
"is",
"a",
"",
Expand Down
Loading