Skip to content

Commit

Permalink
change: renovate fmt_2stats() so that it uses flextable global sett…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
davidgohel committed Dec 21, 2023
1 parent d8092f0 commit f6e4dbc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 58 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flextable
Type: Package
Title: Functions for Tabular Reporting
Version: 0.9.5.004
Version: 0.9.5.005
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
## Changes

- Deprecate `set_formatter_type()`.
- renovate `fmt_2stats()` so that it uses global flextable settings,
i.e. digits, etc.

# flextable 0.9.4

Expand Down
40 changes: 16 additions & 24 deletions R/summarizor.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,7 @@ dataset_describe <- function(dataset) {
#' deviation or a median absolute deviation.
#' @param cts a count to display
#' @param pcts a percentage to display
#' @param num1_mask format associated with `num1`, a format string
#' used by [sprintf()].
#' @param num2_mask format associated with `num2`, a format string
#' used by [sprintf()].
#' @param cts_mask format associated with `cts`, a format string
#' used by [sprintf()].
#' @param pcts_mask format associated with `pcts`, a format string
#' used by [sprintf()].
#' @param ... unused arguments
#' @seealso [summarizor()], [tabulator()], [mk_par()]
#' @family text formatter functions
#' @examples
Expand Down Expand Up @@ -238,9 +231,7 @@ dataset_describe <- function(dataset) {
#' )
#' ft_1 <- autofit(ft_1)
#' ft_1
fmt_2stats <- function(stat, num1, num2, cts, pcts,
num1_mask = "%.01f", num2_mask = "(%.01f)",
cts_mask = "%.0f", pcts_mask = "(%.02f%%)") {
fmt_2stats <- function(stat, num1, num2, cts, pcts, ...) {
z_num <- character(length = length(num1))
z_cts <- character(length = length(num1))

Expand All @@ -251,30 +242,31 @@ fmt_2stats <- function(stat, num1, num2, cts, pcts,
is_cts_2 <- !is.na(cts) & !is.na(pcts)
is_cts_1 <- !is.na(cts) & is.na(pcts)

z_num[is_num_1] <- sprintf(num1_mask, num1[is_num_1])
z_num[is_num_1] <- fmt_dbl(num1[is_num_1])

z_num[is_mean_sd] <- paste0(
sprintf(num1_mask, num1[is_mean_sd]),
" ",
sprintf(num2_mask, num2[is_mean_sd])
fmt_dbl(num1[is_mean_sd]),
" (",
fmt_dbl(num2[is_mean_sd]), ")"
)
z_num[is_median_iqr] <- paste0(
sprintf(num1_mask, num1[is_median_iqr]),
" ",
sprintf(num2_mask, num2[is_median_iqr])
fmt_dbl(num1[is_median_iqr]),
" (",
fmt_dbl(num2[is_median_iqr]),
")"
)
z_num[is_range] <- paste0(
sprintf(num1_mask, num1[is_range]),
fmt_dbl(num1[is_range]),
" - ",
sprintf(num1_mask, num2[is_range])
fmt_dbl(num2[is_range])
)

z_cts[is_cts_2] <- paste0(
sprintf(cts_mask, cts[is_cts_2]),
" ",
sprintf(pcts_mask, pcts[is_cts_2] * 100)
fmt_int(cts[is_cts_2]),
" (",
fmt_pct(pcts[is_cts_2]), ")"
)
z_cts[is_cts_1] <- sprintf(cts_mask, cts[is_cts_1])
z_cts[is_cts_1] <- fmt_int(cts[is_cts_1])

paste0(z_num, z_cts)
}
Expand Down
36 changes: 3 additions & 33 deletions man/fmt_2stats.Rd

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

0 comments on commit f6e4dbc

Please sign in to comment.