diff --git a/main/coverage-report/index.html b/main/coverage-report/index.html index 5ba60dbe2..d5b875952 100644 --- a/main/coverage-report/index.html +++ b/main/coverage-report/index.html @@ -95,7 +95,7 @@ font-size: 11px; }
-

rtables coverage - 90.59%

+

rtables coverage - 90.63%

-
- +
+
@@ -250,7 +250,7 @@

rtables coverage - 90.59%

20 - 2352x + 2299x
  function(x) length(collect_leaves(x, TRUE, TRUE))
@@ -481,7 +481,7 @@

rtables coverage - 90.59%

53 - 23277x + 23164x
    ncol(col_info(x))
@@ -544,14 +544,14 @@

rtables coverage - 90.59%

62 - 70476x + 70239x
    if (!no_colinfo(x)) {
63 - 69420x + 69183x
      ncol(col_info(x))
@@ -698,7 +698,7 @@

rtables coverage - 90.59%

84 - 118284x + 117934x
    length(col_exprs(x))
@@ -754,7 +754,7 @@

rtables coverage - 90.59%

92 - 19254x + 19141x
  function(x) c(nrow(x), ncol(x))
@@ -838,7 +838,7 @@

rtables coverage - 90.59%

104 - 249544x + 247959x
setGeneric("tree_children", function(x) standardGeneric("tree_children"))
@@ -929,7 +929,7 @@

rtables coverage - 90.59%

117 - 67112x + 66518x
  function(x) x@children
@@ -1265,7 +1265,7 @@

rtables coverage - 90.59%

165 - 93304x + 92627x
setGeneric("content_table", function(obj) standardGeneric("content_table"))
@@ -1307,7 +1307,7 @@

rtables coverage - 90.59%

171 - 61511x + 60898x
  function(obj) obj@content
@@ -3715,7 +3715,7 @@

rtables coverage - 90.59%

515 - 48856x + 48541x
  function(obj) obj@name
@@ -3974,7 +3974,7 @@

rtables coverage - 90.59%

552 - 42652x + 42325x
setMethod("obj_label", "TableRow", function(obj) obj@label)
@@ -4429,7 +4429,7 @@

rtables coverage - 90.59%

617 - 139713x + 138265x
setGeneric("tt_labelrow", function(obj) standardGeneric("tt_labelrow"))
@@ -4464,7 +4464,7 @@

rtables coverage - 90.59%

622 - 51439x + 50592x
  function(obj) obj@labelrow
@@ -4597,7 +4597,7 @@

rtables coverage - 90.59%

641 - 211119x + 208927x
setGeneric("labelrow_visible", function(obj) standardGeneric("labelrow_visible"))
@@ -4639,7 +4639,7 @@

rtables coverage - 90.59%

647 - 31309x + 30715x
    labelrow_visible(tt_labelrow(obj))
@@ -4688,7 +4688,7 @@

rtables coverage - 90.59%

654 - 115712x + 114571x
  function(obj) obj@visible
@@ -7012,7 +7012,7 @@

rtables coverage - 90.59%

986 - 72121x + 71884x
setGeneric("row_cells", function(obj) standardGeneric("row_cells"))
@@ -7040,7 +7040,7 @@

rtables coverage - 90.59%

990 - 8418x + 8361x
setMethod("row_cells", "TableRow", function(obj) obj@leaf_value)
@@ -8062,7 +8062,7 @@

rtables coverage - 90.59%

1136 - 7103x + 7065x
setMethod("obj_format", "VTableNodeInfo", function(obj) obj@format)
@@ -8090,7 +8090,7 @@

rtables coverage - 90.59%

1140 - 113549x + 113249x
setMethod("obj_format", "CellValue", function(obj) attr(obj, "format", exact = TRUE))
@@ -8440,7 +8440,7 @@

rtables coverage - 90.59%

1190 - 29557x + 29478x
setMethod("obj_na_str", "VTableNodeInfo", function(obj) obj@na_str)
@@ -9819,7 +9819,7 @@

rtables coverage - 90.59%

1387 - 112908x + 111981x
    standardGeneric("collect_leaves")
@@ -9903,21 +9903,21 @@

rtables coverage - 90.59%

1399 - 26034x + 25500x
    ret <- c(
1400 - 26034x + 25500x
      if (add.labrows && labelrow_visible(tt)) {
1401 - 10671x + 10458x
        tt_labelrow(tt)
@@ -9931,14 +9931,14 @@

rtables coverage - 90.59%

1403 - 26034x + 25500x
      if (incl.cont) {
1404 - 26034x + 25500x
        tree_children(content_table(tt))
@@ -9952,21 +9952,21 @@

rtables coverage - 90.59%

1406 - 26034x + 25500x
      lapply(tree_children(tt),
1407 - 26034x + 25500x
        collect_leaves,
1408 - 26034x + 25500x
        incl.cont = incl.cont, add.labrows = add.labrows
@@ -9987,7 +9987,7 @@

rtables coverage - 90.59%

1411 - 26034x + 25500x
    unlist(ret, recursive = TRUE)
@@ -10050,21 +10050,21 @@

rtables coverage - 90.59%

1420 - 56997x + 56604x
    ret <- tree_children(tt)
1421 - 56997x + 56604x
    if (add.labrows && labelrow_visible(tt)) {
1422 - 11080x + 10960x
      ret <- c(tt_labelrow(tt), ret)
@@ -10078,7 +10078,7 @@

rtables coverage - 90.59%

1424 - 56997x + 56604x
    ret
@@ -10435,7 +10435,7 @@

rtables coverage - 90.59%

1475 - 56665x + 56507x
setGeneric("row_cspans", function(obj) standardGeneric("row_cspans"))
@@ -10456,7 +10456,7 @@

rtables coverage - 90.59%

1478 - 5226x + 5188x
setMethod("row_cspans", "TableRow", function(obj) obj@colspans)
@@ -11205,7 +11205,7 @@

rtables coverage - 90.59%

1585 - 56433x + 56166x
setGeneric("indent_mod", function(obj) standardGeneric("indent_mod"))
@@ -11282,7 +11282,7 @@

rtables coverage - 90.59%

1596 - 26836x + 26569x
  function(obj) obj@indent_modifier
@@ -12115,7 +12115,7 @@

rtables coverage - 90.59%

1715 - 173198x + 172898x
setGeneric("rawvalues", function(obj) standardGeneric("rawvalues"))
@@ -12220,7 +12220,7 @@

rtables coverage - 90.59%

1730 - 88787x + 88487x
setMethod("rawvalues", "CellValue", function(obj) obj[[1]])
@@ -13865,7 +13865,7 @@

rtables coverage - 90.59%

1965 - 274087x + 273500x
setGeneric("col_info", function(obj) standardGeneric("col_info"))
@@ -13907,7 +13907,7 @@

rtables coverage - 90.59%

1971 - 240399x + 239812x
  function(obj) obj@col_info
@@ -15076,7 +15076,7 @@

rtables coverage - 90.59%

2138 - 124532x + 124182x
setGeneric("col_exprs", function(obj, df = NULL) standardGeneric("col_exprs"))
@@ -15265,7 +15265,7 @@

rtables coverage - 90.59%

2165 - 124530x + 124180x
    if (!is.null(df)) {
@@ -15286,7 +15286,7 @@

rtables coverage - 90.59%

2168 - 124530x + 124180x
    obj@subset_exprs
@@ -20928,7 +20928,7 @@

rtables coverage - 90.59%

2974 - 182368x + 181894x
setGeneric("no_colinfo", function(obj) standardGeneric("no_colinfo"))
@@ -20970,7 +20970,7 @@

rtables coverage - 90.59%

2980 - 78012x + 77775x
  function(obj) no_colinfo(col_info(obj))
@@ -21019,7 +21019,7 @@

rtables coverage - 90.59%

2987 - 94206x + 93969x
  function(obj) length(obj@subset_exprs) == 0
@@ -24155,7 +24155,7 @@

rtables coverage - 90.59%

3435 - 54366x + 54073x
setGeneric("row_footnotes", function(obj) standardGeneric("row_footnotes"))
@@ -24197,7 +24197,7 @@

rtables coverage - 90.59%

3441 - 52332x + 52039x
  function(obj) obj@row_footnotes
@@ -24456,7 +24456,7 @@

rtables coverage - 90.59%

3478 - 212558x + 211800x
setGeneric("cell_footnotes", function(obj) standardGeneric("cell_footnotes"))
@@ -24498,7 +24498,7 @@

rtables coverage - 90.59%

3484 - 170178x + 169578x
  function(obj) attr(obj, "footnotes", exact = TRUE) %||% list()
@@ -24554,14 +24554,14 @@

rtables coverage - 90.59%

3492 - 37366x + 37208x
    ret <- lapply(row_cells(obj), cell_footnotes)
3493 - 37366x + 37208x
    if (length(ret) != ncol(obj)) {
@@ -24582,7 +24582,7 @@

rtables coverage - 90.59%

3496 - 37366x + 37208x
    ret
@@ -25660,7 +25660,7 @@

rtables coverage - 90.59%

3650 - 3912x + 3900x
setGeneric("ref_index", function(obj) standardGeneric("ref_index"))
@@ -25702,7 +25702,7 @@

rtables coverage - 90.59%

3656 - 3912x + 3900x
  function(obj) obj@index
@@ -25835,7 +25835,7 @@

rtables coverage - 90.59%

3675 - 3793x + 3781x
setGeneric("ref_symbol", function(obj) standardGeneric("ref_symbol"))
@@ -25877,7 +25877,7 @@

rtables coverage - 90.59%

3681 - 3793x + 3781x
  function(obj) obj@symbol
@@ -26010,7 +26010,7 @@

rtables coverage - 90.59%

3700 - 2929x + 2917x
setGeneric("ref_msg", function(obj) standardGeneric("ref_msg"))
@@ -26052,7 +26052,7 @@

rtables coverage - 90.59%

3706 - 2929x + 2917x
  function(obj) obj@value
@@ -27634,28 +27634,28 @@

rtables coverage - 90.59%

3932 - 27080x + 26813x
setGeneric("trailing_section_div", function(obj) standardGeneric("trailing_section_div"))
3933 - 10651x + 10527x
setMethod("trailing_section_div", "VTableTree", function(obj) obj@trailing_section_div)
3934 - 5169x + 5105x
setMethod("trailing_section_div", "LabelRow", function(obj) obj@trailing_section_div)
3935 - 11260x + 11181x
setMethod("trailing_section_div", "TableRow", function(obj) obj@trailing_section_div)
@@ -27669,7 +27669,7 @@

rtables coverage - 90.59%

3937 - 1646x + 1627x
setGeneric("trailing_section_div<-", function(obj, value) standardGeneric("trailing_section_div<-"))
@@ -27683,14 +27683,14 @@

rtables coverage - 90.59%

3939 - 1547x + 1528x
  obj@trailing_section_div <- value
3940 - 1547x + 1528x
  obj
@@ -93596,35 +93596,35 @@

rtables coverage - 90.59%

21 - 11198x + 11119x
    fns <- sum(unlist(lapply(row_footnotes(x), nlines, max_width = max_width, fontspec = fontspec))) +
22 - 11198x + 11119x
      sum(unlist(lapply(cell_footnotes(x), nlines, max_width = max_width, fontspec = fontspec)))
23 - 11198x + 11119x
    fcells <- as.vector(get_formatted_cells(x))
24 - 11198x + 11119x
    spans <- row_cspans(x)
25 - 11198x + 11119x
    have_cw <- !is.null(colwidths)
@@ -93638,7 +93638,7 @@

rtables coverage - 90.59%

27 - 11198x + 11119x
    if (any(spans > 1)) {
@@ -93785,35 +93785,35 @@

rtables coverage - 90.59%

48 - 11198x + 11119x
    rowext <- max(
49 - 11198x + 11119x
      unlist(
50 - 11198x + 11119x
        mapply(
51 - 11198x + 11119x
          function(s, w) {
52 - 60762x + 60383x
            nlines(strsplit(s, "\n", fixed = TRUE), max_width = w, fontspec = fontspec)
@@ -93827,21 +93827,21 @@

rtables coverage - 90.59%

54 - 11198x + 11119x
          s = c(obj_label(x), fcells),
55 - 11198x + 11119x
          w = (colwidths %||% max_width) %||% vector("list", length(c(obj_label(x), fcells))),
56 - 11198x + 11119x
          SIMPLIFY = FALSE
@@ -93876,7 +93876,7 @@

rtables coverage - 90.59%

61 - 11198x + 11119x
    rowext + fns
@@ -93939,21 +93939,21 @@

rtables coverage - 90.59%

70 - 3633x + 3588x
    if (labelrow_visible(x)) {
71 - 3633x + 3588x
      nlines(strsplit(obj_label(x), "\n", fixed = TRUE)[[1]], max_width = colwidths[1], fontspec = fontspec) +
72 - 3633x + 3588x
        sum(unlist(lapply(row_footnotes(x), nlines, max_width = max_width, fontspec = fontspec)))
@@ -94037,7 +94037,7 @@

rtables coverage - 90.59%

84 - 2140x + 2128x
    nlines(format_fnote_note(x), colwidths = colwidths, max_width = max_width, fontspec = fontspec)
@@ -95010,7 +95010,7 @@

rtables coverage - 90.59%

223 - 10460x + 10336x
    indent <- indent + indent_mod(tt)
@@ -95024,28 +95024,28 @@

rtables coverage - 90.59%

225 - 10460x + 10336x
    orig_rownum <- rownum # nolint
226 - 10460x + 10336x
    if (incontent) {
227 - 1455x + 1436x
      path <- c(path, "@content")
228 - 9005x + 8900x
    } else if (length(path) > 0 || nzchar(obj_name(tt))) { ## don't add "" for root
@@ -95059,7 +95059,7 @@

rtables coverage - 90.59%

230 - 8957x + 8852x
      path <- c(path, obj_name(tt))
@@ -95073,7 +95073,7 @@

rtables coverage - 90.59%

232 - 10460x + 10336x
    ret <- list()
@@ -95094,7 +95094,7 @@

rtables coverage - 90.59%

235 - 10460x + 10336x
    if (!visible_only) {
@@ -95248,91 +95248,91 @@

rtables coverage - 90.59%

257 - 10460x + 10336x
    if (labelrow_visible(tt)) {
258 - 3613x + 3568x
      lr <- tt_labelrow(tt)
259 - 3613x + 3568x
      newdf <- make_row_df(lr,
260 - 3613x + 3568x
        colwidths = colwidths,
261 - 3613x + 3568x
        visible_only = visible_only,
262 - 3613x + 3568x
        rownum = rownum,
263 - 3613x + 3568x
        indent = indent,
264 - 3613x + 3568x
        path = path,
265 - 3613x + 3568x
        incontent = TRUE,
266 - 3613x + 3568x
        repr_ext = repr_ext,
267 - 3613x + 3568x
        repr_inds = repr_inds,
268 - 3613x + 3568x
        max_width = max_width,
269 - 3613x + 3568x
        fontspec = fontspec
@@ -95346,7 +95346,7 @@

rtables coverage - 90.59%

271 - 3613x + 3568x
      rownum <- max(newdf$abs_rownumber, na.rm = TRUE)
@@ -95360,21 +95360,21 @@

rtables coverage - 90.59%

273 - 3613x + 3568x
      ret <- c(
274 - 3613x + 3568x
        ret,
275 - 3613x + 3568x
        list(newdf)
@@ -95388,21 +95388,21 @@

rtables coverage - 90.59%

277 - 3613x + 3568x
      repr_ext <- repr_ext + 1L
278 - 3613x + 3568x
      repr_inds <- c(repr_inds, rownum)
279 - 3613x + 3568x
      indent <- indent + 1L
@@ -95423,105 +95423,105 @@

rtables coverage - 90.59%

282 - 10460x + 10336x
    if (NROW(content_table(tt)) > 0) {
283 - 1455x + 1436x
      ct_tt <- content_table(tt)
284 - 1455x + 1436x
      cind <- indent + indent_mod(ct_tt)
285 - 1455x + 1436x
      trailing_section_div(ct_tt) <- trailing_section_div(tt_labelrow(tt))
286 - 1455x + 1436x
      contdf <- make_row_df(ct_tt,
287 - 1455x + 1436x
        colwidths = colwidths,
288 - 1455x + 1436x
        visible_only = visible_only,
289 - 1455x + 1436x
        rownum = rownum,
290 - 1455x + 1436x
        indent = cind,
291 - 1455x + 1436x
        path = path,
292 - 1455x + 1436x
        incontent = TRUE,
293 - 1455x + 1436x
        repr_ext = repr_ext,
294 - 1455x + 1436x
        repr_inds = repr_inds,
295 - 1455x + 1436x
        max_width = max_width,
296 - 1455x + 1436x
        fontspec = fontspec
@@ -95535,14 +95535,14 @@

rtables coverage - 90.59%

298 - 1455x + 1436x
      crnums <- contdf$abs_rownumber
299 - 1455x + 1436x
      crnums <- crnums[!is.na(crnums)]
@@ -95556,35 +95556,35 @@

rtables coverage - 90.59%

301 - 1455x + 1436x
      newrownum <- max(crnums, na.rm = TRUE)
302 - 1455x + 1436x
      if (is.finite(newrownum)) {
303 - 1455x + 1436x
        rownum <- newrownum
304 - 1455x + 1436x
        repr_ext <- repr_ext + length(crnums)
305 - 1455x + 1436x
        repr_inds <- c(repr_inds, crnums)
@@ -95598,14 +95598,14 @@

rtables coverage - 90.59%

307 - 1455x + 1436x
      ret <- c(ret, list(contdf))
308 - 1455x + 1436x
      indent <- cind + 1
@@ -95626,119 +95626,119 @@

rtables coverage - 90.59%

311 - 10460x + 10336x
    allkids <- tree_children(tt)
312 - 10460x + 10336x
    newnsibs <- length(allkids)
313 - 10460x + 10336x
    for (i in seq_along(allkids)) {
314 - 19336x + 19159x
      kid <- allkids[[i]]
315 - 19336x + 19159x
      kiddfs <- make_row_df(kid,
316 - 19336x + 19159x
        colwidths = colwidths,
317 - 19336x + 19159x
        visible_only = visible_only,
318 - 19336x + 19159x
        rownum = force(rownum),
319 - 19336x + 19159x
        indent = indent, ## + 1,
320 - 19336x + 19159x
        path = path,
321 - 19336x + 19159x
        incontent = incontent,
322 - 19336x + 19159x
        repr_ext = repr_ext,
323 - 19336x + 19159x
        repr_inds = repr_inds,
324 - 19336x + 19159x
        nsibs = newnsibs,
325 - 19336x + 19159x
        sibpos = i,
326 - 19336x + 19159x
        max_width = max_width,
327 - 19336x + 19159x
        fontspec = fontspec
@@ -95766,14 +95766,14 @@

rtables coverage - 90.59%

331 - 19336x + 19159x
      rownum <- max(rownum + 1L, kiddfs$abs_rownumber, na.rm = TRUE)
332 - 19336x + 19159x
      ret <- c(ret, list(kiddfs))
@@ -95794,7 +95794,7 @@

rtables coverage - 90.59%

335 - 10460x + 10336x
    ret <- do.call(rbind, ret)
@@ -95815,7 +95815,7 @@

rtables coverage - 90.59%

338 - 10460x + 10336x
    if (!is.na(trailing_section_div(tt))) {
@@ -95836,7 +95836,7 @@

rtables coverage - 90.59%

341 - 10460x + 10336x
    ret
@@ -95997,84 +95997,84 @@

rtables coverage - 90.59%

364 - 11188x + 11109x
    indent <- indent + indent_mod(tt)
365 - 11188x + 11109x
    rownum <- rownum + 1
366 - 11188x + 11109x
    rrefs <- row_footnotes(tt)
367 - 11188x + 11109x
    crefs <- cell_footnotes(tt)
368 - 11188x + 11109x
    reflines <- sum(
369 - 11188x + 11109x
      sapply(
370 - 11188x + 11109x
        c(rrefs, crefs),
371 - 11188x + 11109x
        nlines,
372 - 11188x + 11109x
        colwidths = colwidths,
373 - 11188x + 11109x
        max_width = max_width,
374 - 11188x + 11109x
        fontspec = fontspec,
375 - 11188x + 11109x
        col_gap = col_gap
@@ -96088,84 +96088,84 @@

rtables coverage - 90.59%

377 - 11188x + 11109x
    ) ## col_gap not strictly necessary as these aren't rows, but why not
378 - 11188x + 11109x
    ret <- pagdfrow(
379 - 11188x + 11109x
      row = tt,
380 - 11188x + 11109x
      rnum = rownum,
381 - 11188x + 11109x
      colwidths = colwidths,
382 - 11188x + 11109x
      sibpos = sibpos,
383 - 11188x + 11109x
      nsibs = nsibs,
384 - 11188x + 11109x
      pth = c(path, unname(obj_name(tt))),
385 - 11188x + 11109x
      repext = repr_ext,
386 - 11188x + 11109x
      repind = repr_inds,
387 - 11188x + 11109x
      indent = indent,
388 - 11188x + 11109x
      extent = nlines(tt, colwidths = colwidths, max_width = max_width, fontspec = fontspec, col_gap = col_gap),
@@ -96179,35 +96179,35 @@

rtables coverage - 90.59%

390 - 11188x + 11109x
      nrowrefs = length(rrefs),
391 - 11188x + 11109x
      ncellrefs = length(unlist(crefs)),
392 - 11188x + 11109x
      nreflines = reflines,
393 - 11188x + 11109x
      trailing_sep = trailing_section_div(tt),
394 - 11188x + 11109x
      fontspec = fontspec
@@ -96221,7 +96221,7 @@

rtables coverage - 90.59%

396 - 11188x + 11109x
    ret
@@ -96368,133 +96368,133 @@

rtables coverage - 90.59%

417 - 3633x + 3588x
    rownum <- rownum + 1
418 - 3633x + 3588x
    indent <- indent + indent_mod(tt)
419 - 3633x + 3588x
    ret <- pagdfrow(tt,
420 - 3633x + 3588x
      extent = nlines(tt, colwidths = colwidths, max_width = max_width, fontspec = fontspec, col_gap = col_gap),
421 - 3633x + 3588x
      rnum = rownum,
422 - 3633x + 3588x
      colwidths = colwidths,
423 - 3633x + 3588x
      sibpos = sibpos,
424 - 3633x + 3588x
      nsibs = nsibs,
425 - 3633x + 3588x
      pth = path,
426 - 3633x + 3588x
      repext = repr_ext,
427 - 3633x + 3588x
      repind = repr_inds,
428 - 3633x + 3588x
      indent = indent,
429 - 3633x + 3588x
      nrowrefs = length(row_footnotes(tt)),
430 - 3633x + 3588x
      ncellrefs = 0L,
431 - 3633x + 3588x
      nreflines = sum(vapply(row_footnotes(tt), nlines, NA_integer_,
432 - 3633x + 3588x
        colwidths = colwidths,
433 - 3633x + 3588x
        max_width = max_width,
434 - 3633x + 3588x
        fontspec = fontspec,
435 - 3633x + 3588x
        col_gap = col_gap
@@ -96508,14 +96508,14 @@

rtables coverage - 90.59%

437 - 3633x + 3588x
      trailing_sep = trailing_section_div(tt),
438 - 3633x + 3588x
      fontspec = fontspec
@@ -96529,7 +96529,7 @@

rtables coverage - 90.59%

440 - 3633x + 3588x
    if (!labelrow_visible(tt)) {
@@ -96550,7 +96550,7 @@

rtables coverage - 90.59%

443 - 3633x + 3588x
    ret
@@ -120115,4092 +120115,4862 @@

rtables coverage - 90.59%

590 -
#'   page size.
+
#'   page size. Defaults to `section_properties_default()`.
591 -
#'
+
#' @param ... (`any`)\cr additional arguments passed to [tt_to_flextable()].
592 -
#' @note `export_as_docx()` has few customization options available. If you require specific formats and details,
+
#'
593 -
#'   we suggest that you use [tt_to_flextable()] prior to `export_as_docx`. Only the `title_as_header` and
+
#' @note `export_as_docx()` has few customization options available. If you require specific formats and details,
594 -
#'   `footer_as_text` parameters must be re-specified if the table is changed first using [tt_to_flextable()].
+
#'   we suggest that you use [tt_to_flextable()] prior to `export_as_docx`. Only the `title_as_header` and
595 -
#'
+
#'   `footer_as_text` parameters must be re-specified if the table is changed first using [tt_to_flextable()].
596 -
#' @seealso [tt_to_flextable()]
+
#'
597 -
#'
+
#' @seealso [tt_to_flextable()]
598 -
#' @examples
+
#'
599 -
#' lyt <- basic_table() %>%
+
#' @examples
600 -
#'   split_cols_by("ARM") %>%
+
#' lyt <- basic_table() %>%
601 -
#'   analyze(c("AGE", "BMRKR2", "COUNTRY"))
+
#'   split_cols_by("ARM") %>%
602 -
#'
+
#'   analyze(c("AGE", "BMRKR2", "COUNTRY"))
603 -
#' tbl <- build_table(lyt, ex_adsl)
+
#'
604 -
#'
+
#' tbl <- build_table(lyt, ex_adsl)
605 -
#' # See how section_properties_portrait function is built for custom
+
#'
606 -
#' \dontrun{
+
#' # See how section_properties_portrait function is built for custom
607 -
#' tf <- tempfile(fileext = ".docx")
+
#' \dontrun{
608 -
#' export_as_docx(tbl, file = tf, section_properties = section_properties_portrait())
+
#' tf <- tempfile(fileext = ".docx")
609 -
#' }
+
#' export_as_docx(tbl,
610 -
#'
+
#'   file = tf,
611 -
#' @export
+
#'   section_properties = section_properties_default(orientation = "landscape")
612 -
export_as_docx <- function(tt,
+
#' )
613 -
                           file,
+
#' }
614 -
                           doc_metadata = NULL,
+
#'
615 -
                           titles_as_header = FALSE,
+
#' @export
616 -
                           footers_as_text = TRUE,
+
export_as_docx <- function(tt,
617 -
                           template_file = NULL,
+
                           file,
618 -
                           section_properties = NULL) {
+
                           doc_metadata = NULL,
619 + +
                           titles_as_header = FALSE,
+ + + + 620 + + +
                           footers_as_text = TRUE,
+ + + + 621 + + +
                           template_file = NULL,
+ + + + 622 + + +
                           section_properties = section_properties_default(),
+ + + + 623 + + +
                           ...) {
+ + + + 624 +
  # Checks
- 620 + 625 3x
  check_required_packages(c("flextable", "officer"))
- 621 + 626 3x
  if (inherits(tt, "VTableTree")) {
- 622 + 627 2x
    flex_tbl <- tt_to_flextable(tt,
- 623 + 628 2x
      titles_as_header = titles_as_header,
- 624 + 629 2x -
      footers_as_text = footers_as_text
+
      footers_as_text = footers_as_text,
- 625 + 630 + + +
      ...
+ + + + 631
    )
- 626 + 632 2x
    if (isFALSE(titles_as_header) || isTRUE(footers_as_text)) {
- 627 + 633
      # Ugly but I could not find a getter for font.size
- 628 + 634 2x
      font_sz <- flex_tbl$header$styles$text$font.size$data[1, 1]
- 629 + 635 2x
      font_sz_footer <- flex_tbl$header$styles$text$font.size$data[1, 1] - 1
- 630 + 636 2x
      font_fam <- flex_tbl$header$styles$text$font.family$data[1, 1]
- 631 + 637

                     
                   
                   
-                    632
+                    638
                     
                     
                       
      # Set the test as the tt
- 633 + 639 2x
      fpt <- officer::fp_text(font.family = font_fam, font.size = font_sz)
- 634 + 640 2x
      fpt_footer <- officer::fp_text(font.family = font_fam, font.size = font_sz_footer)
- 635 + 641
    }
- 636 + 642
  } else {
- 637 + 643 1x
    flex_tbl <- tt
- 638 + 644
  }
- 639 + 645 3x
  if (!is.null(template_file) && !file.exists(template_file)) {
- 640 + 646 1x
    template_file <- NULL
- 641 + 647
  }
- 642 + 648

                     
                   
                   
-                    643
+                    649
                     
                     
                       
  # Create a new empty Word document
- 644 + 650 3x
  if (!is.null(template_file)) {
- 645 + 651 2x
    doc <- officer::read_docx(template_file)
- 646 + 652
  } else {
- 647 + 653 1x
    doc <- officer::read_docx()
- 648 + 654
  }
- 649 + 655

                     
                   
                   
-                    650
+                    656
                     3x
                     
                       
  if (!is.null(section_properties)) {
- 651 + 657 3x
    doc <- officer::body_set_default_section(doc, section_properties)
- 652 + 658
  }
- 653 + 659

                     
                   
                   
-                    654
+                    660
                     
                     
                       
  # Extract title
- 655 + 661 3x
  if (isFALSE(titles_as_header) && inherits(tt, "VTableTree")) {
- 656 + 662 2x
    ts_tbl <- all_titles(tt)
- 657 + 663 2x
    if (length(ts_tbl) > 0) {
- 658 + 664 2x
      doc <- add_text_par(doc, ts_tbl, fpt)
- 659 + 665
    }
- 660 + 666
  }
- 661 + 667

                     
                   
                   
-                    662
+                    668
                     
                     
                       
  # Add the table to the document
- 663 + 669 3x
  doc <- flextable::body_add_flextable(doc, flex_tbl, align = "left")
- 664 + 670

                     
                   
                   
-                    665
+                    671
                     
                     
                       
  # add footers as paragraphs
- 666 + 672 3x
  if (isTRUE(footers_as_text) && inherits(tt, "VTableTree")) {
- 667 + 673 -
    # Adding referantial footer line separator if present
+
    # Adding referential footer line separator if present
- 668 + 674
    # (this is usually done differently, i.e. inside footnotes)
- 669 + 675 2x
    matform <- matrix_form(tt, indent_rownames = TRUE)
- 670 + 676 2x
    if (length(matform$ref_footnotes) > 0) {
- 671 + 677 2x
      doc <- add_text_par(doc, matform$ref_footnotes, fpt_footer)
- 672 + 678
    }
- 673 + 679
    # Footer lines
- 674 + 680 2x
    if (length(all_footers(tt)) > 0) {
- 675 + 681 2x
      doc <- add_text_par(doc, all_footers(tt), fpt_footer)
- 676 + 682
    }
- 677 + 683
  }
- 678 + 684

                     
                   
                   
-                    679
+                    685
                     3x
                     
                       
  if (!is.null(doc_metadata)) {
- 680 + 686
    # Checks for values rely on officer function
- 681 + 687 3x
    doc <- do.call(officer::set_doc_properties, c(list("x" = doc), doc_metadata))
- 682 + 688
  }
- 683 + 689

                     
                   
                   
-                    684
+                    690
                     
                     
                       
  # Save the Word document to a file
- 685 + 691 3x
  print(doc, target = file)
- 686 + 692
}
- 687 + 693

                     
                   
                   
-                    688
+                    694
                     
                     
                       
# Shorthand to add text paragraph
- 689 + 695
add_text_par <- function(doc, chr_v, text_format) {
- 690 + 696 6x
  for (ii in seq_along(chr_v)) {
- 691 + 697 16x
    cur_fp <- officer::fpar(officer::ftext(chr_v[ii], prop = text_format))
- 692 + 698 16x
    doc <- officer::body_add_fpar(doc, cur_fp)
- 693 + 699
  }
- 694 + 700 6x
  doc
- 695 + 701
}
- 696 + 702

                     
                   
                   
-                    697
+                    703
                     
                     
                       
#' @describeIn export_as_docx Helper function that defines standard portrait properties for tables.
- 698 + 704 + + +
#' @param page_size (`character(1)`) page size. Can be `"letter"` or `"A4"`. Defaults to `"letter"`.
+ + + + 705 + + +
#' @param orientation (`character(1)`) page orientation. Can be `"portrait"` or `"landscape"`. Defaults to
+ + + + 706 + + +
#'   `"portrait"`.
+ + + + 707 + + +
#'
+ + + + 708
#' @export
- 699 + 709 + + +
section_properties_default <- function(page_size = c("letter", "A4"),
+ + + + 710 -
section_properties_portrait <- function() {
+
                                       orientation = c("portrait", "landscape")) {
- 700 - 2x + 711 + 3x -
  officer::prop_section(
+
  page_size <- page_size[1]
- 701 - 2x + 712 + 3x -
    page_size = officer::page_size(
+
  orientation <- orientation[1]
- 702 - 2x + 713 + 3x -
      orient = "portrait",
+
  checkmate::assert_choice(
- 703 - 2x + 714 + 3x -
      width = 8.5, height = 11
+
    page_size,
+ + + + 715 + 3x + +
    eval(formals(section_properties_default)$page_size)
- 704 + 716 -
    ),
+
  )
- 705 - 2x + 717 + 3x -
    type = "continuous",
+
  checkmate::assert_choice(
- 706 - 2x + 718 + 3x -
    page_margins = margins_potrait()
+
    orientation,
- - 707 - + + 719 + 3x -
  )
+
    eval(formals(section_properties_default)$orientation)
- 708 + 720 -
}
+
  )
- 709 + 721

                     
                   
-                  
-                    710
-                    
+                  
+                    722
+                    3x
+                    
+                      
  if (page_size == "letter") {
+ + + + 723 + 2x + +
    page_size <- officer::page_size(
+ + + + 724 + 2x -
#' @describeIn export_as_docx Helper function that defines standard landscape properties for tables.
+
      orient = orientation,
+ + + + 725 + 2x + +
      width = 8.5, height = 11
- 711 + 726 -
#' @export
+
    )
- 712 + 727 -
section_properties_landscape <- function() {
+
  } else { # A4
- 713 + 728 1x -
  officer::prop_section(
+
    page_size <- officer::page_size(
- 714 + 729 1x -
    page_size = officer::page_size(
+
      orient = orientation,
- 715 + 730 1x -
      orient = "landscape",
+
      width = 8.27, height = 11.69
- - 716 - 1x + + 731 + -
      width = 8.5, height = 11
+
    )
- 717 + 732 -
    ),
+
  }
+ + + + 733 + + +

+                    
+                  
+                  
+                    734
+                    
+                    
+                      
  # Final output
- 718 - 1x + 735 + 3x + +
  officer::prop_section(
+ + + + 736 + 3x + +
    page_size = page_size,
+ + + + 737 + 3x
    type = "continuous",
- 719 - 1x + 738 + 3x -
    page_margins = margins_landscape()
+
    page_margins = margins_potrait()
- 720 + 739
  )
- 721 + 740
}
- 722 + 741

                     
                   
                   
-                    723
+                    742
                     
                     
                       
#' @describeIn export_as_docx Helper function that defines standard portrait margins for tables.
- 724 + 743
#' @export
- 725 + 744
margins_potrait <- function() {
- 726 - 2x + 745 + 3x
  officer::page_mar(bottom = 0.98, top = 0.95, left = 1.5, right = 1, gutter = 0)
- 727 + 746
}
- 728 + 747
#' @describeIn export_as_docx Helper function that defines standard landscape margins for tables.
- 729 + 748
#' @export
- 730 + 749
margins_landscape <- function() {
- - 731 - 1x + + 750 + !
  officer::page_mar(bottom = 1, top = 1.5, left = 0.98, right = 0.95, gutter = 0)
- 732 + 751
}
- 733 + 752

                     
                   
                   
-                    734
+                    753
                     
                     
                       
#' Create a `flextable` from an `rtables` table
- 735 + 754
#'
- 736 + 755
#' Principally used for export ([export_as_docx()]), this function produces a `flextable`
- 737 + 756
#' from an `rtables` table. If `theme = NULL`, `rtables`-like style will be used. Otherwise,
- 738 + 757
#' [theme_docx_default()] will produce a `.docx`-friendly table.
- 739 + 758
#'
- 740 + 759
#' @inheritParams gen_args
- 741 + 760
#' @inheritParams paginate_table
- 742 + 761
#' @param theme (`function` or `NULL`)\cr A theme function that is designed internally as a function of a `flextable`
- 743 + 762
#'   object to change its layout and style. If `NULL`, it will produce a table similar to `rtables` default. Defaults
- 744 + 763 -
#'   to `theme_docx_default(tt)`.
+
#'   to `theme_docx_default()`. See details for more information.
- 745 + 764
#' @param border (`officer` border object)\cr defaults to `officer::fp_border(width = 0.5)`.
- 746 + 765 -
#' @param indent_size (`integer(1)`)\cr if `NULL`, the default indent size of the table (see [formatters::matrix_form()]
+
#' @param indent_size (`numeric(1)`)\cr if `NULL`, the default indent size of the table (see [formatters::matrix_form()]
- 747 + 766 -
#'   `indent_size`) is used. To work with `docx`, any size is multiplied by 2 mm (5.67 pt) by default.
+
#'   `indent_size`, default is 2) is used. To work with `docx`, any size is multiplied by 1 mm (2.83 pt) by default.
- 748 + 767
#' @param titles_as_header (`flag`)\cr defaults to `TRUE` for [tt_to_flextable()], so the table is self-contained
- 749 + 768
#'   as it makes additional header rows for [formatters::main_title()] string and [formatters::subtitles()] character
- 750 + 769
#'   vector (one per element). `FALSE` is suggested for [export_as_docx()]. This adds titles and subtitles as a text
- 751 + 770
#'   paragraph above the table. The same style is applied.
- 752 + 771
#' @param footers_as_text (`flag`)\cr defaults to `FALSE` for [tt_to_flextable()], so the table is self-contained with
- 753 + 772
#'   the `flextable` definition of footnotes. `TRUE` is used for [export_as_docx()] to add the footers as a new
- 754 + 773
#'   paragraph after the table. The same style is applied, but with a smaller font.
- 755 + 774
#' @param counts_in_newline (`flag`)\cr defaults to `FALSE`. In `rtables` text printing ([formatters::toString()]),
- 756 + 775
#'   the column counts, i.e. `(N=xx)`, are always on a new line. For `docx` exports it could be necessary to print it
- 757 + 776
#'   on the same line.
- 758 + 777
#' @param paginate (`flag`)\cr when exporting `.docx` documents using `export_as_docx`, we suggest relying on the
- 759 + 778
#'   Microsoft Word pagination system. If `TRUE`, this option splits `tt` into different "pages" as multiple
- 760 + 779
#'   `flextables`. Cooperation between the two mechanisms is not guaranteed. Defaults to `FALSE`.
- 761 + 780
#' @param total_width (`numeric(1)`)\cr total width (in inches) for the resulting flextable(s). Defaults to 10.
- 762 + 781
#'
- 763 + 782
#' @return A `flextable` object.
- 764 + 783
#'
- 765 + 784 + + +
#' @details
+ + + + 785 + + +
#' It is possible to use some hidden values for building your own theme. In particular, `tt_to_flextable`
+ + + + 786 + + +
#' sends in the following variables `tbl_ncol_body = NCOL(tt)` and `tbl_row_class = make_row_df(tt)$node_class`.
+ + + + 787 + + +
#' These are ignored if not used in the theme. See `theme_docx_default` for an example on own to retrieve
+ + + + 788 + + +
#' these values and how to use them.
+ + + + 789 + + +
#'
+ + + + 790 + + +
#'
+ + + + 791
#' @seealso [export_as_docx()]
- 766 + 792
#'
- 767 + 793
#' @examples
- 768 + 794
#' analysisfun <- function(x, ...) {
- 769 + 795
#'   in_rows(
- 770 + 796
#'     row1 = 5,
- 771 + 797
#'     row2 = c(1, 2),
- 772 + 798
#'     .row_footnotes = list(row1 = "row 1 - row footnote"),
- 773 + 799
#'     .cell_footnotes = list(row2 = "row 2 - cell footnote")
- 774 + 800
#'   )
- 775 + 801
#' }
- 776 + 802
#'
- 777 + 803
#' lyt <- basic_table(
- 778 + 804
#'   title = "Title says Whaaaat", subtitles = "Oh, ok.",
- 779 + 805
#'   main_footer = "ha HA! Footer!"
- 780 + 806
#' ) %>%
- 781 + 807
#'   split_cols_by("ARM") %>%
- 782 + 808
#'   analyze("AGE", afun = analysisfun)
- 783 + 809
#'
- 784 + 810
#' tbl <- build_table(lyt, ex_adsl)
- 785 + 811
#' # rtables style
- 786 + 812
#' tt_to_flextable(tbl, theme = NULL)
- 787 + 813
#'
- 788 + 814 -
#' tt_to_flextable(tbl, theme = theme_docx_default(tbl, font_size = 7))
+
#' tt_to_flextable(tbl, theme = theme_docx_default(font_size = 6))
- 789 + 815
#'
- 790 + 816
#' @export
- 791 + 817
tt_to_flextable <- function(tt,
- 792 + 818 -
                            theme = theme_docx_default(tt),
+
                            theme = theme_docx_default(),
- 793 + 819
                            border = flextable::fp_border_default(width = 0.5),
- 794 + 820
                            indent_size = NULL,
- 795 + 821
                            titles_as_header = TRUE,
- 796 + 822
                            footers_as_text = FALSE,
- 797 + 823
                            counts_in_newline = FALSE,
- 798 + 824
                            paginate = FALSE,
- 799 + 825
                            lpp = NULL,
- 800 + 826
                            cpp = NULL,
- 801 + 827
                            ...,
- 802 + 828
                            colwidths = propose_column_widths(matrix_form(tt, indent_rownames = TRUE)),
- 803 + 829
                            tf_wrap = !is.null(cpp),
- 804 + 830
                            max_width = cpp,
- 805 + 831
                            total_width = 10) {
- 806 + 832 13x
  check_required_packages("flextable")
- 807 + 833 13x
  if (!inherits(tt, "VTableTree")) {
- 808 + 834 !
    stop("Input table is not an rtables' object.")
- 809 + 835
  }
- 810 + 836 13x
  checkmate::assert_flag(titles_as_header)
- 811 + 837 13x
  checkmate::assert_flag(footers_as_text)
- 812 + 838 13x
  checkmate::assert_flag(counts_in_newline)
+ + 839 + 13x + +
  left_right_fixed_margins <- word_mm_to_pt(1.9)
+ + - 813 + 840

                     
                   
                   
-                    814
+                    841
                     
                     
                       
  ## if we're paginating, just call -> pagination happens also afterwards if needed
- 815 + 842 13x
  if (paginate) {
- 816 + 843 1x
    if (is.null(lpp)) {
- 817 + 844 !
      stop("lpp must be specified when calling tt_to_flextable with paginate=TRUE")
- 818 + 845
    }
- 819 + 846 1x
    tabs <- paginate_table(tt, lpp = lpp, cpp = cpp, tf_wrap = tf_wrap, max_width = max_width, ...)
- 820 + 847 1x
    cinds <- lapply(tabs, function(tb) c(1, .figure_out_colinds(tb, tt) + 1L))
- 821 + 848 1x
    return(mapply(tt_to_flextable,
- 822 + 849 1x
      tt = tabs, colwidths = cinds,
- 823 + 850 1x
      MoreArgs = list(paginate = FALSE, total_width = total_width),
- 824 + 851 1x
      SIMPLIFY = FALSE
- 825 + 852
    ))
- 826 + 853
  }
- 827 + 854

                     
                   
                   
-                    828
+                    855
                     
                     
                       
  # Calculate the needed colwidths
- 829 + 856 12x
  final_cwidths <- total_width * colwidths / sum(colwidths) # xxx to fix
- 830 + 857
  # xxx FIXME missing transformer from character based widths to mm or pt
- 831 + 858

                     
                   
                   
-                    832
+                    859
                     
                     
                       
  # Extract relevant information
- 833 + 860 12x -
  matform <- matrix_form(tt, indent_rownames = TRUE)
+
  matform <- matrix_form(tt, indent_rownames = FALSE)
- 834 + 861 12x
  body <- mf_strings(matform) # Contains header
- 835 + 862 12x
  spans <- mf_spans(matform) # Contains header
- 836 + 863 12x
  mpf_aligns <- mf_aligns(matform) # Contains header
- 837 + 864 12x
  hnum <- mf_nlheader(matform) # Number of lines for the header
- 838 + 865 12x
  rdf <- make_row_df(tt) # Row-wise info
- 839 + 866

                     
                   
                   
-                    840
+                    867
                     
                     
                       
  # decimal alignment pre-proc
- 841 + 868 12x
  if (any(grepl("dec", mpf_aligns))) {
- 842 + 869 !
    body <- decimal_align(body, mpf_aligns)
- 843 + 870
    # Coercion for flextable
- 844 + 871 !
    mpf_aligns[mpf_aligns == "decimal"] <- "center"
- 845 + 872 !
    mpf_aligns[mpf_aligns == "dec_left"] <- "left"
- 846 + 873 !
    mpf_aligns[mpf_aligns == "dec_right"] <- "right"
- 847 + 874
  }
- 848 + 875

                     
                   
                   
-                    849
+                    876
                     
                     
                       
  # Fundamental content of the table
- 850 + 877 12x
  content <- as.data.frame(body[-seq_len(hnum), , drop = FALSE])
- 851 + 878 12x
  flx <- flextable::qflextable(content) %>%
- 852 + 879
    # Default rtables if no footnotes
- 853 + 880 12x
    remove_hborder(part = "body", w = "bottom")
- 854 + 881

                     
                   
                   
-                    855
+                    882
                     
                     
                       
  # Header addition -> NB: here we have a problem with (N=xx)
- 856 + 883 12x
  hdr <- body[seq_len(hnum), , drop = FALSE]
- 857 + 884

                     
                   
                   
-                    858
+                    885
                     
                     
                       
  # XXX NOT NECESSARY change of (N=xx) which is by default on a new line but we do not
- 859 + 886
  # want this in docx, and it depends on the size of the table, it is not another
- 860 + 887
  # row with different columns -> All of this should be fixed at source (in matrix_form)
- 861 + 888
  # See .tbl_header_mat for this change
- 862 + 889 12x
  if (hnum > 1) { # otherwise nothing to do
- 863 + 890 12x
    det_nclab <- apply(hdr, 2, grepl, pattern = "\\(N=[0-9]+\\)$")
- 864 + 891 12x
    has_nclab <- apply(det_nclab, 1, any)
- 865 + 892 12x
    whsnc <- which(has_nclab) # which rows have it -> more than one is not supported
- 866 + 893 12x
    if (isFALSE(counts_in_newline) && any(has_nclab) && length(whsnc) == 1L) {
- 867 + 894 5x
      what_is_nclab <- det_nclab[whsnc, ]
- 868 + 895

                     
                   
                   
-                    869
+                    896
                     
                     
                       
      # condition for popping the interested row by merging the upper one
- 870 + 897 5x
      hdr[whsnc, what_is_nclab] <- paste(hdr[whsnc - 1, what_is_nclab],
- 871 + 898 5x
        hdr[whsnc, what_is_nclab],
- 872 + 899 5x
        sep = " "
- 873 + 900
      )
- 874 + 901 5x
      hdr[whsnc - 1, what_is_nclab] <- ""
- 875 + 902

                     
                   
                   
-                    876
+                    903
                     
                     
                       
      # We can remove the row if they are all ""
- 877 + 904 5x
      row_to_pop <- whsnc - 1
- 878 + 905 5x
      if (all(!nzchar(hdr[row_to_pop, ]))) {
- 879 + 906 4x
        hdr <- hdr[-row_to_pop, , drop = FALSE]
- 880 + 907 4x
        spans <- spans[-row_to_pop, , drop = FALSE]
- 881 + 908 4x
        body <- body[-row_to_pop, , drop = FALSE]
- 882 + 909 4x
        mpf_aligns <- mpf_aligns[-row_to_pop, , drop = FALSE]
- 883 + 910 4x
        hnum <- hnum - 1
- 884 + 911
      }
- 885 + 912
    }
- 886 + 913
  }
- 887 + 914

                     
                   
                   
-                    888
+                    915
                     12x
                     
                       
  flx <- flx %>%
- 889 + 916 12x
    flextable::set_header_labels( # Needed bc headers must be unique
- 890 + 917 12x
      values = setNames(
- 891 + 918 12x
        as.vector(hdr[hnum, , drop = TRUE]),
- 892 + 919 12x
        names(content)
- 893 + 920
      )
- 894 + 921
    )
- 895 + 922
  # If there are more rows
- 896 + 923 12x
  if (hnum > 1) {
- 897 + 924 11x
    for (i in seq(hnum - 1, 1)) {
- 898 + 925 11x
      sel <- spans_to_viscell(spans[i, ])
- 899 + 926 11x
      flx <- flextable::add_header_row(
- 900 + 927 11x
        flx,
- 901 + 928 11x
        top = TRUE,
- 902 + 929 11x
        values = as.vector(hdr[i, sel]),
- 903 + 930 11x
        colwidths = as.integer(spans[i, sel]) # xxx to fix
- 904 + 931
      )
- 905 + 932
    }
- 906 + 933
  }
- 907 + 934

                     
                   
                   
-                    908
+                    935
+                    
+                    
+                      
  # Re-set the number of row count
+ + + + 936 + 12x + +
  nr_body <- flextable::nrow_part(flx, part = "body")
+ + + + 937 + 12x + +
  nr_header <- flextable::nrow_part(flx, part = "header")
+ + + + 938 + + +

+                    
+                  
+                  
+                    939
                     
                     
                       
  # Polish the inner horizontal borders from the header
- 909 + 940 12x
  flx <- flx %>%
- 910 + 941 12x
    remove_hborder(part = "header", w = "all") %>%
- 911 + 942 12x
    add_hborder("header", ii = c(0, hnum), border = border)
- 912 + 943

                     
                   
                   
-                    913
+                    944
                     
                     
                       
  # ALIGNS
- 914 + 945 12x
  flx <- flx %>%
- 915 + 946 12x
    apply_alignments(mpf_aligns[seq_len(hnum), , drop = FALSE], "header") %>%
- 916 + 947 12x
    apply_alignments(mpf_aligns[-seq_len(hnum), , drop = FALSE], "body")
- 917 + 948

                     
                   
                   
-                    918
+                    949
                     
                     
                       
  # Rownames indentation
- 919 + 950 12x -
  checkmate::check_int(indent_size, null.ok = TRUE)
+
  checkmate::check_number(indent_size, null.ok = TRUE)
- 920 + 951 12x
  if (is.null(indent_size)) {
+ + 952 + + +
    # Default indent_size in {rtables} is 2 characters
+ + - 921 + 953 12x -
    indent_size <- matform$indent_size * word_mm_to_pt(2) # default is 2mm (5.7pt)
+
    indent_size <- matform$indent_size * word_mm_to_pt(1) # default is 2mm (5.7pt)
- 922 + 954 + + +
  } else {
+ + + + 955 + ! + +
    indent_size <- indent_size * word_mm_to_pt(1)
+ + + + 956
  }
+ + 957 + + +

+                    
+                  
+                  
+                    958
+                    
+                    
+                      
  # rdf contains information about indentation
+ + - 923 + 959 12x -
  for (i in seq_len(NROW(tt))) {
+
  for (i in seq_len(nr_body)) {
- 924 + 960 229x
    flx <- flextable::padding(flx,
- 925 + 961 229x
      i = i, j = 1,
- 926 + 962 229x -
      padding.left = indent_size * rdf$indent[[i]] + word_mm_to_pt(0.1), # 0.1 mmm in pt
+
      padding.left = indent_size * rdf$indent[[i]] + left_right_fixed_margins, # margins
- 927 + 963 + 229x + +
      padding.right = left_right_fixed_margins, # 0.19 mmm in pt (so not to touch the border)
+ + + + 964 229x -
      padding.right = word_mm_to_pt(0.1) # 0.1 mmm in pt (so not to touch the border)
+
      part = "body"
- 928 + 965
    )
- 929 + 966
  }
- 930 + 967

                     
                   
                   
-                    931
+                    968
                     
                     
-                      
  # Adding referantial footer line separator if present
+
  # TOPLEFT
+ + + + 969 + + +
  # Principally used for topleft indentation, this is a bit of a hack xxx
- 932 + 970 12x -
  if (length(matform$ref_footnotes) > 0 && isFALSE(footers_as_text)) {
+
  for (i in seq_len(nr_header)) {
- 933 - 7x + 971 + 23x -
    flx <- flextable::add_footer_lines(flx, values = matform$ref_footnotes) %>%
+
    leading_spaces_count <- nchar(hdr[i, 1]) - nchar(stringi::stri_replace(hdr[i, 1], regex = "^ +", ""))
- 934 - 7x + 972 + 23x -
      add_hborder(part = "body", ii = nrow(tt), border = border)
+
    header_indent_size <- leading_spaces_count * word_mm_to_pt(1)
- - 935 - + + 973 + 23x -
  }
+
    flx <- flextable::padding(flx,
- - 936 - + + 974 + 23x -

+                      
      i = i, j = 1,
+ + + + 975 + 23x + +
      padding.left = header_indent_size + left_right_fixed_margins, # margins
+ + + + 976 + 23x + +
      padding.right = left_right_fixed_margins, # 0.19 mmm in pt (so not to touch the border)
+ + + + 977 + 23x + +
      part = "header"
- 937 + 978 + + +
    )
+ + + + 979 + + +
  }
+ + + + 980 + + +
  # topleft styling (-> bottom aligned) xxx merge_at() could merge these, but let's see
+ + + + 981 + 12x + +
  flx <- flextable::valign(flx, j = 1, valign = "bottom", part = "header")
+ + + + 982 + + +

+                    
+                  
+                  
+                    983
+                    
+                    
+                      
  # Adding referantial footer line separator if present
+ + + + 984 + 12x + +
  if (length(matform$ref_footnotes) > 0 && isFALSE(footers_as_text)) {
+ + + + 985 + 7x + +
    flx <- flextable::add_footer_lines(flx, values = matform$ref_footnotes) %>%
+ + + + 986 + 7x + +
      add_hborder(part = "body", ii = nrow(tt), border = border)
+ + + + 987 + + +
  }
+ + + + 988 + + +

+                    
+                  
+                  
+                    989
                     
                     
                       
  # Footer lines
- 938 + 990 12x
  if (length(all_footers(tt)) > 0 && isFALSE(footers_as_text)) {
- 939 + 991 1x
    flx <- flextable::add_footer_lines(flx, values = all_footers(tt))
- 940 + 992
  }
- 941 + 993

                     
                   
                   
-                    942
+                    994
                     12x
                     
                       
  flx <- flextable::width(flx, width = final_cwidths) # xxx to fix
- 943 + 995

                     
                   
                   
-                    944
+                    996
                     12x
                     
                       
  if (!is.null(theme)) {
- 945 + 997 11x -
    flx <- theme(flx)
+
    flx <- theme(
+ + + + 998 + 11x + +
      flx,
+ + + + 999 + 11x + +
      tbl_ncol_body = flextable::ncol_keys(flx), # NCOL(tt) + 1, # +1 for rownames
+ + + + 1000 + 11x + +
      tbl_row_class = make_row_df(tt)$node_class # These are ignored if not in the theme
- 946 + 1001 + + +
    )
+ + + + 1002
  }
- 947 + 1003

                     
                   
                   
-                    948
+                    1004
                     
                     
                       
  # Title lines (after theme for problems with lines)
- 949 + 1005 11x
  if (titles_as_header && length(all_titles(tt)) > 0 && any(nzchar(all_titles(tt)))) {
- 950 + 1006 1x
    real_titles <- all_titles(tt)
- 951 + 1007 1x
    real_titles <- real_titles[nzchar(real_titles)]
- 952 + 1008 1x
    flx <- flextable::add_header_lines(flx, values = real_titles, top = TRUE) %>%
- 953 + 1009
      # Remove the added borders
- 954 + 1010 1x
      remove_hborder(part = "header", w = c("inner", "top")) %>%
- 955 + 1011
      # Re-add the separator between titles and real headers
- 956 + 1012 1x
      add_hborder(
- 957 + 1013 1x
        part = "header", ii = length(real_titles),
- 958 + 1014 1x
        border = border
- 959 + 1015
      ) %>%
- 960 + 1016
      # Remove vertical borders added by theme eventually
- 961 + 1017 1x
      remove_vborder(part = "header", ii = seq_along(real_titles))
- 962 + 1018
  }
- 963 + 1019

                     
                   
                   
-                    964
+                    1020
                     
                     
                       
  # These final formatting need to work with colwidths
- 965 + 1021 11x
  flx <- flextable::set_table_properties(flx, layout = "autofit", align = "left") # xxx to fix
- 966 + 1022
  # NB: autofit or fixed may be switched if widths are correctly staying in the page
- 967 + 1023 11x
  flx <- flextable::fix_border_issues(flx) # Fixes some rendering gaps in borders
- 968 + 1024

                     
                   
                   
-                    969
+                    1025
                     11x
                     
                       
  flx
- 970 + 1026
}
- 971 + 1027

                     
                   
                   
-                    972
+                    1028
                     
                     
                       
#' @describeIn tt_to_flextable Main theme function for [export_as_docx()]
- 973 + 1029
#'
- 974 + 1030 -
#' @inheritParams export_as_docx
+
#' @param font (`string`)\cr defaults to `"Arial"`. If the font is not available, `flextable` default is used.
- 975 + 1031 -
#' @param font (`string`)\cr defaults to `"Arial"`. If the font is not available, `flextable` default is used.
+
#' @param font_size (`integer(1)`)\cr font size. Defaults to 9.
- 976 + 1032 -
#' @param font_size (`integer(1)`)\cr font size. Defaults to 9.
+
#' @param cell_margins (`numeric(1)` or `numeric(4)`)\cr a numeric or a vector of four numbers indicating
- 977 + 1033 + + +
#'   `c("left", "right", "top", "bottom")`. It defaults to 0 for top and bottom, and to 0.19 `mm` in word `pt`
+ + + + 1034 + + +
#'   for left and right.
+ + + + 1035
#' @param bold (`character`)\cr parts of the table text that should be in bold. Can be any combination of
- 978 + 1036
#'   `c("header", "content_rows", "label_rows")`. The first one renders all column names bold (not `topleft` content).
- 979 + 1037
#'   The second and third option use [formatters::make_row_df()] to render content or/and label rows as bold.
- 980 + 1038
#' @param bold_manual (named `list` or `NULL`)\cr list of index lists. See example for needed structure. Accepted
- 981 + 1039
#'   groupings/names are `c("header", "body")`.
- 982 + 1040 + + +
#' @param border (`flextable::fp_border()`)\cr border style. Defaults to `flextable::fp_border_default(width = 0.5)`.
+ + + + 1041
#'
- 983 + 1042
#' @seealso [export_as_docx()]
- 984 + 1043
#'
- 985 + 1044
#' @examples
- 986 + 1045
#' # Custom theme
- 987 + 1046
#' special_bold <- list(
- 988 + 1047
#'   "header" = list("i" = 1, "j" = c(1, 3)),
- 989 + 1048
#'   "body" = list("i" = c(1, 2), "j" = 1)
- 990 + 1049
#' )
- 991 + 1050 -
#' custom_theme <- theme_docx_default(tbl,
+
#' custom_theme <- theme_docx_default(
- 992 + 1051
#'   font_size = 10,
- 993 + 1052
#'   font = "Brush Script MT",
- 994 + 1053
#'   border = flextable::fp_border_default(color = "pink", width = 2),
- 995 + 1054
#'   bold = NULL,
- 996 + 1055
#'   bold_manual = special_bold
- 997 + 1056
#' )
- 998 + 1057
#' tt_to_flextable(tbl,
- 999 + 1058
#'   border = flextable::fp_border_default(color = "pink", width = 2),
- 1000 + 1059
#'   theme = custom_theme
- 1001 + 1060
#' )
- 1002 + 1061
#'
- 1003 + 1062
#' @export
- 1004 + 1063 -
theme_docx_default <- function(tt = NULL, # Option for more complicated stuff
+
theme_docx_default <- function(font = "Arial",
- 1005 + 1064 -
                               font = "Arial",
+
                               font_size = 9,
- 1006 + 1065 -
                               font_size = 9,
+
                               cell_margins = c(
- 1007 + 1066 + + +
                                 word_mm_to_pt(1.9),
+ + + + 1067 + + +
                                 word_mm_to_pt(1.9),
+ + + + 1068 + + +
                                 0,
+ + + + 1069 + + +
                                 0
+ + + + 1070 + + +
                               ), # Default in docx
+ + + + 1071
                               bold = c("header", "content_rows", "label_rows"),
- 1008 + 1072
                               bold_manual = NULL,
- 1009 + 1073
                               border = flextable::fp_border_default(width = 0.5)) {
- 1010 + 1074 11x -
  function(flx) {
+
  function(flx, ...) {
- 1011 + 1075 11x
    check_required_packages("flextable")
- 1012 + 1076 11x
    if (!inherits(flx, "flextable")) {
- 1013 + 1077 !
      stop(sprintf(
- 1014 + 1078 !
        "Function `%s` supports only flextable objects.",
- 1015 + 1079 !
        "theme_box()"
- 1016 + 1080
      ))
- 1017 + 1081
    }
- 1018 + 1082 + 11x + +
    checkmate::assert_int(font_size, lower = 6, upper = 12)
+ + + + 1083 + 11x + +
    checkmate::assert_string(font)
+ + + + 1084 + 11x + +
    checkmate::assert_subset(bold,
+ + + + 1085 + 11x + +
      eval(formals(theme_docx_default)$bold),
+ + + + 1086 + 11x + +
      empty.ok = TRUE
+ + + + 1087 + + +
    )
+ + + + 1088 11x -
    if (!is.null(tt) && !inherits(tt, "VTableTree")) {
+
    if (length(cell_margins) == 1) {
- 1019 + 1089 ! -
      stop("Input table is not an rtables' object.")
+
      cell_margins <- rep(cell_margins, 4)
- 1020 + 1090
    }
- 1021 + 1091 11x -
    checkmate::assert_int(font_size, lower = 1)
+
    checkmate::assert_numeric(cell_margins, lower = 0, len = 4)
+ + + + 1092 + + +

+                    
+                  
+                  
+                    1093
+                    
+                    
+                      
    # Setting values coming from ...
- 1022 + 1094 11x -
    checkmate::assert_string(font)
+
    args <- list(...)
- 1023 + 1095 11x -
    checkmate::assert_subset(bold,
+
    tbl_row_class <- args$tbl_row_class # This is internal info
- 1024 + 1096 11x -
      eval(formals(theme_docx_default)$bold),
+
    tbl_ncol_body <- args$tbl_ncol_body # This is internal info
- 1025 + 1097 11x -
      empty.ok = TRUE
+
    if (is.null(tbl_ncol_body)) {
+ + + + 1098 + ! + +
      tbl_ncol_body <- flextable::ncol_keys(flx) # tbl_ncol_body respects if rownames = FALSE
- 1026 + 1099 -
    )
+
    }
- 1027 + 1100

                     
                   
                   
-                    1028
+                    1101
                     
                     
                       
    # Font setting
- 1029 + 1102 11x
    flx <- flextable::fontsize(flx, size = font_size, part = "all") %>%
- 1030 + 1103 11x
      flextable::fontsize(size = font_size - 1, part = "footer") %>%
- 1031 + 1104 11x
      flextable::font(fontname = font, part = "all")
- 1032 + 1105

                     
                   
                   
-                    1033
+                    1106
                     
                     
                       
    # Vertical borders
- 1034 + 1107 11x
    flx <- flx %>%
- 1035 + 1108 11x
      flextable::border_outer(part = "body", border = border) %>%
- 1036 + 1109 11x -
      flextable::border_outer(part = "header", border = border)
+
      flextable::border_outer(part = "header", border = border) %>%
+ + + + 1110 + 11x + +
      flextable::border_inner(part = "header", border = border) # xxx
- 1037 + 1111

                     
                   
                   
-                    1038
+                    1112
                     
                     
-                      
    # Vertical alignment -> all top for now, we will set it for the future
+
    # Vertical alignment -> all top for now
- 1039 + 1113 11x
    flx <- flx %>%
- 1040 + 1114 11x -
      flextable::valign(j = 2:(NCOL(tt) + 1), valign = "top", part = "body") %>%
+
      flextable::valign(j = seq(2, tbl_ncol_body), valign = "top", part = "body") %>%
- 1041 + 1115 11x
      flextable::valign(j = 1, valign = "top", part = "body") %>%
- 1042 + 1116 11x -
      flextable::valign(j = 2:(NCOL(tt) + 1), valign = "top", part = "header")
+
      flextable::valign(j = seq(2, tbl_ncol_body), valign = "top", part = "header")
- 1043 + 1117

                     
                   
                   
-                    1044
+                    1118
+                    
+                    
+                      
    # Vertical padding/spaces - rownames
+ + + + 1119 + 11x + +
    flx <- flx %>% # summary/data rows and cells
+ + + + 1120 + 11x + +
      flextable::padding(padding.top = cell_margins[3], padding.bottom = cell_margins[4], part = "body")
+ + + + 1121 + 11x + +
    if (any(tbl_row_class == "LabelRow")) { # label rows - 3pt top
+ + + + 1122 + 11x + +
      flx <- flextable::padding(flx,
+ + + + 1123 + 11x + +
        j = 1, i = which(tbl_row_class == "LabelRow"),
+ + + + 1124 + 11x + +
        padding.top = 3 + cell_margins[3], padding.bottom = cell_margins[4], part = "body"
+ + + + 1125 + + +
      )
+ + + + 1126 + + +
    }
+ + + + 1127 + 11x + +
    if (any(tbl_row_class == "ContentRow")) { # content rows - 1pt top
+ + + + 1128 + 8x + +
      flx <- flextable::padding(flx,
+ + + + 1129 + + +
        # j = 1, # removed because I suppose we want alignment with body
+ + + + 1130 + 8x + +
        i = which(tbl_row_class == "ContentRow"),
+ + + + 1131 + 8x + +
        padding.top = 1 + cell_margins[3], padding.bottom = cell_margins[4], part = "body"
+ + + + 1132 + + +
      )
+ + + + 1133 + + +
    }
+ + + + 1134 + + +

+                    
+                  
+                  
+                    1135
+                    
+                    
+                      
    # Horizontal padding all table margin 0.19 mm
+ + + + 1136 + 11x + +
    flx <- flextable::padding(flx,
+ + + + 1137 + 11x + +
      j = seq(2, tbl_ncol_body),
+ + + + 1138 + 11x + +
      padding.left = cell_margins[1],
+ + + + 1139 + 11x + +
      padding.right = cell_margins[2]
+ + + + 1140 + + +
    )
+ + + + 1141 + + +

+                    
+                  
+                  
+                    1142
+                    
+                    
+                      
    # Vertical padding/spaces - header (3pt after)
+ + + + 1143 + 11x + +
    flx <- flx %>%
+ + + + 1144 + 11x + +
      flextable::padding(
+ + + + 1145 + 11x + +
        j = seq(2, tbl_ncol_body),
+ + + + 1146 + 11x + +
        padding.top = cell_margins[3],
+ + + + 1147 + 11x + +
        padding.bottom = cell_margins[4],
+ + + + 1148 + 11x + +
        part = "header"
+ + + + 1149 + + +
      )
+ + + + 1150 + + +

+                    
+                  
+                  
+                    1151
+                    
+                    
+                      
    # single line spacing (for safety) -> space = 1
+ + + + 1152 + 11x + +
    flx <- flextable::line_spacing(flx, space = 1, part = "all")
+ + + + 1153 + + +

+                    
+                  
+                  
+                    1154
                     
                     
                       
    # Bold settings
- 1045 + 1155 11x
    if (any(bold == "header")) {
- 1046 + 1156 9x -
      flx <- flextable::bold(flx, j = 2:(NCOL(tt) + 1), part = "header") # Done with theme
+
      flx <- flextable::bold(flx, j = seq(2, tbl_ncol_body), part = "header") # Done with theme
- 1047 + 1157
    }
- 1048 + 1158
    # Content rows are effectively our labels in row names
- 1049 + 1159 11x
    if (any(bold == "content_rows")) {
- - 1050 - ! + + 1160 + 9x -
      if (is.null(tt)) stop('bold = "content_rows" needs the original rtables object (tt).')
+
      if (is.null(tbl_row_class)) {
- - 1051 - 9x + + 1161 + ! -
      rdf <- make_row_df(tt)
+
        stop('bold = "content_rows" needs tbl_row_class = make_row_df(tt).')
- - 1052 - 9x + + 1162 + -
      which_body <- which(rdf$node_class == "ContentRow")
+
      }
- 1053 + 1163 9x -
      flx <- flextable::bold(flx, j = 1, i = which_body, part = "body")
+
      flx <- flextable::bold(flx, j = 1, i = which(tbl_row_class == "ContentRow"), part = "body")
- 1054 + 1164
    }
- 1055 + 1165 11x
    if (any(bold == "label_rows")) {
+ + 1166 + 9x + +
      if (is.null(tbl_row_class)) {
+ + - 1056 + 1167 ! -
      if (is.null(tt)) stop('bold = "content_rows" needs the original rtables object (tt).')
+
        stop('bold = "content_rows" needs tbl_row_class = make_row_df(tt).')
+ + + + 1168 + + +
      }
- 1057 + 1169 9x -
      rdf <- make_row_df(tt)
+
      flx <- flextable::bold(flx, j = 1, i = which(tbl_row_class == "LabelRow"), part = "body")
+ + + + 1170 + + +
    }
+ + + + 1171 + + +
    # topleft information is also bold if content or label rows are bold
- 1058 - 9x + 1172 + 11x -
      which_body <- which(rdf$node_class == "LabelRow")
+
    if (any(bold %in% c("content_rows", "label_rows"))) {
- 1059 + 1173 9x -
      flx <- flextable::bold(flx, j = 1, i = which_body, part = "body")
+
      flx <- flextable::bold(flx, j = 1, part = "header")
- 1060 + 1174
    }
- 1061 + 1175 + + +

+                    
+                  
+                  
+                    1176
                     
                     
                       
    # If you want specific cells to be bold
- 1062 + 1177 11x
    if (!is.null(bold_manual)) {
- 1063 + 1178 2x
      checkmate::assert_list(bold_manual)
- 1064 + 1179 2x
      valid_sections <- c("header", "body") # Only valid values
- 1065 + 1180 2x
      checkmate::assert_subset(names(bold_manual), valid_sections)
- 1066 + 1181 2x
      for (bi in seq_along(bold_manual)) {
- 1067 + 1182 3x
        bld_tmp <- bold_manual[[bi]]
- 1068 + 1183 3x
        checkmate::assert_list(bld_tmp)
- 1069 + 1184 3x
        if (!all(c("i", "j") %in% names(bld_tmp)) || !all(vapply(bld_tmp, checkmate::test_integerish, logical(1)))) {
- 1070 + 1185 1x
          stop(
- 1071 + 1186 1x
            "Found an allowed section for manual bold (", names(bold_manual)[bi],
- 1072 + 1187 1x
            ") that was not a named list with i (row) and j (col) integer vectors."
- 1073 + 1188
          )
- 1074 + 1189
        }
- 1075 + 1190 2x
        flx <- flextable::bold(flx,
- 1076 + 1191 2x
          i = bld_tmp$i, j = bld_tmp$j,
- 1077 + 1192 2x
          part = names(bold_manual)[bi]
- 1078 + 1193
        )
- 1079 + 1194
      }
- 1080 + 1195
    }
- 1081 + 1196

                     
                   
-                  
-                    1082
-                    
-                    
-                      
    # vertical padding is manual atm and respect doc std
- - - 1083 + 1197 10x -
    flx <- flx %>%
+
    flx
- 1084 + 1198 -
      # flextable::padding(j = 2:(NCOL(tt) + 1), padding.top = , part = "body") %>% # not specified
- - - - 1085 - 10x - -
      flextable::padding(j = 1, padding.top = 1, padding.bottom = 1, part = "body") %>%
+
  }
- - 1086 - 10x + + 1199 + -
      flextable::padding(j = 2:(NCOL(tt) + 1), padding.top = 0, padding.bottom = 3, part = "header")
+
}
- 1087 + 1200

                     
                   
                   
-                    1088
+                    1201
                     
                     
-                      
    # single line spacing (for safety) -> space = 1
- - - - 1089 - 10x - -
    flx <- flextable::line_spacing(flx, space = 1, part = "all")
+
#' @describeIn tt_to_flextable Padding helper functions to transform mm to pt.
- 1090 + 1202 -

-                    
-                  
-                  
-                    1091
-                    10x
-                    
-                      
    flx
+
#' @param mm (`numeric(1)`)\cr the value in mm to transform to pt.
- 1092 + 1203 -
  }
+
#'
- 1093 + 1204 -
}
+
#' @export
- 1094 + 1205 -

+                      
word_mm_to_pt <- function(mm) {
- - 1095 - + + 1206 + 70x -
# Padding helper functions to transform mm to pt and viceversa
+
  mm / 0.3527777778
- 1096 + 1207 -
# # General note for word: 1pt -> 0.3527777778mm -> 0.013888888888889"
+
}
- 1097 + 1208 -
word_inch_to_pt <- function(inch) { # nocov
+

                     
                   
                   
-                    1098
+                    1209
                     
                     
-                      
  inch / 0.013888888888889 # nocov
+
# Padding helper functions to transform mm to pt and viceversa
- 1099 + 1210 -
}
+
# # General note for word: 1pt -> 0.3527777778mm -> 0.013888888888889"
- 1100 + 1211 -

+                      
word_inch_to_pt <- function(inch) { # nocov
- 1101 + 1212 -
word_mm_to_pt <- function(mm) {
- - - - 1102 - 470x - -
  mm / 0.3527777778
+
  inch / 0.013888888888889 # nocov
- 1103 + 1213
}
- 1104 + 1214

                     
                   
                   
-                    1105
+                    1215
                     
                     
                       
# Polish horizontal borders
- 1106 + 1216
remove_hborder <- function(flx, part, w = c("top", "bottom", "inner")) {
- 1107 + 1217
  # If you need to remove all of them
- 1108 + 1218 25x
  if (length(w) == 1 && w == "all") {
- 1109 + 1219 12x
    w <- eval(formals(remove_hborder)$w)
- 1110 + 1220
  }
- 1111 + 1221

                     
                   
                   
-                    1112
+                    1222
                     25x
                     
                       
  if (any(w == "top")) {
- 1113 + 1223 13x
    flx <- flextable::hline_top(flx,
- 1114 + 1224 13x
      border = flextable::fp_border_default(width = 0),
- 1115 + 1225 13x
      part = part
- 1116 + 1226
    )
- 1117 + 1227
  }
- 1118 + 1228 25x
  if (any(w == "bottom")) {
- 1119 + 1229 24x
    flx <- flextable::hline_bottom(flx,
- 1120 + 1230 24x
      border = flextable::fp_border_default(width = 0),
- 1121 + 1231 24x
      part = part
- 1122 + 1232
    )
- 1123 + 1233
  }
- 1124 + 1234
  # Inner horizontal lines removal
- 1125 + 1235 25x
  if (any(w == "inner")) {
- 1126 + 1236 13x
    flx <- flextable::border_inner_h(
- 1127 + 1237 13x
      flx,
- 1128 + 1238 13x
      border = flextable::fp_border_default(width = 0),
- 1129 + 1239 13x
      part = part
- 1130 + 1240
    )
- 1131 + 1241
  }
- 1132 + 1242 25x
  flx
- 1133 + 1243
}
- 1134 + 1244

                     
                   
                   
-                    1135
+                    1245
                     
                     
                       
# Remove vertical borders from both sides (for titles)
- 1136 + 1246
remove_vborder <- function(flx, part, ii) {
- 1137 + 1247 1x
  flx <- flextable::border(flx,
- 1138 + 1248 1x
    i = ii, part = part,
- 1139 + 1249 1x
    border.left = flextable::fp_border_default(width = 0),
- 1140 + 1250 1x
    border.right = flextable::fp_border_default(width = 0)
- 1141 + 1251
  )
- 1142 + 1252
}
- 1143 + 1253

                     
                   
                   
-                    1144
+                    1254
                     
                     
                       
# Add horizontal border
- 1145 + 1255
add_hborder <- function(flx, part, ii, border) {
- 1146 + 1256 20x
  if (any(ii == 0)) {
- 1147 + 1257 12x
    flx <- flextable::border(flx, i = 1, border.top = border, part = part)
- 1148 + 1258 12x
    ii <- ii[!(ii == 0)]
- 1149 + 1259
  }
- 1150 + 1260 20x
  if (length(ii) > 0) {
- 1151 + 1261 20x
    flx <- flextable::border(flx, i = ii, border.bottom = border, part = part)
- 1152 + 1262
  }
- 1153 + 1263 20x
  flx
- 1154 + 1264
}
- 1155 + 1265

                     
                   
                   
-                    1156
+                    1266
                     
                     
                       
apply_alignments <- function(flx, aligns_df, part) {
- 1157 + 1267
  # List of characters you want to search for
- 1158 + 1268 24x
  search_chars <- unique(c(aligns_df))
- 1159 + 1269

                     
                   
                   
-                    1160
+                    1270
                     
                     
                       
  # Loop through each character and find its indexes
- 1161 + 1271 24x
  for (char in search_chars) {
- 1162 + 1272 48x
    indexes <- which(aligns_df == char, arr.ind = TRUE)
- 1163 + 1273 48x
    tmp_inds <- as.data.frame(indexes)
- 1164 + 1274 48x
    flx <- flx %>%
- 1165 + 1275 48x
      flextable::align(
- 1166 + 1276 48x
        i = tmp_inds[["row"]],
- 1167 + 1277 48x
        j = tmp_inds[["col"]],
- 1168 + 1278 48x
        align = char,
- 1169 + 1279 48x
        part = part
- 1170 + 1280
      )
- 1171 + 1281
  }
- 1172 + 1282

                     
                   
                   
-                    1173
+                    1283
                     24x
                     
                       
  flx
- 1174 + 1284
}
@@ -126090,14 +126860,14 @@

rtables coverage - 90.59%

269 - 248x + 236x
      body[, 1] <- indent_string(body[, 1], c(rep(0, nr_header), sr$indent),
270 - 248x + 236x
        incr = indent_size
@@ -126118,14 +126888,14 @@

rtables coverage - 90.59%

273 - 248x + 236x
      formats[, 1] <- indent_string(formats[, 1], c(rep(0, nr_header), sr$indent),
274 - 248x + 236x
        incr = indent_size
@@ -126139,14 +126909,14 @@

rtables coverage - 90.59%

276 - 75x + 87x
    } else if (NROW(sr) > 0) {
277 - 71x + 83x
      sr$indent <- rep(0, NROW(sr))
@@ -126769,7 +127539,7 @@

rtables coverage - 90.59%

366 - 3242x + 3230x
  if (!is(fn, "RefFootnote")) {
@@ -126790,21 +127560,21 @@

rtables coverage - 90.59%

369 - 3242x + 3230x
  ret <- ref_symbol(fn)
370 - 3242x + 3230x
  if (is.na(ret)) {
371 - 3242x + 3230x
    ret <- as.character(ref_index(fn))
@@ -126818,7 +127588,7 @@

rtables coverage - 90.59%

373 - 3242x + 3230x
  ret
@@ -126972,7 +127742,7 @@

rtables coverage - 90.59%

395 - 2691x + 2679x
  if (length(fn) == 0 || (is.list(fn) && all(vapply(fn, function(x) length(x) == 0, TRUE)))) {
@@ -126993,7 +127763,7 @@

rtables coverage - 90.59%

398 - 2691x + 2679x
  if (is.list(fn)) {
@@ -127021,14 +127791,14 @@

rtables coverage - 90.59%

402 - 2691x + 2679x
  if (is(fn, "RefFootnote")) {
403 - 2691x + 2679x
    paste0("{", .resolve_fn_symbol(fn), "} - ", ref_msg(fn))
@@ -128876,7 +129646,7 @@

rtables coverage - 90.59%

667 - 41873x + 41794x
setGeneric("get_formatted_cells", function(obj, shell = FALSE) standardGeneric("get_formatted_cells"))
@@ -129128,14 +129898,14 @@

rtables coverage - 90.59%

703 - 22635x + 22556x
    pr_row_format <- if (is.null(obj_format(obj))) "xx" else obj_format(obj)
704 - 22635x + 22556x
    pr_row_na_str <- obj_na_str(obj) %||% "NA"
@@ -129149,21 +129919,21 @@

rtables coverage - 90.59%

706 - 22635x + 22556x
    matrix(
707 - 22635x + 22556x
      unlist(Map(function(val, spn, shelli) {
708 - 108348x + 108048x
        stopifnot(is(spn, "integer"))
@@ -129177,28 +129947,28 @@

rtables coverage - 90.59%

710 - 108348x + 108048x
        out <- format_rcell(val,
711 - 108348x + 108048x
          pr_row_format = pr_row_format,
712 - 108348x + 108048x
          pr_row_na_str = pr_row_na_str,
713 - 108348x + 108048x
          shell = shelli
@@ -129212,14 +129982,14 @@

rtables coverage - 90.59%

715 - 108348x + 108048x
        if (!is.function(out) && is.character(out)) {
716 - 108340x + 108040x
          out <- paste(out, collapse = ", ")
@@ -129240,21 +130010,21 @@

rtables coverage - 90.59%

719 - 108348x + 108048x
        rep(list(out), spn)
720 - 22635x + 22556x
      }, val = row_cells(obj), spn = row_cspans(obj), shelli = shell)),
721 - 22635x + 22556x
      ncol = ncol(obj)
@@ -130213,21 +130983,21 @@

rtables coverage - 90.59%

858 - 650x + 626x
  if (length(x) > 0) {
859 - 650x + 626x
    indent <- rep_len(indent, length.out = length(x))
860 - 650x + 626x
    incr <- rep_len(incr, length.out = length(x))
@@ -130248,7 +131018,7 @@

rtables coverage - 90.59%

863 - 650x + 626x
  indent_str <- strrep(" ", (indent > 0) * indent * incr)
@@ -130262,28 +131032,28 @@

rtables coverage - 90.59%

865 - 650x + 626x
  if (including_newline) {
866 - 650x + 626x
    x <- unlist(mapply(function(xi, stri) {
867 - 13964x + 13452x
      gsub("\n", stri, xi, fixed = TRUE)
868 - 650x + 626x
    }, x, paste0("\n", indent_str)))
@@ -130304,7 +131074,7 @@

rtables coverage - 90.59%

871 - 650x + 626x
  paste0(indent_str, x)
@@ -153531,21 +154301,21 @@

rtables coverage - 90.59%

37 - 108365x + 108065x
  format <- if (missing(format)) obj_format(x) else format
38 - 108365x + 108065x
  if (is.null(format) && !is.null(pr_row_format)) {
39 - 75718x + 75694x
    format <- pr_row_format
@@ -153566,14 +154336,14 @@

rtables coverage - 90.59%

42 - 108365x + 108065x
  if (is.null(obj_na_str(x)) && !is.null(pr_row_na_str)) {
43 - 90388x + 90310x
    na_str <- pr_row_na_str
@@ -153601,7 +154371,7 @@

rtables coverage - 90.59%

47 - 108365x + 108065x
  if (shell) {
@@ -153622,28 +154392,28 @@

rtables coverage - 90.59%

50 - 79987x + 79687x
  format_value(rawvalues(x),
51 - 79987x + 79687x
    format = format,
52 - 79987x + 79687x
    output = output,
53 - 79987x + 79687x
    na_str = na_str