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

Adapting to formatters changes to allow whitespaces #741

Merged
merged 7 commits into from
Oct 11, 2023
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## rtables 0.6.4.9000
### New Features
* Added support for white spaces in all labels and text by redesigning of wrapping functions in `formatters`.

## rtables 0.6.4
### New Features
Expand Down
14 changes: 8 additions & 6 deletions R/tt_paginate.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 1. user defined number of lines per page
## 2. all lines have the same height
## 3. header always reprinted on all pages
## 4. "Label-rows", i.e. content rows above break in the nesting structure, optionaly reprinted (default TRUE)
## 4. "Label-rows", i.e. content rows above break in the nesting structure, optionally reprinted (default TRUE)
## 5. Never (?) break on a "label"/content row
## 6. Never (?) break on the second (i.e. after the first) data row at a particular leaf Elementary table.
##
Expand Down Expand Up @@ -150,6 +150,8 @@ pos_to_path <- function(pos) {



# make_row_df ---------------------------------------------------------------
#
#' @inherit formatters::make_row_df
#'
# #' @note the technically present root tree node is excluded from the summary
Expand Down Expand Up @@ -478,6 +480,7 @@ setMethod("inner_col_df", "LayoutColTree",
flines
}

# Pagination ---------------------------------------------------------------

#' Pagination of a `TableTree`
#'
Expand Down Expand Up @@ -532,10 +535,8 @@ setMethod("inner_col_df", "LayoutColTree",
#' @param nosplitin character. List of names of sub-tables where page-breaks are not allowed, regardless of other
#' considerations. Defaults to none.
#'
#' @export
#' @return for \code{pag_tt_indices} a list of paginated-groups of row-indices of \code{tt}. For \code{paginate_table},
#' The subtables defined by subsetting by the indices defined by \code{pag_tt_indices}.
#' @rdname paginate
#'
#' @examples
#'
Expand Down Expand Up @@ -582,7 +583,8 @@ setMethod("inner_col_df", "LayoutColTree",
#' cat("\n\n")
#' })
#'
#'
#' @rdname paginate
#' @export
pag_tt_indices <- function(tt, lpp = 15,
min_siblings = 2,
nosplitin = character(),
Expand Down Expand Up @@ -685,16 +687,16 @@ setMethod("do_forced_paginate", "VTableTree",

non_null_na <- function(x) !is.null(x) && is.na(x)

#' @export
#' @aliases paginate_table
#' @param cpp numeric(1) or NULL. Width (in characters) of the pages for
#' horizontal pagination. `NA` (the default) indicates `cpp` should be inferred from
#' the page size; `NULL` indicates no horizontal pagination should be done
#' regardless of page size.
#' @rdname paginate
#' @inheritParams formatters::vert_pag_indices
#' @inheritParams formatters::page_lcpp
#' @inheritParams formatters::toString
#' @rdname paginate
#' @export
paginate_table <- function(tt,
page_type = "letter",
font_family = "Courier",
Expand Down
1 change: 0 additions & 1 deletion man/paginate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/tostring.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,10 @@ test_that("Cell and column label wrapping works in printing", {
expected <- c(" Incredib",
" ly long ",
" column ",
" name to ",
" be ")
expect_identical(splitted_res[1:5], expected)
" name ",
" to be ",
" wrapped ")
expect_identical(splitted_res[1:6], expected)

# String replacement of NAs wider than expected works with cell wrapping
expected <- c("Mean A very ",
Expand Down Expand Up @@ -487,9 +488,11 @@ test_that("row label indentation is kept even if there are newline characters",

# Matrix form and toString
mf_a <- matrix_form(tbl_a, TRUE, FALSE)
expect_error(res_a <- toString(mf_a, widths = c(15, 12, 12)),
regexp = "Inserted width\\(s\\) for column\\(s\\) 1 is\\(are\\) not wide enough for the desired indentation.")
res_a <- toString(mf_a, widths = c(16, 12, 12))
expect_error(
res_a <- toString(mf_a, widths = c(15, 12, 12)),
regexp = "Inserted width for row label column is not wide enough"
)
expect_silent(res_a <- toString(mf_a, widths = c(17, 12, 12)))
# 2 is the indentation of summarize_row_groups
# 1 is the standard indentation
# 1 + 1 + 4 is the standard nesting indentation (twice) + 4 manual indentation (indentation_mod)
Expand Down Expand Up @@ -532,14 +535,11 @@ test_that("row label indentation is kept even if there are newline characters",
main_title(tbl_b) <- "Summary of \nTime and \nTreatment"
subtitles(tbl_b) <- paste("Number: ", 1:3)
main_footer(tbl_b) <- "NE: Not Estimable"
mf_b <- matrix_form(tbl_b, indent_rownames = TRUE, expand_newlines = TRUE)
res_b <- toString(mf_b, widths = c(16, 12, 12))
res_b <- strsplit(res_b, "\n")[[1]]

# Taking out the splitted col names and the trailing 0s lets check it is the same none-the-less
res_a <- res_a[-10]
res_b <- res_b[-c(10, 11)]
expect_identical(res_a[1:10], res_b[1:10]) # First part
expect_identical(res_a[10:27], res_b[10:27]) # Center part
expect_identical(res_a[seq(28, length(res_a))], res_b[seq(41, length(res_b))]) # Final part

# These errors happen but they should not -> to fix matrix_form (in the second case)
mf_b <- matrix_form(tbl_b, indent_rownames = TRUE, expand_newlines = FALSE)
expect_error(
toString(mf_b, widths = c(17, 12, 12)),
"Found newline characters"
)
})
1 change: 1 addition & 0 deletions tests/testthat/test-regressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test_that("manually created label l rows are always visible",
## was error before rtables 0.3.2.16
test_that("printing table with 0 rows works", {
norows <- rtable(c("hi", "lo"))
mf_rinfo(matrix_form(norows))
capture.output({prout <- print(norows)})
expect_identical(prout, norows)
})
Expand Down