add_table_footnotes: Add footnotes within your tables in a smart way

View source: R/NMFSReports.R

add_table_footnotesR Documentation

Add footnotes within your tables in a smart way

Description

Add footnotes within your tables in a smart way

Usage

add_table_footnotes(
  table,
  footnote = NULL,
  from_col = "",
  to_col = "",
  from_row = "",
  to_row = "",
  delim = ",,,"
)

Arguments

table

The data.frame you are adding footnotes to (and possibly from).

footnote

A string that you want to add as a footnote to the table. Optional.

from_col

What column number or name you want to pull footnotes from.

to_col

What column number or name you want add footnotes to.

from_row

What row number or name you want to pull footnotes from.

to_row

What row number or name you want add footnotes to.

delim

A deliminator string that seperates if you have multiple footnotes stored in a cell. The deliminator can be anything, as long as it does not conflict with anything that can be interpreted by regex. Default = "&&&"

Value

The table "tab" with the footnotes inserted into the table.

Examples

table<-data.frame(col = LETTERS[1:10],
                      x = rnorm(n = 10),
                      y = rnorm(n = 10),
                      footnotes = NA)
table$footnotes[3]<-"Example footnote in a table 1."
table$footnotes[4]<-"Example footnote in a table 2.&&&Example footnote in a table 3."
table[,c("x", "y")] <- NMFSReports::mod_number(table[,c("x", "y")],
                                                     divideby = 1, #'
                                                     comma_seperator = TRUE,
                                                     digits = 2)
# Here, add footnotes from the "footnotes" column to the content in the first column where necessary
table <- add_table_footnotes(tab = table,
                                   from_col = "footnotes", # either use the name of the column
                                   to_col = 1) # or the number of that column in that table
# Here, add a specific footnote to a specific place in the table
table <- add_table_footnotes(tab = table,
                                   footnote = "Example footnote in a table 4.",
                                   to_row = 2,
                                   to_col = 2)
table <- add_table_footnotes(tab = table,
                                   footnote = c("Example footnote in a table 5.",
                                                "Example footnote in a table 6."),
                                   to_row = 4,
                                   to_col = 2)
knitr::kable(table)

EmilyMarkowitz-NOAA/NMFSReports documentation built on March 26, 2023, 1:08 a.m.