Skip to content

Commit

Permalink
Merge branch 'main' into remove_decoration_nl_matrix_form@243_fix_nl_…
Browse files Browse the repository at this point in the history
…expansion@main
  • Loading branch information
Melkiades authored Jan 12, 2024
2 parents 9f8c8dc + 39b5fd5 commit 1d7ce66
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rtables
Title: Reporting Tables
Version: 0.6.6.9002
Date: 2024-01-08
Version: 0.6.6.9003
Date: 2024-01-10
Authors@R: c(
person("Gabriel", "Becker", , "[email protected]", role = "aut",
comment = "Original creator of the package"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## rtables 0.6.6.9002
## rtables 0.6.6.9003
### New Features
* Added `top_level_section_div` for `basic_table` to set section dividers for top level rows.

Expand Down
11 changes: 7 additions & 4 deletions R/tree_accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -1173,18 +1173,22 @@ setMethod("content_na_str<-", "Split", function(obj, value) {
#' Returns a matrix of formats for the cells in a table
#' @param obj A table or row object.
#' @param default `FormatSpec`.
#' @export
#'
#' @return Matrix (storage mode list) containing the effective format for each
#' cell position in the table (including 'virtual' cells implied by label rows,
#' whose formats are always `NULL`)
#' @examples
#' whose formats are always `NULL`).
#'
#' @seealso [table_shell()] and [table_shell_str()] for information on the table format structure.
#'
#' @examples
#' lyt <- basic_table() %>%
#' split_rows_by("RACE", split_fun = keep_split_levels(c("ASIAN", "WHITE"))) %>%
#' analyze("AGE")
#'
#' tbl <- build_table(lyt, DM)
#' value_formats(tbl)
#'
#' @export
setGeneric("value_formats", function(obj, default = obj_format(obj)) standardGeneric("value_formats"))
#' @rdname value_formats
setMethod(
Expand All @@ -1193,7 +1197,6 @@ setMethod(
obj_format(obj) %||% default
}
)

#' @rdname value_formats
setMethod(
"value_formats", "TableRow",
Expand Down
8 changes: 6 additions & 2 deletions R/tt_toString.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ setMethod("toString", "VTableTree", function(x,
#' @inheritParams tostring
#' @inheritParams gen_args
#' @return for `table_shell_str` the string representing the table shell, for `table_shell`,
#' `NULL`, as the function is called for the side effect of printing the shell to the console
#' @export
#' `NULL`, as the function is called for the side effect of printing the shell to the console.
#'
#' @seealso [value_formats()] for a matrix of formats for each cell in a table.
#'
#' @examples
#' library(dplyr)
#'
Expand All @@ -89,6 +91,8 @@ setMethod("toString", "VTableTree", function(x,
#'
#' tbl <- build_table(lyt, iris2)
#' table_shell(tbl)
#'
#' @export
table_shell <- function(tt, widths = NULL, col_gap = 3, hsep = default_hsep(),
tf_wrap = FALSE, max_width = NULL) {
cat(table_shell_str(
Expand Down
6 changes: 5 additions & 1 deletion man/table_shell.Rd

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

7 changes: 5 additions & 2 deletions man/value_formats.Rd

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

14 changes: 14 additions & 0 deletions vignettes/introspecting_tables.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ row_paths_summary(tbl)
col_paths_summary(tbl)
```

## Insights on Value Format Structure

We can gain insight into the value formatting structure of a table using `table_shell()`, which returns a table with the same output as `print()` but with the cell values replaced by their underlying format strings (e.g. instead of `40.0`, `xx.x` is displayed, and so on). This is useful for understanding the structure of the table, and for debugging purposes. Another useful tool is the `value_formats()` function which instead of a table returns a matrix of the format strings for each cell value in the table.

See below the printout for the above examples:

```{r}
table_shell(tbl)
```

```{r}
value_formats(tbl)
```

## Applications

Knowing the structure of an `rtable` object is helpful for retrieving specific values from the table.
Expand Down

0 comments on commit 1d7ce66

Please sign in to comment.