Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 1 | #' Add footnote |
| 2 | #' |
Hao Zhu | e7c8f70 | 2017-10-10 13:22:59 -0400 | [diff] [blame] | 3 | #' @description Add footnote to your favorite kable output. |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 4 | #' |
| 5 | #' @param input The direct output of your \code{kable} function or your last |
| 6 | #' \code{kableExtra} function. |
| 7 | #' @param label A vector of footnotes you want to add. You don't need to add |
| 8 | #' notations in your notes. |
| 9 | #' @param notation You can select the format of your footnote notation from |
Hao Zhu | b8b0cae | 2018-04-11 16:27:13 -0400 | [diff] [blame] | 10 | #' `number`, `alphabet`, `symbol` and `none`. |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 11 | #' @param threeparttable Boolean value indicating if a |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 12 | #' \href{https://www.ctan.org/pkg/threeparttable}{threeparttable} scheme should |
| 13 | #' be used. |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 14 | #' @param escape Logical value controlling if the label needs to be escaped. |
| 15 | #' Default is TRUE. |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 16 | #' |
Hao Zhu | 9399dcc | 2020-08-26 17:27:38 -0400 | [diff] [blame] | 17 | #' @examples |
| 18 | #' \dontrun{ |
| 19 | #' x <- knitr::kable(head(mtcars), "html") |
Hao Zhu | 78e6122 | 2017-05-24 20:53:35 -0400 | [diff] [blame] | 20 | #' add_footnote(x, c("footnote 1", "footnote 2"), notation = "symbol") |
Hao Zhu | 9399dcc | 2020-08-26 17:27:38 -0400 | [diff] [blame] | 21 | #' } |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 22 | #' |
| 23 | #' @export |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 24 | add_footnote <- function(input, label = NULL, |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 25 | notation = "alphabet", |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 26 | threeparttable = FALSE, |
| 27 | escape = TRUE) { |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 28 | if (is.null(label)) return(input) |
Hao Zhu | 8977a8a | 2015-11-19 16:52:21 -0500 | [diff] [blame] | 29 | |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 30 | if (notation == "alphabet") { |
| 31 | notation <- getOption("kable_footnote_notation", "alphabet") |
| 32 | } |
| 33 | if (!threeparttable) { |
| 34 | threeparttable <- getOption("kable_footnote_threeparttable", FALSE) |
| 35 | } |
| 36 | |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 37 | table_info <- NULL |
| 38 | |
Hao Zhu | b8b0cae | 2018-04-11 16:27:13 -0400 | [diff] [blame] | 39 | notation <- match.arg(notation, c("alphabet", "number", "symbol", "none")) |
| 40 | if (notation == "none") { |
| 41 | ids <- rep("", 20) |
| 42 | ids.intable <- ids |
| 43 | } else { |
| 44 | if (notation == "symbol") { |
| 45 | notation <- paste0(notation, ".", attr(input, "format")) |
| 46 | } |
| 47 | |
| 48 | ids.ops <- read.csv(system.file("symbol_index.csv", package = "kableExtra")) |
| 49 | ids <- ids.ops[, notation] |
| 50 | ids.intable <- gsub("\\*", "\\\\*", ids) |
| 51 | } |
| 52 | |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 53 | |
| 54 | #count the number of items in label and intable notation |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 55 | count.label <- length(label) |
| 56 | count.intablenote <- sum(str_count(input, "\\[note\\]")) |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 57 | if (count.intablenote != 0 & count.label != count.intablenote) { |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 58 | warning(paste("You entered", count.label, "labels but you put", |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 59 | count.intablenote, "[note] in your table.")) |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 60 | } |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 61 | |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 62 | export <- input |
| 63 | |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 64 | # Find out if there are any extra in-table notations needed to be corrected |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 65 | extra.notation <- unique(as.numeric( |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 66 | str_extract( |
| 67 | str_extract_all( |
| 68 | paste0(export, collapse = ""), "\\[note[0-9]{1,2}\\]" |
| 69 | )[[1]], |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 70 | "[0-9]{1,2}"))) |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 71 | |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 72 | # Pandoc --------------------------- |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 73 | # Footnote solution for markdown and pandoc. It is not perfect as |
| 74 | # markdown doesn't support complex table formats but this solution |
| 75 | # should be able to satisfy people who don't want to spend extra |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 76 | # time to define their `kable` format. |
| 77 | if (!attr(input, "format") %in% c("html", "latex")) { |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 78 | # In table notation |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 79 | if (count.intablenote != 0) { |
| 80 | for (i in 1:count.intablenote) { |
| 81 | replace_note <- paste0("^", ids.intable[i], "^", |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 82 | paste0(rep(" ", 4 - ceiling(i/5)), collapse = "")) |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 83 | |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 84 | export[which(str_detect(export, "\\[note\\]"))[1]] <- |
Hao Zhu | e10cfd3 | 2017-02-21 16:41:14 -0500 | [diff] [blame] | 85 | sub("\\[note\\]", replace_note, |
| 86 | export[which(str_detect(export, "\\[note\\]"))[1]]) |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 87 | } |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 88 | } |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 89 | # Fix extra in table notation |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 90 | for (i in extra.notation) { |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 91 | export <- gsub(paste0("\\[note", i, "\\]"), |
| 92 | paste0("^", ids.intable[i], "^", |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 93 | paste0(rep(" ", 4 - ceiling(i/5)), collapse = "")), |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 94 | export) |
| 95 | } |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 96 | |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 97 | export[length(export) + 1] <- "" |
| 98 | export[length(export) + 1] <- "__Note:__" |
| 99 | export[length(export) + 1] <- paste0( |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 100 | paste0("^", ids[1:length(label)], "^ ", label), collapse = " " |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 101 | ) |
| 102 | } |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 103 | |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 104 | # LaTeX Tables -------------------------------- |
| 105 | if (attr(input, "format") == "latex") { |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 106 | # Clean the entry for labels |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 107 | if (escape) { |
| 108 | label <- escape_latex(label) |
Hao Zhu | 1aff734 | 2018-04-02 18:33:15 -0400 | [diff] [blame] | 109 | label <- linebreak(label) |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 110 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 111 | label <- gsub("\\\\", "\\\\\\\\", label) |
Hao Zhu | 8977a8a | 2015-11-19 16:52:21 -0500 | [diff] [blame] | 112 | |
Hao Zhu | 904c0dc | 2018-04-04 16:14:32 -0400 | [diff] [blame] | 113 | export <- enc2utf8(export) |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 114 | table_info <- magic_mirror(input) |
| 115 | if (table_info$tabular == "longtable") { |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 116 | if (notation != "number") { |
| 117 | warning("Notation is set to 'number' and other formats are not supported.") |
| 118 | notation <- "number" |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 119 | } |
| 120 | # If longtable is used, then use page footnote instead of threeparttable |
| 121 | # as it makes more sense to see the footnote at the bottom of page if |
| 122 | # table is longer than one page. |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 123 | if (threeparttable == T) { |
| 124 | warning("Threeparttable does not support longtable.") |
| 125 | threeparttable = F |
| 126 | } |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 127 | |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 128 | # Longtable doesn't support footnote in caption directly. |
| 129 | # See http://tex.stackexchange.com/questions/50151/footnotes-in-longtable-captions |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 130 | |
| 131 | count.in.caption.note <- 0 |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 132 | if (!is.na(table_info$caption)) { |
| 133 | count.in.caption.note <- str_count(table_info$caption, "\\[note\\]") |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 134 | } |
| 135 | if (count.in.caption.note != 0) { |
| 136 | caption.footnote <- paste0("\\\\addtocounter{footnote}{-", |
| 137 | count.in.caption.note, "}") |
| 138 | for (i in 1:count.in.caption.note) { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 139 | export <- sub("\\[note\\]", "\\\\protect\\\\footnotemark ", export) |
| 140 | caption.footnote <- paste0( |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 141 | caption.footnote, "\n\\\\stepcounter{footnote}\\\\footnotetext{", |
| 142 | label[i], "}") |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 145 | if (str_detect(export, "\\\\toprule")) { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 146 | export <- sub("\\\\toprule", |
| 147 | paste0("\\\\toprule\n", caption.footnote), export) |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 148 | } else { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 149 | export <- sub("\\\\hline", |
| 150 | paste0("\\\\hline\n", caption.footnote), export) |
| 151 | } |
| 152 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 153 | for (i in (count.in.caption.note + 1):count.intablenote) { |
Hao Zhu | 4adea85 | 2015-11-16 16:38:34 -0500 | [diff] [blame] | 154 | export <- sub("\\[note\\]", |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 155 | paste0("\\\\footnote[", i, "]{", label[i], "}"), export) |
| 156 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 157 | for (i in extra.notation) { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 158 | export <- gsub(paste0("\\[note", i, "\\]"), |
| 159 | paste0("\\\\footnotemark[", i, "]"), |
| 160 | export) |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 161 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 162 | } else { |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 163 | # Replace in-table notation with appropriate symbol |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 164 | for (i in 1:count.intablenote) { |
| 165 | export <- sub("\\[note\\]", |
| 166 | paste0("\\\\textsuperscript{", ids.intable[i], "}"), |
| 167 | export) |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 168 | } |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 169 | |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 170 | # Fix extra in table notation |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 171 | for (i in extra.notation) { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 172 | export <- gsub(paste0("\\[note", i, "\\]"), |
| 173 | paste0("\\\\textsuperscript{", ids.intable[i], "}"), |
| 174 | export) |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 175 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 176 | if (threeparttable == T) { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 177 | # generate footer with appropriate symbol |
Hao Zhu | f7994dd | 2017-02-27 16:58:42 -0500 | [diff] [blame] | 178 | usepackage_latex("threeparttable") |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 179 | footer <- "" |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 180 | for (i in 1:count.label) { |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 181 | footer <- paste0(footer,"\\\\item [", ids[i], "] ", label[i], "\n") |
| 182 | } |
| 183 | |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 184 | if (grepl("\\\\caption\\{.*?\\}", export)) { |
| 185 | export <- sub("\\\\caption\\{", |
| 186 | "\\\\begin{threeparttable}\n\\\\caption{", |
| 187 | export) |
| 188 | } else { |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 189 | export <- sub(paste0("\\\\begin\\{", table_info$tabular, "\\}"), |
| 190 | paste0("\\\\begin{threeparttable}\n\\\\begin{", |
| 191 | table_info$tabular, "}"), |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 192 | export) |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 193 | } |
| 194 | export <- gsub( |
| 195 | "\\\\end\\{tabular\\}", |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 196 | paste0("\\\\end{tabular}\n\\\\begin{tablenotes}\n\\\\small\n", |
| 197 | footer, "\\\\end{tablenotes}\n\\\\end{threeparttable}"), |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 198 | export) |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 199 | } else { |
| 200 | table.width <- max(nchar( |
| 201 | str_replace_all( |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 202 | str_replace_all(table_info$contents, "\\[note\\]", ""), |
| 203 | "\\[note[0-9]{1,2}\\]", ""))) + 2 * (table_info$ncol - 1) |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 204 | footer <- "" |
| 205 | for (i in 1:count.label) { |
| 206 | label.wrap <- strwrap(label[i], table.width) |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 207 | footer <- paste0(footer, "\\\\multicolumn{", table_info$ncol, |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 208 | "}{l}{\\\\textsuperscript{", ids[i], "} ", |
| 209 | label.wrap[1], "}\\\\\\\\\n") |
| 210 | if (length(label.wrap) > 1) { |
| 211 | for (j in 2:length(label.wrap)) { |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 212 | footer <- paste0(footer, "\\\\multicolumn{", table_info$ncol, |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 213 | "}{l}{", label.wrap[j], "}\\\\\\\\\n") |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 214 | } |
| 215 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 216 | } |
Hao Zhu | 9f91748 | 2018-01-08 18:09:33 -0500 | [diff] [blame] | 217 | export <- gsub(table_info$end_tabular, |
| 218 | paste0(footer, "\\\\end{", table_info$tabular, "}"), |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 219 | export) |
Hao Zhu | dc4b714 | 2015-11-19 10:37:53 -0500 | [diff] [blame] | 220 | } |
Hao Zhu | db04e30 | 2015-11-15 16:57:38 -0500 | [diff] [blame] | 221 | } |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 222 | } |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 223 | |
| 224 | # HTML Tables ------------------- |
| 225 | if (attr(input, "format") == "html") { |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 226 | # Clean the entry for labels |
Hao Zhu | 9b45a18 | 2017-02-27 18:17:46 -0500 | [diff] [blame] | 227 | table_info <- magic_mirror(input) |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 228 | if (escape) { |
| 229 | label <- escape_html(label) |
| 230 | } |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 231 | # Replace in-table notation with appropriate symbol |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 232 | for (i in 1:count.intablenote) { |
| 233 | export <- sub("\\[note\\]", |
| 234 | paste0("<sup>", ids.intable[i], "</sup>"), |
| 235 | export) |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | # Fix extra in table notation |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 239 | for (i in extra.notation) { |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 240 | export <- gsub(paste0("\\[note", i, "\\]"), |
| 241 | paste0("<sup>", ids.intable[i], "</sup>"), |
| 242 | export) |
| 243 | } |
| 244 | |
| 245 | # Build footer |
| 246 | footer <- "<tfoot>\n" |
Hao Zhu | c541563 | 2017-02-21 17:16:13 -0500 | [diff] [blame] | 247 | for (i in 1:count.label) { |
Hao Zhu | 2203f66 | 2015-11-20 11:53:39 -0500 | [diff] [blame] | 248 | footer <- paste0(footer, "<tr>\n<td style = 'padding: 0; border:0;' ", |
| 249 | "colspan='100%'><sup>", ids[i],"</sup> ", |
| 250 | label[i], "</td>\n</tr>\n") |
| 251 | } |
| 252 | footer <- paste0(footer, "</tfoot>\n") |
| 253 | |
| 254 | # Paste footer to the table |
| 255 | export[1] <- gsub("</tbody>\n", paste0("</tbody>\n", footer), export[1]) |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 256 | } |
Hao Zhu | 32f43f7 | 2017-06-20 18:24:54 -0400 | [diff] [blame] | 257 | attr(export, "kable_meta") <- table_info |
Hao Zhu | b1bc0aa | 2015-11-12 11:23:42 -0500 | [diff] [blame] | 258 | return(export) |
| 259 | } |