Skip to content

Commit

Permalink
Merge be51495 into 5385b1a
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbecker authored Feb 6, 2025
2 parents 5385b1a + be51495 commit 1d7e84a
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 59 deletions.
5 changes: 4 additions & 1 deletion R/format_rcell.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' This is a wrapper for [formatters::format_value()] for use with `CellValue` objects
#'
#' @inheritParams lyt_args
#' @inheritParams formatters::format_value
#' @param x (`CellValue` or `ANY`)\cr an object of class `CellValue`, or a raw value.
#' @param format (`string` or `function`)\cr the format label or formatter function to
#' apply to `x`.
Expand Down Expand Up @@ -32,6 +33,7 @@ format_rcell <- function(x, format,
na_str = obj_na_str(x) %||% "NA",
pr_row_format = NULL,
pr_row_na_str = NULL,
round_type = c("iec", "sas"),
shell = FALSE) {
# Check for format and parent row format
format <- if (missing(format)) obj_format(x) else format
Expand All @@ -50,6 +52,7 @@ format_rcell <- function(x, format,
format_value(rawvalues(x),
format = format,
output = output,
na_str = na_str
na_str = na_str,
round_type = round_type
)
}
42 changes: 26 additions & 16 deletions R/tt_toString.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ setMethod("toString", "VTableTree", function(x,
tf_wrap = FALSE,
max_width = NULL,
fontspec = font_spec(),
ttype_ok = FALSE) {
ttype_ok = FALSE,
round_type = c("iec", "sas")) {
toString(
matrix_form(x,
indent_rownames = TRUE,
indent_size = indent_size,
fontspec = fontspec,
col_gap = col_gap
col_gap = col_gap,
round_type = round_type
),
widths = widths, col_gap = col_gap,
hsep = hsep,
tf_wrap = tf_wrap,
max_width = max_width,
fontspec = fontspec,
ttype_ok = ttype_ok
ttype_ok = ttype_ok,
round_type = round_type
)
})

Expand Down Expand Up @@ -146,6 +149,7 @@ table_shell_str <- function(tt, widths = NULL, col_gap = 3, hsep = default_hsep(
#' it is useful to map the `rtable` to an in-between state with the formatted cells in a matrix form.
#'
#' @inheritParams gen_args
#' @inheritParams formatters::format_value
#' @param indent_rownames (`flag`)\cr if `TRUE`, the column with the row names in the `strings` matrix of the output
#' has indented row names (strings pre-fixed).
#' @param expand_newlines (`flag`)\cr whether the matrix form generated should expand rows whose values contain
Expand Down Expand Up @@ -203,7 +207,8 @@ setMethod(
expand_newlines = TRUE,
indent_size = 2,
fontspec = NULL,
col_gap = 3L) {
col_gap = 3L,
round_type = c("iec", "sas")) {
stopifnot(is(obj, "VTableTree"))
check_ccount_vis_ok(obj)
header_content <- .tbl_header_mat(obj) # first col are for row.names
Expand All @@ -213,7 +218,7 @@ setMethod(
body_content_strings <- if (NROW(sr) == 0) {
character()
} else {
cbind(as.character(sr$label), get_formatted_cells(obj))
cbind(as.character(sr$label), get_formatted_cells(obj, round_type = round_type))
}

formats_strings <- if (NROW(sr) == 0) {
Expand Down Expand Up @@ -641,6 +646,7 @@ get_formatted_fnotes <- function(tt) {
#' Get formatted cells
#'
#' @inheritParams gen_args
#' @inheritParams formatters::format_value
#' @param shell (`flag`)\cr whether the formats themselves should be returned instead of the values with formats
#' applied. Defaults to `FALSE`.
#'
Expand All @@ -664,17 +670,20 @@ get_formatted_fnotes <- function(tt) {
#'
#' @export
#' @rdname gfc
setGeneric("get_formatted_cells", function(obj, shell = FALSE) standardGeneric("get_formatted_cells"))
setGeneric(
"get_formatted_cells",
function(obj, shell = FALSE, round_type = c("iec", "sas")) standardGeneric("get_formatted_cells")
)

#' @rdname gfc
setMethod(
"get_formatted_cells", "TableTree",
function(obj, shell = FALSE) {
lr <- get_formatted_cells(tt_labelrow(obj), shell = shell)
function(obj, shell = FALSE, round_type = c("iec", "sas")) {
lr <- get_formatted_cells(tt_labelrow(obj), shell = shell, round_type = round_type)

ct <- get_formatted_cells(content_table(obj), shell = shell)
ct <- get_formatted_cells(content_table(obj), shell = shell, round_type = round_type)

els <- lapply(tree_children(obj), get_formatted_cells, shell = shell)
els <- lapply(tree_children(obj), get_formatted_cells, shell = shell, round_type = round_type)

## TODO fix ncol problem for rrow()
if (ncol(ct) == 0 && ncol(lr) != ncol(ct)) {
Expand All @@ -688,17 +697,17 @@ setMethod(
#' @rdname gfc
setMethod(
"get_formatted_cells", "ElementaryTable",
function(obj, shell = FALSE) {
lr <- get_formatted_cells(tt_labelrow(obj), shell = shell)
els <- lapply(tree_children(obj), get_formatted_cells, shell = shell)
function(obj, shell = FALSE, round_type = c("iec", "sas")) {
lr <- get_formatted_cells(tt_labelrow(obj), shell = shell, round_type = round_type)
els <- lapply(tree_children(obj), get_formatted_cells, shell = shell, round_type = round_type)
do.call(rbind, c(list(lr), els))
}
)

#' @rdname gfc
setMethod(
"get_formatted_cells", "TableRow",
function(obj, shell = FALSE) {
function(obj, shell = FALSE, round_type = c("iec", "sas")) {
# Parent row format and na_str
pr_row_format <- if (is.null(obj_format(obj))) "xx" else obj_format(obj)
pr_row_na_str <- obj_na_str(obj) %||% "NA"
Expand All @@ -710,7 +719,8 @@ setMethod(
out <- format_rcell(val,
pr_row_format = pr_row_format,
pr_row_na_str = pr_row_na_str,
shell = shelli
shell = shelli,
round_type = round_type
)
if (!is.function(out) && is.character(out)) {
out <- paste(out, collapse = ", ")
Expand All @@ -726,7 +736,7 @@ setMethod(
#' @rdname gfc
setMethod(
"get_formatted_cells", "LabelRow",
function(obj, shell = FALSE) {
function(obj, shell = FALSE, round_type = c("iec", "sas")) {
nc <- ncol(obj) # TODO note rrow() or rrow("label") has the wrong ncol
vstr <- if (shell) "-" else ""
if (labelrow_visible(obj)) {
Expand Down
70 changes: 37 additions & 33 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
amongst
ARD
ARDs
Bové
CRAN's
Bov<U+00E9>
Carreras
charset
Cheatsheet
Chohan
FFFL
Godwin
Heng
Hoffmann
Kelkhoff
Layouting
Lewandowski
Maximo
Modelling
NSE
ORCID
Paszty
Pharma
Phuse
Pre
Qi
RStudio
Resync
Rua
STUDYID
Sabanés
Saibah
Stoilova
Subtable
Subtables
Tadeusz
Unstratified
ValueWrapper
Yung
amongst
charset
combinatorial
CRAN's
customizations
de
decrementing
Expand All @@ -45,49 +16,82 @@ dplyr
emph
facetted
facetting
FFFL
formatter
forseeable
funder
getter
getters
Godwin
Heng
Hoffmann
IEC
iec
ing
initializer
iteratively
Kelkhoff
labelled
Layouting
layouting
Lewandowski
mandatorily
Maximo
Modelling
monospace
multivariable
NSE
ORCID
orderable
Paszty
pathing
peforms
Pharma
Phuse
postfix
postprocessing
Pre
pre
priori
programmatically
Qi
reindexed
repo
repped
responder
Resync
reusability
roadmap
RStudio
Rua
Saban<U+00E9>s
Saibah
sas
sortable
spl
Stoilova
STUDYID
subsplits
Subtable
subtable
subtable's
Subtables
subtables
summarization
tableone
Tadeusz
todo
traversable
truetype
unaggregated
unicode
univariable
unpruned
Unstratified
unstratified
useR
ValueWrapper
visibilty
visiblities
xtable
Yung
5 changes: 5 additions & 0 deletions man/format_rcell.Rd

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

4 changes: 2 additions & 2 deletions man/formatters_methods.Rd

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

14 changes: 9 additions & 5 deletions man/gfc.Rd

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

7 changes: 6 additions & 1 deletion man/matrix_form-VTableTree-method.Rd

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

7 changes: 6 additions & 1 deletion man/tostring.Rd

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

Loading

0 comments on commit 1d7e84a

Please sign in to comment.