finished html table footnote
diff --git a/R/footnote.R b/R/footnote.R
index e995af1..d849779 100644
--- a/R/footnote.R
+++ b/R/footnote.R
@@ -14,8 +14,8 @@
#' "number", "alphabet" and "symbol".
#'
#' @export
-add_footnote <- function(input, label = NULL, notation = "alphabet", escape = T,
- threeparttable = F) {
+add_footnote <- function(input, label = NULL, notation = "number",
+ threeparttable = FALSE) {
if (is.null(label)){return(input)}
# Define available id list
@@ -83,12 +83,12 @@
export <- input
# Find out if there are any extra in-table notations needed to be corrected
- extra.notation <- as.numeric(
+ extra.notation <- unique(as.numeric(
str_extract(
str_extract_all(
paste0(export, collapse = ""), "\\[note[0-9]{1,2}\\]"
)[[1]],
- "[0-9]{1,2}"))
+ "[0-9]{1,2}")))
@@ -124,8 +124,9 @@
# Generate latex table footnote --------------------------------
if(attr(input, "format")=="latex"){
- # Clean the entry for labels when escape is enabled
- if (escape = T){label <- knitr:::escape_latex(label)}
+ # Clean the entry for labels
+ label <- knitr:::escape_latex(label)
+ label <- gsub("\\\\", "\\\\\\\\", label)
kable_info <- magic_mirror(input)
if(kable_info$tabular == "longtable"){
@@ -226,7 +227,32 @@
}
}
if(attr(input, "format")=="html"){
+ # Clean the entry for labels
+ label <- knitr:::escape_html(label)
+ # Replace in-table notation with appropriate symbol
+ for(i in 1:count.intablenoot){
+ export <- sub("\\[note\\]", paste0("<sup>", ids.intable[i], "</sup>"), export)
+ }
+
+ # Fix extra in table notation
+ for(i in extra.notation){
+ export <- gsub(paste0("\\[note", i, "\\]"),
+ paste0("<sup>", ids.intable[i], "</sup>"),
+ export)
+ }
+
+ # Build footer
+ footer <- "<tfoot>\n"
+ for(i in 1:count.label){
+ footer <- paste0(footer, "<tr>\n<td style = 'padding: 0; border:0;' ",
+ "colspan='100%'><sup>", ids[i],"</sup> ",
+ label[i], "</td>\n</tr>\n")
+ }
+ footer <- paste0(footer, "</tfoot>\n")
+
+ # Paste footer to the table
+ export[1] <- gsub("</tbody>\n", paste0("</tbody>\n", footer), export[1])
}
return(export)
}
diff --git a/man/add_footnote.Rd b/man/add_footnote.Rd
index 17122b1..029032c 100644
--- a/man/add_footnote.Rd
+++ b/man/add_footnote.Rd
@@ -4,8 +4,8 @@
\alias{add_footnote}
\title{Add footnote}
\usage{
-add_footnote(input, label = NULL, notation = "alphabet",
- threeparttable = F)
+add_footnote(input, label = NULL, notation = "number",
+ threeparttable = FALSE)
}
\arguments{
\item{input}{The direct output of your \code{kable} function or your last
diff --git a/man/magic_mirror_html.Rd b/man/magic_mirror_html.Rd
index afdcf9a..8f58d5f 100644
--- a/man/magic_mirror_html.Rd
+++ b/man/magic_mirror_html.Rd
@@ -6,6 +6,9 @@
\usage{
magic_mirror_html(input)
}
+\arguments{
+\item{input}{The output of kable}
+}
\description{
Magic Mirror for html table --------
}
diff --git a/man/magic_mirror_latex.Rd b/man/magic_mirror_latex.Rd
index c5874fd..c6ba366 100644
--- a/man/magic_mirror_latex.Rd
+++ b/man/magic_mirror_latex.Rd
@@ -6,6 +6,9 @@
\usage{
magic_mirror_latex(input)
}
+\arguments{
+\item{input}{The output of kable}
+}
\description{
Magic mirror for latex tables --------------
}