Description Usage Arguments Details Value Examples
pretty_pvalues() takes a vector of p-values, rounds them to a specified digit amount, allows options for emphasizing p-values < the defined significance level, and returns a character for missing.
1 2 3 4 |
pvalues |
numeric vector of raw p-values to be formatted |
digits |
number of digits to round to; values with zeros past this number of digits are truncated |
missing_char |
character string that will replace missing values from the p-value vector. Default = "—" |
include_p |
TRUE or FALSE: set to TRUE to print "p = " before each p-value |
trailing_zeros |
TRUE or FALSE: default = TRUE, p-values are formatted with trailing zeros to the defined number of digits (i.e. 0.100 instead of 0.1 if digits= 3) |
output_type |
output type, either NULL (default), "latex", or "html" (making special charaters latex friendly) |
bold |
TRUE or FALSE: set to TRUE to bold p-values < the defined significance level |
italic |
TRUE or FALSE: set to TRUE to italicize p-values < the defined significance level |
background |
highlight color for p-values < the defined significance level. Default = NULL (no highlighting) |
sig_alpha |
the defined significance level. Default = 0.05 |
With this function, there are two things to be noted:
Since the p-value vector formatting uses cell_spec
, which generates raw HTML or LaTeX code, make sure you remember to put escape = FALSE
into your kable code when generating your table. At the same time, you will need to escape special symbols manually.
Additionally, cell_spec
needs a way to know whether you want HTML or LaTeX output. You can specify it locally in the function or globally using options(knitr.table.format = "latex")
. If you don't provide anything, this function will output as HTML by default.
Vector of transformed p-values for table output
1 2 3 4 5 6 7 8 9 10 11 | pvalue_example = c(1, 0.06, 0.0005, NA, 1e-6)
pretty_pvalues(pvalue_example, background = "pink")
pretty_pvalues(pvalue_example, digits = 4, missing_char = "missing", bold = TRUE)
# How to use pretty_pvalues in reports
raw_pvals <- c(0.00000007, .05000001, NaN, NA, 0.783)
pretty_pvals <- pretty_pvalues(raw_pvals , digits = 3,
background = "green", italic = TRUE, bold = TRUE)
kableExtra::kable(pretty_pvals , format = "latex", escape = FALSE, col.names = c("P-values"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.