diff --git a/DESCRIPTION b/DESCRIPTION index f343a1b..ecea9b2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -50,5 +50,5 @@ VignetteBuilder: Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 SystemRequirements: pandoc (>= 2.0.6) - http://pandoc.org diff --git a/man/as_flextable_methods.Rd b/man/as_flextable_methods.Rd index 9dc4572..3bae194 100644 --- a/man/as_flextable_methods.Rd +++ b/man/as_flextable_methods.Rd @@ -4,7 +4,7 @@ \alias{as_flextable_methods} \alias{as_flextable.grouped_df} \alias{as_flextable.data.frame} -\title{method to convert object to flextable} +\title{Method to transform objects into flextables} \usage{ \method{as_flextable}{grouped_df}( x, @@ -60,12 +60,17 @@ iris \%>\% } \seealso{ Other as_flextable methods: +\code{\link[flextable]{as_flextable.data.frame}()}, \code{\link[flextable]{as_flextable.gam}()}, \code{\link[flextable]{as_flextable.glm}()}, \code{\link[flextable]{as_flextable.grouped_data}()}, \code{\link[flextable]{as_flextable.htest}()}, +\code{\link[flextable]{as_flextable.kmeans}()}, \code{\link[flextable]{as_flextable.lm}()}, +\code{\link[flextable]{as_flextable.merMod}()}, +\code{\link[flextable]{as_flextable.pam}()}, \code{\link[flextable]{as_flextable.summarizor}()}, +\code{\link[flextable]{as_flextable.tabular}()}, \code{\link[flextable]{as_flextable.tabulator}()}, \code{\link[flextable]{as_flextable.xtable}()} } diff --git a/man/footnote_options.Rd b/man/footnote_options.Rd index b34e120..f6c0af4 100644 --- a/man/footnote_options.Rd +++ b/man/footnote_options.Rd @@ -15,14 +15,19 @@ footnote_options( ) } \arguments{ -\item{ref}{One of "1", "a", "A", "i", "I", or "*" to as a choice for a symbol to -cross-reference footnotes.} +\item{ref}{A string or a function that defines symbols of footnote references. +If the value is string, it must be one of the "1", "a", "A", "i", "I", or +"*". If a function, keep in mind this is an experimental feature. It +receives an integer vector as an input, and returns a character vector +with the length equal to the input. The returned values will further be +processed as markdown strings.} -\item{prefix, suffix}{Pre- and suf-fixes for \code{ref} (default: \code{""}).} +\item{prefix, suffix}{Pre- and suf-fixes for \code{ref} (default: \code{""}). These parameters are used +if and only if ref is a character.} \item{start}{A starting number of footnotes.} -\item{max}{A max number of footnotes.} +\item{max}{A max number of footnotes used only when \code{ref} is "a" or "A".} \item{inline}{whether to add footnote on same line as previous footnote or not} @@ -36,6 +41,52 @@ An environment Configure options for footnotes. } \examples{ -o <- footnote_options("1", start = 1L) +# A examole flextable with unprocessed markdown footnotes +ft <- as_flextable(tibble::tibble( + "header1^[note a]" = c("x^[note 1]", "y"), + "header2" = c("a", "b^[note 2]") +)) +# Render all footnotes in the same format. +if (rmarkdown::pandoc_available()) { + ft \%>\% + colformat_md( + part = "all", + .footnote_options = footnote_options("1", start = 1L) + ) +} + +# Use a user-defined function to format footnote symbols +if (rmarkdown::pandoc_available()) { + # a function to format symbols of footnote references + ref <- function(n, part, footer) { + # Header uses letters and body uses integers for the symbols + s <- if (part == "header") { + letters[n] + } else { + as.character(n) + } + + # Suffix symbols with ": " (a colon and a space) in the footer + if (footer) { + return(paste(s, ":\\\\ ")) + } + + # Use superscript in the header and the body + return(paste0("^", s, "^")) + } + + # apply custom format of symbols + ft \%>\% + # process header first + colformat_md( + part = "header", .footnote_options = footnote_options(ref) + ) \%>\% + # process body next + colformat_md( + part = "body", .footnote_options = footnote_options(ref) + ) \%>\% + # tweak width for visibility + flextable::autofit(add_w = 0.2) +} }