Skip to content

Commit

Permalink
Merge branch 'main' into strict_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelru authored Jan 24, 2024
2 parents 48b2525 + 7b05e38 commit 191b9d4
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ inst/extdata/Advanced_rtables_part1.pdf
inst/extdata/Advances_rtables_part2.pdf
inst/extdata/Clinical_Trial_Reporting_Tables_in_R.pdf
inst/extdata/r_adoption_slides.pdf
inst/cheatsheet/Cheatsheet_v1-rtables.pdf
inst/cheatsheet/Cheatsheet_v1-rtables.pptx
^pkgdown$
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rtables
Title: Reporting Tables
Version: 0.6.6.9003
Date: 2024-01-10
Version: 0.6.6.9005
Date: 2024-01-19
Authors@R: c(
person("Gabriel", "Becker", , "[email protected]", role = "aut",
comment = "Original creator of the package"),
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## rtables 0.6.6.9003
## rtables 0.6.6.9005
### 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 @@ -243,20 +243,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 @@ -266,10 +258,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 @@ -300,23 +288,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
Binary file added inst/cheatsheet/rtables_cheatsheet_01-24.pdf
Binary file not shown.
Binary file added inst/cheatsheet/rtables_cheatsheet_01-24.pptx
Binary file not shown.
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
2 changes: 1 addition & 1 deletion tests/testthat/test-exporters.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ test_that("Can create flextable object that works with different styles", {

# internal package check
not_a_pkg <- "bwrereloakdosirabttjtaeerr"
expect_error(check_required_packages(c("flextable", not_a_pkg)), not_a_pkg)
suppressMessages(expect_error(check_required_packages(c("flextable", not_a_pkg)), not_a_pkg))
})

test_that("export_as_doc works thanks to tt_to_flextable", {
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-pagination.R
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,11 @@ test_that("Pagination works with non-default min_siblings", {
expect_identical(length(ttlst), nlevels(DM$RACE))
expect_identical(tt[1], ttlst[[1]])

expect_error(
paginate_table(tt, lpp = 3, min_siblings = 1),
"Unable to find any valid pagination split between rows 1 and 1"
suppressMessages(
expect_error(
paginate_table(tt, lpp = 3, min_siblings = 1),
"*Unable to find any valid pagination split for page 1 between rows 1 and 1*"
)
)
})

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

0 comments on commit 191b9d4

Please sign in to comment.