Convert to Markdown
sbf_as_md.RdConverts a data frame to the lines of a markdown table in the same format
as the .md file saved by sbf_save_table() and sbf_save_plot().
Arguments
- x
A data frame.
- round
A flag specifying whether to round the numeric columns as in the
.mdfile saved bysbf_save_table()(described there), in which case significant trailing zeros are kept. IfFALSEthe values are not rounded.- proportion
A flag specifying whether the columns
estimate,lower,upperandsdare proportions, in which case significant digits are counted from the nearer of 0 and 1 in the.mdfile.- format_column
A list of two-sided formulas of the form
column ~ fun(.)specifying how to round and format numeric columns other thanestimate,lower,upperandsdin the.mdfile. The function can return a numeric vector, which is formatted without further rounding, or a character vector, which is used as is. The values in the.rdsand.csvfiles are not altered.- round_as_estimate
A character vector of numeric columns, other than
estimate,lower,upper,sdandsvalue, to round in the.mdfile to the same number of decimal places asestimatein the same row (e.g. anobservedvalue compared with the estimate). Rows with a missing estimate are formatted as data. Ifproportion = TRUEthe columns must also be proportions.
Details
Numeric columns are right-aligned with their decimal points aligned using spaces and commas as thousands separators only for numbers of 10,000 or more. Other columns, including numbers stored as character, are left-aligned. List columns and the geometry column of sf objects are dropped.
Examples
x <- data.frame(
term = c("bIntercept", "bYear"),
estimate = c(0.53124, 12.3456),
lower = c(0.21234, 9.8765),
upper = c(0.87012, 15.4321)
)
writeLines(sbf_as_md(x))
#> | term | estimate | lower | upper |
#> | :--------- | -------: | ------: | -------: |
#> | bIntercept | 0.53124 | 0.21234 | 0.87012 |
#> | bYear | 12.3456 | 9.8765 | 15.4321 |
writeLines(sbf_as_md(x, round = TRUE))
#> | term | estimate | lower | upper |
#> | :--------- | -------: | ----: | ----: |
#> | bIntercept | 0.53 | 0.21 | 0.87 |
#> | bYear | 12.3 | 9.9 | 15 |