Hao Zhu | cdd7f92 | 2018-01-08 11:39:40 -0500 | [diff] [blame] | 1 | #' Footnote marker |
Hao Zhu | e0782ab | 2018-01-09 13:24:13 -0500 | [diff] [blame^] | 2 | #' |
| 3 | #' @description Put footnote mark in superscription in table. Unless you are |
| 4 | #' using it in the `caption` of `kable`, you will need to put `escape = F` |
| 5 | #' in `kable` (similar with `cell_spec`). Again, similar with `cell_spec`, the |
| 6 | #' `format` option here can read default value from global option |
| 7 | #' `knitr.table.format`. |
| 8 | #' |
| 9 | #' @param x a number. For example, for `footnote_marker_alphabet(2)` will |
| 10 | #' return "b" in HTML. |
| 11 | #' @param format Either `html` or `latex`. All functions here can read |
| 12 | #' default value from global option `knitr.table.format`. |
| 13 | #' |
Hao Zhu | 1ac13ad | 2018-01-08 16:12:24 -0500 | [diff] [blame] | 14 | #' @export |
| 15 | footnote_marker_number <- function(x, format) { |
| 16 | if (missing(format) || is.null(format)) { |
| 17 | format <- getOption('knitr.table.format') |
| 18 | } |
| 19 | if (is.null(format)) { |
| 20 | message("Setting footnote_marker_number format as html") |
| 21 | format <- "html" |
| 22 | } |
| 23 | if (format == "html") { |
| 24 | return(paste0("<sup>", x, "</sup>")) |
| 25 | } else { |
Hao Zhu | 19c4fa5 | 2018-01-09 12:01:14 -0500 | [diff] [blame] | 26 | return(paste0("\\textsuperscript{", x, "}")) |
Hao Zhu | 1ac13ad | 2018-01-08 16:12:24 -0500 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
Hao Zhu | e0782ab | 2018-01-09 13:24:13 -0500 | [diff] [blame^] | 30 | #' @rdname footnote_marker_number |
Hao Zhu | 1ac13ad | 2018-01-08 16:12:24 -0500 | [diff] [blame] | 31 | #' @export |
| 32 | footnote_marker_alphabet <- function(x, format) { |
| 33 | if (missing(format) || is.null(format)) { |
| 34 | format <- getOption('knitr.table.format') |
| 35 | } |
| 36 | if (is.null(format)) { |
| 37 | message("Setting footnote_marker_alphabet format as html") |
| 38 | format <- "html" |
| 39 | } |
| 40 | if (is.numeric(x)) x <- letters[x] |
| 41 | if (format == "html") { |
| 42 | return(paste0("<sup>", x, "</sup>")) |
| 43 | } else { |
Hao Zhu | 19c4fa5 | 2018-01-09 12:01:14 -0500 | [diff] [blame] | 44 | return(paste0("\\textsuperscript{", x, "}")) |
Hao Zhu | 1ac13ad | 2018-01-08 16:12:24 -0500 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
Hao Zhu | e0782ab | 2018-01-09 13:24:13 -0500 | [diff] [blame^] | 48 | #' @rdname footnote_marker_number |
Hao Zhu | 1ac13ad | 2018-01-08 16:12:24 -0500 | [diff] [blame] | 49 | #' @export |
| 50 | footnote_marker_symbol <- function(x, format) { |
| 51 | if (missing(format) || is.null(format)) { |
| 52 | format <- getOption('knitr.table.format') |
| 53 | } |
| 54 | if (is.null(format)) { |
| 55 | message("Setting footnote_marker_symbol format as html") |
| 56 | format <- "html" |
| 57 | } |
| 58 | number_index <- read.csv(system.file("symbol_index.csv", |
| 59 | package = "kableExtra")) |
| 60 | if (format == "html") { |
| 61 | x <- number_index$symbol.html[x] |
| 62 | return(paste0("<sup>", x, "</sup>")) |
| 63 | } else { |
| 64 | x <- number_index$symbol.latex[x] |
Hao Zhu | 19c4fa5 | 2018-01-09 12:01:14 -0500 | [diff] [blame] | 65 | return(paste0("\\textsuperscript{", x, "}")) |
Hao Zhu | 1ac13ad | 2018-01-08 16:12:24 -0500 | [diff] [blame] | 66 | } |
| 67 | } |