Deprecated in 0.8.x (it says so once a session and still works),
removed in 0.9.0: the function is fmt_count_pct() now, named like the
other cell formatters.
Usage
format_count_pct(
count,
pct,
pct_unit = c("fraction", "percent"),
nbsp = " ",
pct_sign = FALSE,
na = "",
rounding = NULL
)Arguments
- count
Integer / numeric vector of counts. A
0count produces the count-only branch (no parentheses); a missing count produces thenatoken instead.- pct
Numeric vector of percentages. By default expressed as a fraction in
[0, 1]; passpct_unit = "percent"if your values are already in[0, 100]. Recycled againstcountif one argument is length 1. A fraction above 1 says once a session that the values look like percentages (5prints as500).- pct_unit
Either
"fraction"(default,0..1) or"percent"(0..100).- nbsp
Character used to replace the padding spaces. Default is the non-breaking space (Unicode code point U+00A0) so that RTF and Word do not collapse leading whitespace. Pass
" "(regular space) for plain-text output.- pct_sign
Logical (default
FALSE). WhenTRUE, a literal%is placed before the closing parenthesis (e.g." 14 (50.0%)") and every branch is one character wider so the)still aligns.- na
Text to print when the count is missing (
NA, orNaN– R counts it as missing). Right-justified in the count field, so its right edge lands on the ones digit, then padded to the branch width. The default""returns an empty cell. A missing percent alongside a real count is not missing data: the count still prints, on its own.Inf/-Infcounts print as"Inf"/"-Inf"– an infinity means a division by zero upstream, and hiding it would hide the bug.- rounding
How the percent is rounded to one decimal:
"r"(half to even) or"sas"(half away from zero).NULL, the default, readsgetOption("rtfreporter.rounding"); seeround_num().1/16is6.25%, printed"6.2"under"r"and"6.3"under"sas".
Value
As fmt_count_pct().
Examples
suppressWarnings(format_count_pct(5L, 0.05)) # fmt_count_pct(5L, 0.05)
#> [1] " 5 (5.0)"