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

872 as html fix@main #873

Merged
merged 25 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f1da9f
use string matrix for initialization.
ayogasekaram May 28, 2024
2d743ef
Clean up as_html - implement mf_* getters throughout func
edelarua May 28, 2024
e2beff2
update wordlist
ayogasekaram May 29, 2024
eabaeff
Fix random URL
edelarua May 30, 2024
6708657
add indentation logic to allow newline characters.
ayogasekaram Jun 6, 2024
01e96c4
Merge branch '872_as_html_fix@main' of github.com:insightsengineering…
ayogasekaram Jun 6, 2024
3cb9d17
merge main
ayogasekaram Jun 7, 2024
ccae0fd
remove indentation logic
ayogasekaram Jun 7, 2024
8c7db10
[skip style] [skip vbump] Restyle files
github-actions[bot] Jun 7, 2024
cdd3274
add styler
ayogasekaram Jun 7, 2024
ab05cd3
resolve conflict
ayogasekaram Jun 7, 2024
5be801c
Resolve partial argument match warning in tests - unrelated to as_html
edelarua Jun 7, 2024
6e59224
remove just indenting code.
ayogasekaram Jun 7, 2024
54a4c9a
Merge branch '872_as_html_fix@main' of github.com:insightsengineering…
ayogasekaram Jun 7, 2024
4512fce
reintroduce indentation code. Add mapping b/w linegrouping and indent…
ayogasekaram Jun 10, 2024
ba97cc6
Merge branch 'main' into 872_as_html_fix@main
ayogasekaram Jun 11, 2024
c0a241c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jun 11, 2024
dc52a57
update news
ayogasekaram Jun 11, 2024
30cd0db
apply comments from review
ayogasekaram Jun 11, 2024
63c80a6
[skip style] [skip vbump] Restyle files
github-actions[bot] Jun 11, 2024
c986146
Merge branch 'main' into 872_as_html_fix@main
ayogasekaram Jun 12, 2024
42bbc0a
add regression test
ayogasekaram Jun 12, 2024
355708b
[skip style] [skip vbump] Restyle files
github-actions[bot] Jun 12, 2024
cec443b
change in testing policy
Melkiades Jun 12, 2024
4b8e113
[skip style] [skip vbump] Restyle files
github-actions[bot] Jun 12, 2024
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Fixed bug in `as_html` preventing indentation from being applied in `Viewer` output.
* `col_counts<-` and `col_total<-` methods now explicitly convert `value` to integer, by @gmbecker.
* `col_gap` is now respected in `nlines` row methods, and thus by `make_row_df`, by @gmbecker.
* Updated `as_html` to accommodate `\n` characters.


### Miscellaneous
Expand Down
45 changes: 30 additions & 15 deletions R/as_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ as_html <- function(x,

nlh <- mf_nlheader(mat)
nc <- ncol(x) + 1
nr <- length(mf_lgrouping(mat))

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

for (i in seq_len(nrow(mat$strings))) {
for (j in seq_len(ncol(mat$strings))) {
curstrs <- mat$strings[i, j]
curspn <- mat$spans[i, j]
algn <- mat$aligns[i, j]
for (i in seq_len(nr)) {
for (j in seq_len(nc)) {
curstrs <- mf_strings(mat)[i, j]
curspn <- mf_spans(mat)[i, j]
algn <- mf_aligns(mat)[i, j]

inhdr <- i <= nlh
tagfun <- if (inhdr) tags$th else tags$td
Expand All @@ -110,18 +111,32 @@ as_html <- function(x,
)
}

# row labels style
for (i in seq_len(nrow(x))) {
indent <- mat$row_info$indent[i]
if (indent > 0) { # indentation
cells[i + nlh, 1][[1]] <- htmltools::tagAppendAttributes(cells[i + nlh, 1][[1]],
# Create a map between line numbers and line groupings, adjusting abs_rownumber with nlh
map <- data.frame(lines = seq_len(nr), abs_rownumber = mat$line_grouping)
row_info_df <- data.frame(indent = mat$row_info$indent, abs_rownumber = mat$row_info$abs_rownumber + nlh)
map <- merge(map, row_info_df, by = "abs_rownumber")

# add indent values for headerlines
map <- rbind(data.frame(abs_rownumber = 1:nlh, indent = 0, lines = 0), map)


# Row labels style
for (i in seq_len(nr)) {
indent <- ifelse(any(map$lines == i), map$indent[map$lines == i][1], -1)

# Apply indentation
if (indent > 0) {
cells[i, 1][[1]] <- htmltools::tagAppendAttributes(
cells[i, 1][[1]],
style = paste0("padding-left: ", indent * 3, "ch;")
)
}
if ("row_names" %in% bold) { # font weight
cells[i + nlh, 1][[1]] <- htmltools::tagAppendAttributes(
cells[i + nlh, 1][[1]],
style = paste0("font-weight: bold;")

# Apply bold font weight if "row_names" is in 'bold'
if ("row_names" %in% bold) {
cells[i, 1][[1]] <- htmltools::tagAppendAttributes(
cells[i, 1][[1]],
style = "font-weight: bold;"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/make_split_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ add_combo_facet <- function(name, label = name, levels, extra = list()) {
subexpr <- expression(TRUE)
datpart <- list(fulldf)
} else {
subexpr <- .combine_value_exprs(ret$value[levels])
subexpr <- .combine_value_exprs(ret$values[levels])
datpart <- list(do.call(rbind, ret$datasplit[levels]))
}

Expand Down
3 changes: 3 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ flextable
formatter
formatters
funder
funs
getter
getters
ing
Expand All @@ -57,12 +58,14 @@ mandatorily
monospace
multivariable
orderable
params
pathing
postfix
postprocessing
pre
priori
programmatically
quartiles
reindexed
repo
repped
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-exporters.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,36 @@ test_that("as_html header line works", {
expect_true(all(sapply(1:4, function(x) "border-bottom: 1px solid black;" %in% html_parts[[x]]$attribs)))
})

# https://github.com/insightsengineering/rtables/issues/872
test_that("as_html indentation is translated to rows with linebreaks", {
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("SEX") %>%
analyze("AGE", afun = function(x) {
mn <- round(mean(x), 2)
if (!is.nan(mn) && mn > mean(DM$AGE)) {
val <- paste(mn, " ^ ", sep = "\n")
} else {
val <- paste(mn)
}
in_rows(my_row_label = rcell(val,
format = "xx"
))
})
tbl <- build_table(lyt, DM)

# Resolves correctly \n
expect_silent(res <- as_html(tbl))
expect_equal(
as.character(res$children[[1]][[2]]$children[[7]]$children[[1]][[1]]),
'<td style="text-align: left; padding-left: 3ch;"></td>'
)
expect_equal(
as.character(res$children[[1]][[2]]$children[[7]]$children[[1]][[2]]),
'<td style="text-align: center;"> ^ </td>'
)
})

## https://github.com/insightsengineering/rtables/issues/308
test_that("path_enriched_df works for tables with a column that has all length 1 elements", {
my_table <- basic_table() %>%
Expand Down
Loading