Skip to content

Commit

Permalink
Merge branch 'main' into 636_tag_release@main
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Zhu <[email protected]>
  • Loading branch information
shajoezhu authored May 18, 2023
2 parents b62e6f4 + d19e447 commit fa22cac
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 118 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Suggests:
testthat,
tibble,
tidyr,
xml2
xml2,
r2rtf
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
13 changes: 11 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
## rtables 0.6.1
* Improved resilience of pagination machinery (`paginate_table`) by generalizing parameters' defaults (`cpp`, `lpp`, and `font_size`).
* Moved `export_as_txt` to `formatters`. Added to reexports.
* Fixed warning in `str` function when called upon table objects.
* Maximal level of nesting (`max.level`) set for `str` at 3 to avoid displaying all nested structures.
* Migrated `export_as_rtf` to `formatters`. Not re-exported.
* add `r2rtf` to Suggests
* pagination logic has been migrated completely (excepting page_by splits) to `formatters` and is now invoked from there. paginate_table remains as a convenience function.
* Removed warning in `str` method when called upon table objects.
* Provide `str` method for `VTableTree` objects with a default `max.level` of 3, as the infinite default from base is not
useful or informative.
* default `font_size` value is now `8` across pagination and export machinery
* `margins` argument in pagination and export machinery now (correctly) interpreted as inches. This change is inherited from `formatters`
* `lpp` and `cpp` now default to `NA_integer_`, which is interpreted as inferring their value from the physical page size specified.
* Horizontal pagination now occurs by default due to the above (because there is a default page type - `"letter"`. Pagination can still be turned off in either direction by setting `l/cpp` to `NULL` explicitly.
* Referential footnotes now have both a `symbol` and an `index`. Messages associated with symbols will only appear once per page in the footer materials regardless of number of elements referenced in the page with that symbol. Matches and inherits from changes in `formatters`
* Started deprecation cycle for `trim_zero_rows`.
* Fixed bug occurring when extracting `cell_values` after sorting.
* Removed deprecated function `vpaginate_table`.
Expand Down
87 changes: 2 additions & 85 deletions R/tt_export.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ path_enriched_df <- function(tt, path_fun = collapse_path, value_fun = collapse_
### Migrated to formatters.

#' @importFrom formatters export_as_txt
#'
#'
#' @examples
#' lyt <- basic_table() %>%
#' split_cols_by("ARM") %>%
Expand All @@ -136,7 +136,7 @@ path_enriched_df <- function(tt, path_fun = collapse_path, value_fun = collapse_
#' export_as_txt(tbl, file = tf)
#' system2("cat", tf)
#' }
#'
#'
#' @export
formatters::export_as_txt

Expand Down Expand Up @@ -504,86 +504,3 @@ export_as_pdf <- function(tt,
}
list(file = file, npages = npages, exceeds_width = exceeds_width, exceeds_height = exceeds_height, lpp = lpp, cpp = cpp)
}

.margin_lines_to_in <- function(margins, font_size, font_family) {
tmpfile <- tempfile(fileext = ".pdf")
gp_plot <- gpar(fontsize = font_size, fontfamily = font_family)
pdf(file = tmpfile, width = 20, height = 20)
on.exit({dev.off(); file.remove(tmpfile)})
grid.newpage()
pushViewport(plotViewport(margins = margins, gp = gp_plot))
c(bottom = convertHeight(unit(margins["bottom"], "lines"), "inches", valueOnly = TRUE),
left = convertWidth(unit(1, "strwidth", strrep("m", margins["left"])), "inches", valueOnly = TRUE),
top = convertHeight(unit(margins["top"], "lines"), "inches", valueOnly = TRUE),
right = convertWidth(unit(1, "strwidth", strrep("m", margins["right"])), "inches", valueOnly = TRUE))
}



### Migrated to formatters

## #' Export table to RTF
## #'
## #' Experimental export to the RTF format.
## #'
## #' @details RTF export occurs by via the following steps
## #'
## #' \itemize{
## #' \item{the table is paginated to the page size (Vertically and horizontally)}
## #' \item{Each separate page is converted to a MatrixPrintForm and from there to RTF-encoded text}
## #' \item{Separate rtfs text chunks are combined and written out as a single RTF file}
## #' }
## #'
## #' Conversion of `MatrixPrintForm` objects to RTF is done via [formatters::mpf_to_rtf()].
## #' @inheritParams export_as_txt
## #' @inheritParams tostring
## #' @inheritParams grid::plotViewport
## #' @inheritParams paginate_table
## #' @export

## export_as_rtf <- function(tt,
## file = NULL,
## colwidths = propose_column_widths(matrix_form(tt, TRUE)),
## page_type = "letter",
## pg_width = page_dim(page_type)[if(landscape) 2 else 1],
## pg_height = page_dim(page_type)[if(landscape) 1 else 2],
## landscape = FALSE,
## margins = c(bottom = 4, left = 4, top=4, right = 4),
## font_size = 8,
## font_family = "Courier",
## ...) {
## if(!requireNamespace("r2rtf"))
## stop("RTF export requires the r2rtf package, please install it.")
## if(is.null(names(margins)))
## names(margins) <- c("bottom", "left", "top", "right")
## if(!is.null(colwidths) && length(colwidths) != ncol(tt) + 1)
## stop("non-null colwidths argument must have length ncol(tt) + 1 [",
## ncol(tt) + 1, "], got length ", length(colwidths))

## margins_in <- .margin_lines_to_in(margins, font_size, font_family)
## true_width <- pg_width - sum(margins_in[c("left", "right")])
## true_height <- pg_height - sum(margins_in[c("top", "bottom")])

## tbls <- paginate_table(tt, font_family = font_family, font_size = font_size,
## pg_width = true_width,
## pg_height = true_height,
## margins = c(bottom = 0, left = 0, top = 0, right = 0),
## lineheight = 1.25,
## colwidths = colwidths,
## ...)

## rtftxts <- lapply(tbls, function(tbl) r2rtf::rtf_encode(mpf_to_rtf(tbl,
## colwidths = colwidths[c(1, .figure_out_colinds(tbl, tt))],
## page_type = page_type,
## pg_width = pg_width,
## pg_height = pg_height,
## font_size = font_size,
## margins = c(top = 0, left = 0, bottom = 0, right = 0))))
## restxt <- paste(rtftxts[[1]]$start,
## paste(sapply(rtftxts, function(x) x$body), collapse = "\n{\\pard\\fs2\\par}\\page{\\pard\\fs2\\par}\n"),
## rtftxts[[1]]$end)
## if(!is.null(file))
## cat(restxt, file = file)
## else
## restxt
## }
30 changes: 1 addition & 29 deletions R/tt_paginate.R
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ non_null_na <- function(x) !is.null(x) && is.na(x)
paginate_table <- function(tt,
page_type = "letter",
font_family = "Courier",
font_size = 12,
font_size = 8,
lineheight = 1,
landscape = FALSE,
pg_width = NULL,
Expand Down Expand Up @@ -802,33 +802,5 @@ paginate_table <- function(tt,
})
})
res <- unlist(res, recursive = FALSE)

## else if(!is.null(lpp)) {
## inds <- pag_tt_indices(tt, lpp = lpp,
## min_siblings = min_siblings,
## nosplitin = nosplitin,
## colwidths = colwidths,
## verbose = verbose,
## max_width = max_width)
## res <- lapply(inds, function(x) tt[x, , keep_topleft = TRUE,
## keep_titles = TRUE,
## reindex_refs = FALSE])
## } else { ## lpp is NULL
## res <- list(tt)
## }

## if(!is.null(cpp)) {
## inds <- vert_pag_indices(tt, cpp = cpp, colwidths = colwidths,
## verbose = verbose,
## rep_cols = 0L)
## res <- lapply(res,
## function(oneres) {
## lapply(inds,
## function(ii) oneres[, ii, drop = FALSE,
## keep_titles = TRUE,
## reindex_refs = FALSE])
## })
## res <- unlist(res, recursive = FALSE)
## }
res
}
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ rrows
RStudio
rtable
rtablel
rtf
sabanes
Sabanés
Saibah
Expand Down
2 changes: 1 addition & 1 deletion man/paginate.Rd

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

0 comments on commit fa22cac

Please sign in to comment.