Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Sep 25, 2023
1 parent 0909b8b commit 87b48c1
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions R/tt_export.R
Original file line number Diff line number Diff line change
Expand Up @@ -730,26 +730,28 @@ tt_to_flextable <- function(tt,
# IMPORTANT: Fix of (N=xx) which is by default on a new line but we usually do not
# want this, and it depends on the size of the table, it is not another
# row with different columns -> All of this should be fixed at source (in toString)
det_nclab <- apply(hdr, 2, grepl, pattern = "\\(N=[0-9]+\\)$")
has_nclab <- apply(det_nclab, 1, any)
if (isFALSE(counts_in_newline) && any(has_nclab)) {
whsnc <- which(has_nclab) # which rows have it
what_is_nclab <- det_nclab[whsnc, ]
# condition for popping the interested row by merging the upper one
hdr[whsnc - 1, what_is_nclab] <- paste(hdr[whsnc - 1, what_is_nclab],
hdr[whsnc, what_is_nclab],
sep = " "
)
hdr[whsnc, what_is_nclab] <- ""

# We can remove the row if they are all ""
if (all(!nzchar(hdr[whsnc, ]))) {
hdr <- hdr[-whsnc, , drop = FALSE]
spans <- spans[-whsnc, , drop = FALSE]
body <- body[-whsnc, , drop = FALSE]
mpf_aligns <- mpf_aligns[-whsnc, , drop = FALSE]
hnum <- hnum - 1
}
if (hnum > 1) { # otherwise nothing to do
det_nclab <- apply(hdr, 2, grepl, pattern = "\\(N=[0-9]+\\)$")
has_nclab <- apply(det_nclab, 1, any)
if (isFALSE(counts_in_newline) && any(has_nclab)) {
whsnc <- which(has_nclab) # which rows have it
what_is_nclab <- det_nclab[whsnc, ]
# condition for popping the interested row by merging the upper one
hdr[whsnc - 1, what_is_nclab] <- paste(hdr[whsnc - 1, what_is_nclab],
hdr[whsnc, what_is_nclab],
sep = " "
)
hdr[whsnc, what_is_nclab] <- ""

# We can remove the row if they are all ""
if (all(!nzchar(hdr[whsnc, ]))) {
hdr <- hdr[-whsnc, , drop = FALSE]
spans <- spans[-whsnc, , drop = FALSE]
body <- body[-whsnc, , drop = FALSE]
mpf_aligns <- mpf_aligns[-whsnc, , drop = FALSE]
hnum <- hnum - 1
}
}
}

flx <- flx %>%
Expand Down

0 comments on commit 87b48c1

Please sign in to comment.