lowcase_parens | R Documentation |
These functions are used to format the "N=" population label on column headers.
lowcase_parens(x)
upcase_parens(x)
lowcase_n(x)
upcase_n(x)
x |
Population count |
Which function to use to format the population label is specified
on the n_format
parameter on the create_table
function.
These formatting functions provide several options for formatting the "N=",
including whether the "N" should be upper case or lower case, and whether
or not to put the value in parentheses. If one of these options does not
meet the specifications for your report, you may also write your own
formatting function and pass it to the n_format
function. When an
N value is supplied, the output of this function will be concatenated
to the header label.
create_table
function to create a table.
# Create test data
l <- "Label"
n <- 47
cat(paste0(l, lowcase_parens(n)))
# Label
# (n=47)
cat(paste0(l, upcase_parens(n)))
# Label
# (N=47)
cat(paste0(l, lowcase_n(n)))
# Label
# n=47
cat(paste0(l, upcase_n(n)))
# Label
# N=47
customN <- function(n) {
return(paste0(": N=", n))
}
cat(paste0(l, customN(n)))
# Label: N=47
## Use alternate n format ##
library(reporter)
library(magrittr)
tmp <- tempfile(fileext = ".txt")
# Prepare data
df <- read.table(header = TRUE, text = '
Hair Group1 Group2
Black 25 16
Brown 13 18
Blonde 5 7
Red 2 1')
# Create table with lowcase n formatting
tbl <- create_table(df, n_format=lowcase_n) %>%
titles("Hair Color") %>%
define(Group1, n = 45) %>%
define(Group2, n = 42)
# Create report
rpt <- create_report(tmp) %>%
add_content(tbl, align = "left")
# Write to file system
write_report(rpt)
writeLines(readLines(tmp))
# Hair Color
#
# Group1 Group2
# Hair n=45 n=42
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# Black 25 16
# Brown 13 18
# Blonde 5 7
# Red 2 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.