add escape to footnote; add function documentation
diff --git a/R/footnote.R b/R/footnote.R
index 9999be7..8863327 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -1,5 +1,31 @@
#' Add footnote (new)
#'
+#' @description `footnote` provides a more flexible way to add footnote. You
+#' can add mutiple sets of footnote using differeny notation system. It is
+#' also possible to specify footnote section header one by one and print
+#' footnotes as a chunk of texts.
+#'
+#' @param kable_input HTML or LaTeX table generated by `knitr::kable`
+#' @param general Text for general footnote comments. Footnotes in this section
+#' won't be labeled with any notations
+#' @param number A vector of footnote texts. Footnotes here will be numbered.
+#' There is no upper cap for the number of footnotes here
+#' @param alphabet A vector of footnote texts, Footnotes here will be labeled
+#' with abc. The vector here should not have more than 26 elements.
+#' @param symbol A vector of footnote texts, Footnotes here will be labeled
+#' with special symbols. The vector here should not have more than 20 elements.
+#' @param footnote_order The order of how to arrange `general`, `number`,
+#' `alphabet` and `symbol`.
+#' @param footnote_as_chunk T/F value. Default is FALSE. It controls whether
+#' the footnotes should be printed in a chunk (without line break).
+#' @param escape T/F value. It controls whether the contents and titles should
+#' be escaped against HTML or LaTeX. Default is TRUE.
+#' @param general_title Section header for general footnotes. Default is
+#' "Note: ".
+#' @param number_title Section header for number footnotes. Default is "".
+#' @param alphabet_title Section header for alphabet footnotes. Default is "".
+#' @param symbol_title Section header for symbol footnotes. Default is "".
+#'
#' @export
footnote <- function(kable_input,
general = NULL,
@@ -9,6 +35,7 @@
footnote_order = c("general", "number",
"alphabet", "symbol"),
footnote_as_chunk = FALSE,
+ escape = TRUE,
general_title = "Note: ",
number_title = "",
alphabet_title = "",
@@ -19,15 +46,6 @@
message("Currently generic markdown table using pandoc is not supported.")
return(kable_input)
}
- footnote_titles <- list(
- general = general_title, number = number_title,
- alphabet = alphabet_title, symbol = symbol_title
- )
- footnote_contents <- list(
- general = general, number = number, alphabet = alphabet, symbol = symbol
- )
- notnull <- names(footnote_contents)[!sapply(footnote_contents, is.null)]
- if (length(notnull) == 0) {return(kable_input)}
if (length(alphabet) > 26) {
alphabet <- alphabet[1:26]
warning("Please don't use more than 26 footnotes in table_footnote ",
@@ -38,9 +56,28 @@
warning("Please don't use more than 20 footnotes in table_footnote ",
"symbol. Use number instead.")
}
+ footnote_titles <- list(
+ general = general_title, number = number_title,
+ alphabet = alphabet_title, symbol = symbol_title
+ )
+ footnote_contents <- list(
+ general = general, number = number, alphabet = alphabet, symbol = symbol
+ )
+ notnull <- names(footnote_contents)[!sapply(footnote_contents, is.null)]
+ if (length(notnull) == 0) {return(kable_input)}
footnote_order <- footnote_order[footnote_order %in% notnull]
footnote_titles <- footnote_titles[footnote_order]
footnote_contents <- footnote_contents[footnote_order]
+ footnote_contents <- lapply(footnote_contents, esca)
+ if (escape) {
+ if (kable_format == "html") {
+ footnote_contents <- lapply(footnote_contents, escape_html)
+ footnote_titles <- lapply(footnote_titles, escape_html)
+ } else {
+ footnote_contents <- lapply(footnote_contents, escape_latex)
+ footnote_titles <- lapply(footnote_titles, escape_latex)
+ }
+ }
footnote_table <- footnote_table_maker(
kable_format, footnote_titles, footnote_contents
)
diff --git a/R/footnote_marker.R b/R/footnote_marker.R
index 45ffafb..df54339 100644
--- a/R/footnote_marker.R
+++ b/R/footnote_marker.R
@@ -1,4 +1,16 @@
#' Footnote marker
+#'
+#' @description Put footnote mark in superscription in table. Unless you are
+#' using it in the `caption` of `kable`, you will need to put `escape = F`
+#' in `kable` (similar with `cell_spec`). Again, similar with `cell_spec`, the
+#' `format` option here can read default value from global option
+#' `knitr.table.format`.
+#'
+#' @param x a number. For example, for `footnote_marker_alphabet(2)` will
+#' return "b" in HTML.
+#' @param format Either `html` or `latex`. All functions here can read
+#' default value from global option `knitr.table.format`.
+#'
#' @export
footnote_marker_number <- function(x, format) {
if (missing(format) || is.null(format)) {
@@ -15,6 +27,7 @@
}
}
+#' @rdname footnote_marker_number
#' @export
footnote_marker_alphabet <- function(x, format) {
if (missing(format) || is.null(format)) {
@@ -32,6 +45,7 @@
}
}
+#' @rdname footnote_marker_number
#' @export
footnote_marker_symbol <- function(x, format) {
if (missing(format) || is.null(format)) {