| Title: | Formatting Tools for Scientific Journal Writing |
|---|---|
| Description: | Scientific journal numeric formatting policies implemented in code. Emphasis on formatting mean/upper/lower sets of values to pasteable text for journal submission. For example c(2e6, 1e6, 3e6) becomes "2.00 million (1.00--3.00)". Lancet and Nature have built-in styles for rounding and punctuation marks. Users may extend journal styles arbitrarily. Four metrics are supported; proportions, percentage points, counts and rates. Magnitudes for all metrics are discovered automatically. |
| Authors: | Sam Byrne [aut, cre, cph] (ORCID: <https://orcid.org/0009-0008-1067-307X>) |
| Maintainer: | Sam Byrne <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.7.0 |
| Built: | 2026-06-04 07:31:30 UTC |
| Source: | https://github.com/epi-sam/journalr |
Standard for "x – y" and Lancet negative: ("\U2013")
en_dash()en_dash()
(chr) en-dash character
Other marks:
mid_dot(),
thin_space()
en_dash()en_dash()
Format a numeric vector into a string with specified magnitude (billion, million, thousand).
fmt_magnitude( x, metric, rate_unit = NULL, digits = 1, nsmall = 1, decimal.mark = ".", big.mark = ",", mag = NULL, count_label_thousands = FALSE, assert_prop_range = TRUE )fmt_magnitude( x, metric, rate_unit = NULL, digits = 1, nsmall = 1, decimal.mark = ".", big.mark = ",", mag = NULL, count_label_thousands = FALSE, assert_prop_range = TRUE )
x |
(num) numeric vector |
metric |
(chr 'c("prop", "pp", "count", "rate")') |
rate_unit |
(chr: default NULL) unit label for rates (e.g., "deaths", "cases"). Required when metric = "rate", ignored otherwise. |
digits |
(int: default 1L) passed to 'round()' |
nsmall |
(int: default 1L) passed to 'format()' |
decimal.mark |
(chr: default ".") decimal mark passed to 'format()' |
big.mark |
(chr: default ",") thousands separator passed to 'format()' |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" |
count_label_thousands |
(lgl: default FALSE) allow thousands magnitude? Not Lancet-valid. Passed to 'set_magnitude()' |
assert_prop_range |
(lgl: default TRUE) assert that proportion values are between -1 and +1 (or -100 and +100 if mag="as-is") |
Unaware of styles, just a hard-coded git-er-done function.
Caution - thousands magnitude is not Lancet compliant.
(chr) formatted string
Other vector_formats:
add_epsilon(),
format_oxford_comma(),
fround(),
fround_count_rate(),
fround_metric(),
fround_metric_lancet(),
fround_props()
Other magnitudes:
set_magnitude(),
set_magnitude_count(),
set_magnitude_prop(),
set_magnitude_rate()
fmt_magnitude(123456789, metric = "count") fmt_magnitude(0.0000123, metric = "rate", rate_unit = "deaths")fmt_magnitude(123456789, metric = "count") fmt_magnitude(0.0000123, metric = "rate", rate_unit = "deaths")
Defaults are generic. This function allows special formtting marks to be applied by journal. Use 'format_lancet_clu()' for Lancet-specific formatting. Use 'format_nature_clu()' for Nature-specific formatting.
format_journal_clu( central, lower, upper, metric, rate_unit = NULL, mag = NULL, style_name = "nature" )format_journal_clu( central, lower, upper, metric, rate_unit = NULL, mag = NULL, style_name = "nature" )
central |
(num) central, point_estimate value vector |
lower |
(num) lower bound vector |
upper |
(num) upper bound vector |
metric |
(chr c(prop, pp, count, rate)) metric - proportion, percentage point, count, or rate |
rate_unit |
(chr: default NULL) rate unit label (required when metric = 'rate') |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" - Examples: "deaths", "cases", "events", "births" |
style_name |
(chr: default 'nature') style name - controls rounding and formatting. |
Takes three vectors as main arguments for data.table-friendly vectorization.
'central' could be mean, median, point_estimate
Transform c(central = 0.994, lower = 0.984, upper = 0.998) to "99.4% (98.4–99.8)"
Accounts for negative values, and UIs that cross zero. Checks if central, lower, upper values are in the correct order.
(chr) formatted string vector
Other styled_formats:
format_journal_df(),
format_lancet_clu(),
format_lancet_df(),
format_metric_cols(),
format_nature_clu(),
format_nature_df(),
fround_clu_triplet(),
new_style()
format_journal_clu( central = c(0.994, -0.994) , lower = c(0.984, -0.998) , upper = c(0.998, -0.984) , metric = "prop" ) # Rate formatting with rate_unit format_journal_clu( central = 0.0000123, lower = 0.0000098, upper = 0.0000152, metric = "rate", rate_unit = "deaths" )format_journal_clu( central = c(0.994, -0.994) , lower = c(0.984, -0.998) , upper = c(0.998, -0.984) , metric = "prop" ) # Rate formatting with rate_unit format_journal_clu( central = 0.0000123, lower = 0.0000098, upper = 0.0000152, metric = "rate", rate_unit = "deaths" )
Assumes a single data-type (metric) for the whole table (e.g. 'prop', 'pp', 'count')
format_journal_df( df, metric, new_var = "clu_fmt", style_name = "nature", central_var = "mean", lower_var = "lower", upper_var = "upper", remove_clu_columns = TRUE, rate_unit = NULL, mag = NULL )format_journal_df( df, metric, new_var = "clu_fmt", style_name = "nature", central_var = "mean", lower_var = "lower", upper_var = "upper", remove_clu_columns = TRUE, rate_unit = NULL, mag = NULL )
df |
(data.frame, data.table) |
metric |
(chr c('prop', 'pp', 'count', 'rate')) a single metric |
new_var |
(chr: default 'clu_fmt') name of new formatted column |
style_name |
(chr: default 'nature') style name - controls rounding and formatting. |
central_var |
(chr: default 'mean') name of central tendency variable |
lower_var |
(chr: default 'lower') name of lower bound variable |
upper_var |
(chr: default 'upper') name of upper bound variable |
remove_clu_columns |
(lgl: default TRUE) remove central, lower, upper variables after formatting? |
rate_unit |
(chr: default NULL) rate unit label (required when metric = 'rate') - Examples: "deaths", "cases", "events", "births" |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" - Examples: "deaths", "cases", "events", "births" |
(data.frame) data.frame, data.table with new 'clu_fmt' column
Other styled_formats:
format_journal_clu(),
format_lancet_clu(),
format_lancet_df(),
format_metric_cols(),
format_nature_clu(),
format_nature_df(),
fround_clu_triplet(),
new_style()
df <- data.frame( location_id = c(1, 2, 3) , mean = c(0.1234, 0, -0.3456) , lower = c(0.1134, -0.2245, -0.4445) , upper = c(0.1334, 0.2445, 0.3556) ) format_journal_df(df, metric = "prop") # Rate formatting example rate_df <- data.frame( location = c("Global", "USA"), mean = c(0.0000123, 0.0000456), lower = c(0.0000098, 0.0000401), upper = c(0.0000152, 0.0000512) ) format_journal_df(rate_df, metric = "rate", rate_unit = "deaths")df <- data.frame( location_id = c(1, 2, 3) , mean = c(0.1234, 0, -0.3456) , lower = c(0.1134, -0.2245, -0.4445) , upper = c(0.1334, 0.2445, 0.3556) ) format_journal_df(df, metric = "prop") # Rate formatting example rate_df <- data.frame( location = c("Global", "USA"), mean = c(0.0000123, 0.0000456), lower = c(0.0000098, 0.0000401), upper = c(0.0000152, 0.0000512) ) format_journal_df(rate_df, metric = "rate", rate_unit = "deaths")
Format central, lower, upper value triplets for Lancet journal presentation
format_lancet_clu(central, lower, upper, metric, rate_unit = NULL, mag = NULL)format_lancet_clu(central, lower, upper, metric, rate_unit = NULL, mag = NULL)
central |
(num) central, point_estimate value vector |
lower |
(num) lower bound vector |
upper |
(num) upper bound vector |
metric |
(chr c(prop, pp, count, rate)) metric - proportion, percentage point, count, or rate |
rate_unit |
(chr: default NULL) rate unit label (required when metric = 'rate') |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" - Examples: "deaths", "cases", "events", "births" |
(chr) formatted string vector
Other styled_formats:
format_journal_clu(),
format_journal_df(),
format_lancet_df(),
format_metric_cols(),
format_nature_clu(),
format_nature_df(),
fround_clu_triplet(),
new_style()
format_lancet_clu( central = c(0.994, -0.994) , lower = c(0.984, -0.998) , upper = c(0.998, -0.984) , metric = "prop" ) # Rate example with Lancet formatting format_lancet_clu( central = 0.0000123, lower = 0.0000098, upper = 0.0000152, metric = "rate", rate_unit = "deaths" )format_lancet_clu( central = c(0.994, -0.994) , lower = c(0.984, -0.998) , upper = c(0.998, -0.984) , metric = "prop" ) # Rate example with Lancet formatting format_lancet_clu( central = 0.0000123, lower = 0.0000098, upper = 0.0000152, metric = "rate", rate_unit = "deaths" )
Assumes a single data-type (metric) for the whole table (e.g. 'prop', 'pp', 'count')
format_lancet_df( df, metric, new_var = "clu_fmt", central_var = "mean", lower_var = "lower", upper_var = "upper", remove_clu_columns = TRUE, rate_unit = NULL, mag = NULL )format_lancet_df( df, metric, new_var = "clu_fmt", central_var = "mean", lower_var = "lower", upper_var = "upper", remove_clu_columns = TRUE, rate_unit = NULL, mag = NULL )
df |
(data.table) with central, lower, upper columns |
metric |
(chr c('prop', 'pp', 'count', 'rate')) metric - proportion, percentage point, count, or rate |
new_var |
(chr: default 'clu_fmt') name of new formatted column |
central_var |
(chr: default 'mean') name of central tendency e.g. 'point_estimate' |
lower_var |
(chr: default 'lower') |
upper_var |
(chr: default 'upper') |
remove_clu_columns |
(lgl: default TRUE) remove central, lower, upper columns after formatting? |
rate_unit |
(chr: default NULL) rate unit label (required when metric = 'rate') |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" - Examples: "deaths", "cases", "events", "births" |
(data.frame, data.table) with mean_95_UI_formatted column, and central, lower, upper columns removed (if specified)
Other styled_formats:
format_journal_clu(),
format_journal_df(),
format_lancet_clu(),
format_metric_cols(),
format_nature_clu(),
format_nature_df(),
fround_clu_triplet(),
new_style()
df <- data.frame( location_did = 1 , location_name = "Global" , me_name = "vacc_dpt1" , mean = 55.8e6 , lower = 50.7e6 , upper = 60.7e6 ) format_lancet_df(df = df, metric = "count", central_var = 'mean')df <- data.frame( location_did = 1 , location_name = "Global" , me_name = "vacc_dpt1" , mean = 55.8e6 , lower = 50.7e6 , upper = 60.7e6 ) format_lancet_df(df = df, metric = "count", central_var = 'mean')
Format one or more 'mean_' columns by magnitude, metric, and style.
format_metric_cols( df, metric, var_prefix = "mean", rate_unit = NULL, mag = NULL, style_name = "nature" )format_metric_cols( df, metric, var_prefix = "mean", rate_unit = NULL, mag = NULL, style_name = "nature" )
df |
(data.table) input data.table with one or more 'mean_' columns |
metric |
(chr c('prop', 'pp', 'count', 'rate')) a single metric |
var_prefix |
(chr: default 'mean') prefix of mean variable names to format. Implemented as e.g. "^mean[_]+" to capture 'mean', 'mean_1990', 'mean_2000', etc. |
rate_unit |
(chr: default NULL) unit label for rates (e.g., "deaths", "cases"). Required when metric = "rate", ignored otherwise. |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" |
style_name |
(chr: default 'nature') style name - controls rounding and formatting. |
(data.table) copy of input data.table with formatted mean column(s)
Other styled_formats:
format_journal_clu(),
format_journal_df(),
format_lancet_clu(),
format_lancet_df(),
format_nature_clu(),
format_nature_df(),
fround_clu_triplet(),
new_style()
df <- data.frame( location_id = c(1, 2, 3) , mean_1990 = c(100, 1e6, 1e9) , mean_2000 = c(200, 2e6, 2e-1) ) format_metric_cols(df, metric = "count")df <- data.frame( location_id = c(1, 2, 3) , mean_1990 = c(100, 1e6, 1e9) , mean_2000 = c(200, 2e6, 2e-1) ) format_metric_cols(df, metric = "count")
Format central, lower, upper value triplets for Nature journal presentation
format_nature_clu(central, lower, upper, metric, rate_unit = NULL, mag = NULL)format_nature_clu(central, lower, upper, metric, rate_unit = NULL, mag = NULL)
central |
(num) central, point_estimate value vector |
lower |
(num) lower bound vector |
upper |
(num) upper bound vector |
metric |
(chr c(prop, pp, count, rate)) metric - proportion, percentage point, count, or rate |
rate_unit |
(chr: default NULL) rate unit label (required when metric = 'rate') |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" - Examples: "deaths", "cases", "events", "births" |
(chr) formatted string vector
Other styled_formats:
format_journal_clu(),
format_journal_df(),
format_lancet_clu(),
format_lancet_df(),
format_metric_cols(),
format_nature_df(),
fround_clu_triplet(),
new_style()
format_nature_clu( central = c(0.994, -0.994) , lower = c(0.984, -0.998) , upper = c(0.998, -0.984) , metric = "prop" ) # Rate example with Nature formatting format_nature_clu( central = 0.0000123, lower = 0.0000098, upper = 0.0000152, metric = "rate", rate_unit = "cases" )format_nature_clu( central = c(0.994, -0.994) , lower = c(0.984, -0.998) , upper = c(0.998, -0.984) , metric = "prop" ) # Rate example with Nature formatting format_nature_clu( central = 0.0000123, lower = 0.0000098, upper = 0.0000152, metric = "rate", rate_unit = "cases" )
Return a table with formatted central, lower, upper for Nature journal
format_nature_df( df, metric, new_var = "clu_fmt", central_var = "mean", lower_var = "lower", upper_var = "upper", remove_clu_columns = TRUE, rate_unit = NULL, mag = NULL )format_nature_df( df, metric, new_var = "clu_fmt", central_var = "mean", lower_var = "lower", upper_var = "upper", remove_clu_columns = TRUE, rate_unit = NULL, mag = NULL )
df |
(data.table) |
metric |
(chr c('prop', 'pp', 'count', 'rate')) a single metric |
new_var |
(chr: default 'clu_fmt') name of new formatted column |
central_var |
(chr: default 'mean') name of central tendency variable |
lower_var |
(chr: default 'lower') name of lower bound variable |
upper_var |
(chr: default 'upper') name of upper bound variable |
remove_clu_columns |
(lgl: default TRUE) remove central, lower, upper columns after formatting? |
rate_unit |
(chr: default NULL) rate unit label (required when metric = 'rate') |
mag |
(chr: default NULL) magnitude override - see set_magnitude() - For props/pp: "as-is" (no scaling, use values as provided) - For counts: "t" (thousand), "m" (million), "b" (billion) - For rates: "per10", "per100", "per1k", ..., "per10b" - Examples: "deaths", "cases", "events", "births" |
(data.table) copy of input data.table with new 'clu_fmt' column
Other styled_formats:
format_journal_clu(),
format_journal_df(),
format_lancet_clu(),
format_lancet_df(),
format_metric_cols(),
format_nature_clu(),
fround_clu_triplet(),
new_style()
df <- data.frame( location_did = 1 , location_name = "Global" , me_name = "vacc_dpt1" , mean = 55.8e6 , lower = 50.7e6 , upper = 60.7e6 ) format_nature_df(df = df, metric = "count", central_var = 'mean')df <- data.frame( location_did = 1 , location_name = "Global" , me_name = "vacc_dpt1" , mean = 55.8e6 , lower = 50.7e6 , upper = 60.7e6 ) format_nature_df(df = df, metric = "count", central_var = 'mean')
Format vector of items with Oxford comma
format_oxford_comma(vec, sep = "and")format_oxford_comma(vec, sep = "and")
vec |
(any) vector of items to format |
sep |
(chr: default "and") separator before last item |
(chr) formatted string with Oxford comma
Other vector_formats:
add_epsilon(),
fmt_magnitude(),
fround(),
fround_count_rate(),
fround_metric(),
fround_metric_lancet(),
fround_props()
format_oxford_comma(1:2) format_oxford_comma(1:3) format_oxford_comma(1:3, "or")format_oxford_comma(1:2) format_oxford_comma(1:3) format_oxford_comma(1:3, "or")
Unaware of data-type or schema, just a hard-coded git-er-done function.
fround(x, digits = 1L, nsmall = 1L, decimal.mark = ".")fround(x, digits = 1L, nsmall = 1L, decimal.mark = ".")
x |
(num) numeric vector |
digits |
(integer) passed to 'round()' |
nsmall |
(integer) passed to 'format()' |
decimal.mark |
(chr) passed to 'format()' |
(chr) formatted string
Other vector_formats:
add_epsilon(),
fmt_magnitude(),
format_oxford_comma(),
fround_count_rate(),
fround_metric(),
fround_metric_lancet(),
fround_props()
fround(0.123456789) fround(0.123456789, digits = 3) fround(0.123456789, digits = 3, nsmall = 4)fround(0.123456789) fround(0.123456789, digits = 3) fround(0.123456789, digits = 3, nsmall = 4)
Unaware of schema, just a hard-coded git-er-done function.
fround_metric(x, metric = "prop", digits = 1L, nsmall = 1L, decimal.mark = ".")fround_metric(x, metric = "prop", digits = 1L, nsmall = 1L, decimal.mark = ".")
x |
(num) numeric value |
metric |
(chr: default 'prop' c('prop', 'pp', 'count', 'rate')) |
digits |
(integer: default 1L) passed to 'round()' |
nsmall |
(integer: default 1L) passed to 'format()' |
decimal.mark |
(chr: default ".") decimal mark passed to 'format()' |
(chr) formatted string
Other vector_formats:
add_epsilon(),
fmt_magnitude(),
format_oxford_comma(),
fround(),
fround_count_rate(),
fround_metric_lancet(),
fround_props()
fround_metric(0.123456789) fround_metric(0.123456789, 'pp', 3, 4) fround_metric(c(55.8346, 123.456789), 'count', 3, 4, ".")fround_metric(0.123456789) fround_metric(0.123456789, 'pp', 3, 4) fround_metric(c(55.8346, 123.456789), 'count', 3, 4, ".")
Lancet-specific wrapper for 'fround_metric()', using mid-dot as decimal mark. Retaining for legacy purposes (no Nature equivalent)
fround_metric_lancet( x, metric = "prop", digits = 1L, nsmall = 1L, decimal.mark = mid_dot() )fround_metric_lancet( x, metric = "prop", digits = 1L, nsmall = 1L, decimal.mark = mid_dot() )
x |
(num) numeric value |
metric |
(chr: default 'prop' c('prop', 'pp', 'count', rate)) |
digits |
(integer: default 1L) passed to 'round()' |
nsmall |
(integer: default 1L) passed to 'format()' |
decimal.mark |
(chr: default mid_dot()) decimal mark passed to 'format()' |
(chr) formatted string
Other vector_formats:
add_epsilon(),
fmt_magnitude(),
format_oxford_comma(),
fround(),
fround_count_rate(),
fround_metric(),
fround_props()
fround_metric_lancet(0.123456789) fround_metric_lancet(0.123456789, 'pp', 3, 4) fround_metric_lancet(c(55.8346, 123.456789), 'count', 3, 4, ".")fround_metric_lancet(0.123456789) fround_metric_lancet(0.123456789, 'pp', 3, 4) fround_metric_lancet(c(55.8346, 123.456789), 'count', 3, 4, ".")
Centrally managed definition for all metric labels.
get_metric_labels(metric)get_metric_labels(metric)
metric |
(chr) |
(list) named list of metric labels
Other metrics:
get_metrics()
get_metric_labels('prop')get_metric_labels('prop')
Centrally managed definition for all allowed metrics.
get_metrics()get_metrics()
(chr) vector of allowed metrics
Other metrics:
get_metric_labels()
get_metrics()get_metrics()
Accessor function to retrieve a style from the package's styles dictionary.
get_style(style_name)get_style(style_name)
style_name |
(chr) name of the style to retrieve |
(list) the requested style as a named list
Other styles:
assert_style_schema(),
get_style_schema(),
new_style(),
set_style(),
style_lancet(),
style_nature()
get_style("lancet")get_style("lancet")
Centrally managed definition for all required journal format styles.
get_style_schema()get_style_schema()
(list) named list of style elements and their expected types
Other styles:
assert_style_schema(),
get_style(),
new_style(),
set_style(),
style_lancet(),
style_nature()
get_style_schema()get_style_schema()
Lancet numeric decimal standard: "" ("\U00B7")
mid_dot()mid_dot()
(chr) mid-dot character
Other marks:
en_dash(),
thin_space()
mid_dot()mid_dot()
Wrapper function to create and set a new style in one step.
new_style( style_name, prop_digits_round = 1, prop_nsmall = 1, prop_invert_all_neg_UI = TRUE, count_method = "sigfig", count_digits_sigfig = 3, count_pad_sigfigs = TRUE, count_nsmall = 1, count_big.mark = ",", count_label_thousands = FALSE, count_invert_all_neg_UI = FALSE, rate_method = "sigfig", rate_digits_sigfig = 3, rate_pad_sigfigs = TRUE, rate_nsmall = 1, rate_invert_all_neg_UI = FALSE, decimal.mark = ".", neg_mark_mean = "-", neg_mark_UI = "-", UI_only = FALSE, UI_text = "", is_lancet = FALSE, round_5_up = TRUE, assert_clu_order = TRUE, assert_prop_range = TRUE )new_style( style_name, prop_digits_round = 1, prop_nsmall = 1, prop_invert_all_neg_UI = TRUE, count_method = "sigfig", count_digits_sigfig = 3, count_pad_sigfigs = TRUE, count_nsmall = 1, count_big.mark = ",", count_label_thousands = FALSE, count_invert_all_neg_UI = FALSE, rate_method = "sigfig", rate_digits_sigfig = 3, rate_pad_sigfigs = TRUE, rate_nsmall = 1, rate_invert_all_neg_UI = FALSE, decimal.mark = ".", neg_mark_mean = "-", neg_mark_UI = "-", UI_only = FALSE, UI_text = "", is_lancet = FALSE, round_5_up = TRUE, assert_clu_order = TRUE, assert_prop_range = TRUE )
style_name |
(chr) name of the style to set |
prop_digits_round |
(int: default 1) number of digits to round proportions to |
prop_nsmall |
(int: default 1) minimum number of digits to the right of the decimal point - proportions |
prop_invert_all_neg_UI |
(lgl: default TRUE) if mean/lower/upper are all negative, invert signs in UI for proportions? e.g. -0.1 (-0.2 to -0.05) becomes - 0.1 (0.05 to 0.2) |
count_method |
(chr: c("sigfig", "decimal", "int")) choose how to report counts - prioritize sigfigs across mean/lower/upper, hard-set decimals, or leave numbers in integer space. |
count_digits_sigfig |
(int: default 3) number of significant figures for counts |
count_pad_sigfigs |
(lgl: default TRUE) signif(5.00, 3) is "5" - do you want to pad the trailing 0s back on - usually TRUE? |
count_nsmall |
(int: default 1) passed to ‘format()' if 'count_method' == ’decimal' |
count_big.mark |
(chr: default ",") character to use for counts thousand, million, billion separator e.g. "," |
count_label_thousands |
(lgl: default FALSE) whether format counts as e.g. 10,000 as '10 thousand' |
count_invert_all_neg_UI |
(lgl: default FALSE) if mean/lower/upper are all negative, invert signs in UI for counts? e.g. -10 (-20 to -5) becomes -10 (5 to 20) |
rate_method |
(chr: c("sigfig", "decimal", "int")) choose how to report rates - prioritize sigfigs across mean/lower/upper, hard-set decimals, or leave numbers in integer space. |
rate_digits_sigfig |
(int: default 3) number of significant figures for rates |
rate_pad_sigfigs |
(lgl: default TRUE) signif(5.00, 3) is "5" - do you want to pad the trailing 0s back on for rates - usually TRUE? |
rate_nsmall |
(int: default 1) passed to ‘format()' if 'rate_method' == ’decimal' |
rate_invert_all_neg_UI |
(lgl: default FALSE) if mean/lower/upper are all negative, invert signs in UI for rates? e.g. -10 (-20 to -5) per million becomes -10 (5 to 20) per million |
decimal.mark |
(chr: default ".") decimal mark e.g. "." or 'mid_dot()' for Lancet. |
neg_mark_mean |
(chr: default "-") string to describe central value negatives - e.g. "-1 (-2 to 4)" could become "Negtive 1 (-2 to 4)" |
neg_mark_UI |
(chr: default "-") string to describe negative sign in UI brackets e.g. "1 (-2 to 4)" could become "1 (–2 to 4)" (en-dash) |
UI_only |
(lgl: default FALSE) Return only UI from 'format_journal_df()' family functions? |
UI_text |
(chr: default "") Text to appear inside UI brackets before numbers e.g. "2 (1 – 4)" could become "2 (95%UI 1 – 4)" |
is_lancet |
(lgl: default FALSE) TRUE to handle edge-case Lancet count formatting policies |
round_5_up |
(lgl: default TRUE) In R, 'round(1245, 3)' is "1240". Do you want to round to "1250" instead? Default TRUE to conform with common expectations. |
assert_clu_order |
(lgl: default TRUE) whether to assert CLU relationships (ensure lower < central < upper) |
assert_prop_range |
(lgl: default TRUE) whether to assert that proportion values are between -1 and +1 |
(chr) invisible vector of input objects
Other styles:
assert_style_schema(),
get_style(),
get_style_schema(),
set_style(),
style_lancet(),
style_nature()
Other styled_formats:
format_journal_clu(),
format_journal_df(),
format_lancet_clu(),
format_lancet_df(),
format_metric_cols(),
format_nature_clu(),
format_nature_df(),
fround_clu_triplet()
new_style(style_name = "my_style")new_style(style_name = "my_style")
Support function used on _central_ (e.g. mean) values for later formatting. Routes to appropriate helper based on metric.
set_magnitude( x, metric, mag = NULL, count_label_thousands = FALSE, assert_prop_range = TRUE, verbose = TRUE )set_magnitude( x, metric, mag = NULL, count_label_thousands = FALSE, assert_prop_range = TRUE, verbose = TRUE )
x |
(num) numeric vector |
metric |
(chr) metric: "prop", "pp", "count", "rate" (required) |
mag |
(chr: default NULL) magnitude override (NULL = auto-detect) - For counts: "t", "m", "b" - For rates: "per10", "per100", "per1k", ..., "per10b" - For props/pp: "as-is" (no scaling, use values as provided) |
count_label_thousands |
(lgl: default FALSE) allow "thousands" magnitude for counts? Not Lancet-valid. |
assert_prop_range |
(lgl: default TRUE) for proportions, assert that values are between -1 and +1 (or -100 and +100 if mag="as-is")? |
verbose |
(lgl: default TRUE) show warnings? |
(data.frame) with columns: mag, mag_label, denom
Other magnitudes:
fmt_magnitude(),
set_magnitude_count(),
set_magnitude_prop(),
set_magnitude_rate()
# Proportions (no scaling) set_magnitude(c(0.5, 0.75), metric = "prop") # Counts set_magnitude(c(1e3, 1e6, 1e9), metric = "count") # Rates set_magnitude(c(0.0000123, 0.0000456), metric = "rate")# Proportions (no scaling) set_magnitude(c(0.5, 0.75), metric = "prop") # Counts set_magnitude(c(1e3, 1e6, 1e9), metric = "count") # Rates set_magnitude(c(0.0000123, 0.0000456), metric = "rate")
Set a new style by list
set_style(style_name, style_entry)set_style(style_name, style_entry)
style_name |
(chr) name of the style to set |
style_entry |
(list) named list representing the style entry |
(chr) invisible vector of input objects, to allow easier un-locking
Other styles:
assert_style_schema(),
get_style(),
get_style_schema(),
new_style(),
style_lancet(),
style_nature()
set_style( style_name = "my_style" , style_entry = list( style_name = "my_style" , prop_digits_round = 1 , prop_nsmall = 1 , prop_invert_all_neg_UI = TRUE , count_method = "sigfig" , count_digits_sigfig = 3 , count_pad_sigfigs = TRUE , count_nsmall = 1 , count_big.mark = "," , count_label_thousands = FALSE , count_invert_all_neg_UI = FALSE , rate_method = "sigfig" , rate_digits_sigfig = 3 , rate_pad_sigfigs = TRUE , rate_nsmall = 1 , rate_invert_all_neg_UI = FALSE , decimal.mark = "." , neg_mark_mean = "-" , neg_mark_UI = "-" , UI_only = FALSE , UI_text = "" , is_lancet = FALSE , round_5_up = TRUE , assert_clu_order = TRUE , assert_prop_range = TRUE ) )set_style( style_name = "my_style" , style_entry = list( style_name = "my_style" , prop_digits_round = 1 , prop_nsmall = 1 , prop_invert_all_neg_UI = TRUE , count_method = "sigfig" , count_digits_sigfig = 3 , count_pad_sigfigs = TRUE , count_nsmall = 1 , count_big.mark = "," , count_label_thousands = FALSE , count_invert_all_neg_UI = FALSE , rate_method = "sigfig" , rate_digits_sigfig = 3 , rate_pad_sigfigs = TRUE , rate_nsmall = 1 , rate_invert_all_neg_UI = FALSE , decimal.mark = "." , neg_mark_mean = "-" , neg_mark_UI = "-" , UI_only = FALSE , UI_text = "" , is_lancet = FALSE , round_5_up = TRUE , assert_clu_order = TRUE , assert_prop_range = TRUE ) )
Pre-defined style schema for Lancet journal formatting
style_lancet()style_lancet()
(list) named list representing the lancet style
Other styles:
assert_style_schema(),
get_style(),
get_style_schema(),
new_style(),
set_style(),
style_nature()
style_lancet()style_lancet()
The default style for the package.
style_nature()style_nature()
Pre-defined style schema for Nature journal formatting.
(list) named list representing the nature style
Other styles:
assert_style_schema(),
get_style(),
get_style_schema(),
new_style(),
set_style(),
style_lancet()
style_nature()style_nature()
Lancet thin space separator for counts 10,000 – 999,9999 instead of comma ",": ("\U2009")
thin_space()thin_space()
(chr) thin space character
Other marks:
en_dash(),
mid_dot()
thin_space()thin_space()