Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Oct 12, 2023
1 parent 08ed785 commit e3dfa6f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
28 changes: 23 additions & 5 deletions R/as_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ as_html <- function(x,
nrh <- mf_nrheader(mat)
nc <- ncol(x) + 1

cells <- matrix(rep(list(list()), (nrh + nrow(x)) * (nc)),
ncol = nc)
# Structure is a list of lists with rows (one for each line grouping) and cols as dimensions
cells <- matrix(rep(list(list()), (nrh + nrow(x)) * (nc)), ncol = nc)

for(i in unique(mat$line_grouping)) {
rows <- which(mat$line_grouping == i)
Expand Down Expand Up @@ -121,9 +121,27 @@ as_html <- function(x,
}

if (any(!mat$display)) {
ii <- apply(mat$display, 2, function(xx) any(!xx))
jj <- apply(mat$display, 1, function(xx) any(!xx))
cells[ii, jj, drop = FALSE] <- NA_integer_
# Check that expansion kept the same display info
check_expansion <- c()
for(ii in unique(mat$line_grouping)) {
rows <- which(mat$line_grouping == ii)
check_expansion <- c(
check_expansion,
apply(mat$display[rows, , drop = FALSE], 2, function(x) all(x) || all(!x))
)
}

if (!all(check_expansion)) {
stop("Found that a group of rows have different display options even if ",
"they belong to the same line group. This should not happen. Please ",
"file an issue or report to the maintainers.") # nocov
}

for (ii in unique(mat$line_grouping)) {
rows <- which(mat$line_grouping == ii)
should_display_col <- apply(mat$display[rows, , drop = FALSE], 2, any)
cells[ii, !should_display_col] <- NA_integer_
}
}

rows <- apply(cells, 1, function(row) {
Expand Down
1 change: 1 addition & 0 deletions man/as_html.Rd

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

16 changes: 14 additions & 2 deletions tests/testthat/test-exporters.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,21 @@ test_that("as_html Viewer with newline test", {
split_cols_by_multivar(c("AGE", "AGE"), varlabels = varlabs) %>%
analyze_colvars(afun = colfuns)

tbl <- build_table(lyt, DM)
tbl_wrapping <- build_table(lyt, DM)

tbl_normal <- rtable(
header = c("Treatement\nN=100", "Comparison\nN=300"),
format = "xx (xx.xx%)",
rrow("A", c(104, .2), c(100, .4)),
rrow("B", c(23, .4), c(43, .5)),
rrow(),
rrow("this is a very long section header"),
rrow("estimate", rcell(55.23, "xx.xx", colspan = 2)),
rrow("95% CI", indent = 1, rcell(c(44.8, 67.4), format = "(xx.x, xx.x)", colspan = 2))
)
oldo <- options(viewer = identity)
expect_silent(fl <- Viewer(tbl))
expect_silent(fl <- Viewer(tbl_wrapping))
expect_silent(fl <- Viewer(tbl_normal))
xml2::read_html(fl)
expect_true(TRUE)
options(oldo)
Expand Down

0 comments on commit e3dfa6f

Please sign in to comment.