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