Skip to content
Draft
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- DOCX exporter fixed watermark location in case of listings
- DOCX exporter updated table border width from 0.75 to 0.875 inches
- DOCX exporter when having vertical pagination in tables or listings, fixed the rows misalignment from page 2 and below compared to RTF
- `tt_to_tlgrtf()` now is passing vectorized colwidths when exporting 'allparts' to match the colwidths of the individual parts (#225)

### Changed

Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Depends:
formatters (>= 0.5.12),
rtables (>= 0.6.15)
Imports:
tidytlg (>= 0.11.0),
tidytlg (>= 0.11.0.9000),
tern (>= 0.9.10),
rlistings (>= 0.2.13),
checkmate (>= 2.1.0),
Expand Down Expand Up @@ -82,3 +82,4 @@ Suggests:
pharmaverseadamjnj (>= 0.0.2)
VignetteBuilder: knitr
Config/testthat/edition: 3
Remotes: eanokian/tidytlg@vectorize_colwidths
Comment thread
gmbecker marked this conversation as resolved.
59 changes: 39 additions & 20 deletions R/tt_to_tblfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ pg_width_by_orient <- function(landscape = FALSE) {
fullpg - mar_plus_gutters
}

get_colwidths_as_proportions <- function(colwidths, tlgtype, label_width_ins, pg_width) {
if (tlgtype == "Table") {
colwidths <- cwidths_final_adj(
labwidth_ins = label_width_ins,
total_width = pg_width,
colwidths = colwidths[-1]
)
}
colwidths <- colwidths / sum(colwidths)
if (sum(colwidths) > 1) {
colwidths <- colwidths - .Machine$double.eps ## much smaller than a twip = 1/20 printing point
}
return(colwidths)
}

get_output_csv_filename <- function(output_csv_directory, fpath, fname) {
if (is.null(output_csv_directory)) {
output_csv_filename <- file.path(fpath, paste0(tolower(fname), ".csv"))
Expand Down Expand Up @@ -691,28 +706,32 @@ tt_to_tlgrtf <- function(
fpath <- dirname(file)
}

if (tlgtype == "Table") {
colwidths <- cwidths_final_adj(
labwidth_ins = label_width_ins,
total_width = pg_width,
colwidths = colwidths[-1]
)
}
colwidths <- colwidths / sum(colwidths)
# finite precision arithmetic is a dreamscape of infinite wonder...
## sum(rep(1/18, 18)) <= 1 is FALSE...
if (sum(colwidths) > 1) {
colwidths <- colwidths - 0.00000000001 ## much smaller than a twip = 1/20 printing point
}

if (!one_table && # nolint start
is.list(tt) && !is(tt, "MatrixPrintForm")) {
### gentlg is not vectorized on wcol. x.x x.x x.x
### but it won't break if we only give it one number...
### Calling this an ugly hack is an insult to all the hard working hacks
### out there
colwidths <- colwidths[1]
} # nolint end
# this should be technically always 1 but just in case
num_repeated_cols <- ncol(tt[[1]]$strings) - ncol(tt[[1]])
# the following lines will listify the vector colwidths, this is, convert it
# to a list of vectors (one vector per page)
l_colwidths <- list()
j <- num_repeated_cols + 1
for (i in seq_along(tt)) {
subt_col_idxs <- j - 1 + seq(ncol(tt[[i]]))
Comment thread
eanokian marked this conversation as resolved.
colwidths_subt <- colwidths[c(1:num_repeated_cols, subt_col_idxs)]
## jump current col position to first column on next page
j <- tail(subt_col_idxs, 1) + 1
Comment thread
eanokian marked this conversation as resolved.
l_colwidths[[i]] <- get_colwidths_as_proportions(colwidths_subt,
tlgtype,
label_width_ins,
pg_width)
}
colwidths <- l_colwidths
} else { # nolint end
colwidths <- get_colwidths_as_proportions(colwidths,
tlgtype,
label_width_ins,
pg_width)
}


footer_val <- prep_strs_for_rtf(
c(
Expand Down
Loading