| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/pandoc.R |
| 3 |
\name{pandoc.table.return} |
| 4 |
\alias{pandoc.table.return} |
| 5 |
\alias{pandoc.table} |
| 6 |
\title{Create a table} |
| 7 |
\usage{ |
| 8 |
pandoc.table.return( |
| 9 |
t, |
| 10 |
caption, |
| 11 |
digits = panderOptions("digits"), |
| 12 |
decimal.mark = panderOptions("decimal.mark"), |
| 13 |
big.mark = panderOptions("big.mark"), |
| 14 |
round = panderOptions("round"), |
| 15 |
missing = panderOptions("missing"), |
| 16 |
justify, |
| 17 |
style = c("multiline", "grid", "simple", "rmarkdown", "jira"), |
| 18 |
split.tables = panderOptions("table.split.table"), |
| 19 |
split.cells = panderOptions("table.split.cells"), |
| 20 |
keep.trailing.zeros = panderOptions("keep.trailing.zeros"), |
| 21 |
keep.line.breaks = panderOptions("keep.line.breaks"), |
| 22 |
plain.ascii = panderOptions("plain.ascii"), |
| 23 |
use.hyphening = panderOptions("use.hyphening"), |
| 24 |
row.names, |
| 25 |
col.names, |
| 26 |
emphasize.rownames = panderOptions("table.emphasize.rownames"), |
| 27 |
emphasize.rows, |
| 28 |
emphasize.cols, |
| 29 |
emphasize.cells, |
| 30 |
emphasize.strong.rows, |
| 31 |
emphasize.strong.cols, |
| 32 |
emphasize.strong.cells, |
| 33 |
emphasize.italics.rows, |
| 34 |
emphasize.italics.cols, |
| 35 |
emphasize.italics.cells, |
| 36 |
emphasize.verbatim.rows, |
| 37 |
emphasize.verbatim.cols, |
| 38 |
emphasize.verbatim.cells, |
| 39 |
... |
| 40 |
) |
| 41 |
} |
| 42 |
\arguments{ |
| 43 |
\item{t}{data frame, matrix or table} |
| 44 |
|
| 45 |
\item{caption}{caption (string) to be shown under the table} |
| 46 |
|
| 47 |
\item{digits}{passed to \code{format}. Can be a vector specifying values for each column (has to be the same length as number of columns).} |
| 48 |
|
| 49 |
\item{decimal.mark}{passed to \code{format}} |
| 50 |
|
| 51 |
\item{big.mark}{passed to \code{format}} |
| 52 |
|
| 53 |
\item{round}{passed to \code{round}. Can be a vector specifying values for each column (has to be the same length as number of columns). Values for non-numeric columns will be disregarded.} |
| 54 |
|
| 55 |
\item{missing}{string to replace missing values} |
| 56 |
|
| 57 |
\item{justify}{defines alignment in cells passed to \code{format}. Can be \code{left}, \code{right} or \code{centre}, which latter can be also spelled as \code{center}. Defaults to \code{centre}. Can be abbreviated to a string consisting of the letters \code{l}, \code{c} and \code{r} (e.g. 'lcr' instead of c('left', 'centre', 'right').} |
| 58 |
|
| 59 |
\item{style}{which Pandoc style to use: \code{simple}, \code{multiline}, \code{grid} or \code{rmarkdown}} |
| 60 |
|
| 61 |
\item{split.tables}{where to split wide tables to separate tables. The default value (\code{80}) suggests the conventional number of characters used in a line, feel free to change (e.g. to \code{Inf} to disable this feature) if you are not using a VT100 terminal any more :)} |
| 62 |
|
| 63 |
\item{split.cells}{where to split cells' text with line breaks. Default to \code{30}, to disable set to \code{Inf}. Can be also supplied as a vector, for each cell separately (if length(split.cells) == number of columns + 1, then first value in split.cells if for row names, and others are for columns). Supports relative (percentage) parameters in combination with split.tables.} |
| 64 |
|
| 65 |
\item{keep.trailing.zeros}{to show or remove trailing zeros in numbers on a column basis width} |
| 66 |
|
| 67 |
\item{keep.line.breaks}{(default: \code{FALSE}) if to keep or remove line breaks from cells in a table} |
| 68 |
|
| 69 |
\item{plain.ascii}{(default: \code{FALSE}) if output should be in plain ascii (without markdown markup) or not} |
| 70 |
|
| 71 |
\item{use.hyphening}{boolean (default: \code{FALSE}) if try to use hyphening when splitting large cells according to table.split.cells. Requires \pkg{sylly}.} |
| 72 |
|
| 73 |
\item{row.names}{if \code{FALSE}, row names are suppressed. A character vector of row names can also be specified here. By default, row names are included if \code{rownames(t)} is neither |
| 74 |
\code{NULL} nor identical to \code{1:nrow(x)}} |
| 75 |
|
| 76 |
\item{col.names}{a character vector of column names to be used in the table} |
| 77 |
|
| 78 |
\item{emphasize.rownames}{boolean (default: \code{TRUE}) if row names should be highlighted} |
| 79 |
|
| 80 |
\item{emphasize.rows}{deprecated for \code{emphasize.italics.rows} argument} |
| 81 |
|
| 82 |
\item{emphasize.cols}{deprecated for \code{emphasize.italics.cols} argument} |
| 83 |
|
| 84 |
\item{emphasize.cells}{deprecated for \code{emphasize.italics.cells} argument} |
| 85 |
|
| 86 |
\item{emphasize.strong.rows}{see \code{emphasize.italics.rows} but in bold} |
| 87 |
|
| 88 |
\item{emphasize.strong.cols}{see \code{emphasize.italics.cols} but in bold} |
| 89 |
|
| 90 |
\item{emphasize.strong.cells}{see \code{emphasize.italics.cells} but in bold} |
| 91 |
|
| 92 |
\item{emphasize.italics.rows}{a vector for a two dimensional table specifying which rows to emphasize} |
| 93 |
|
| 94 |
\item{emphasize.italics.cols}{a vector for a two dimensional table specifying which cols to emphasize} |
| 95 |
|
| 96 |
\item{emphasize.italics.cells}{a vector for one-dimensional tables or a matrix like structure with two columns for row and column indexes to be emphasized in two dimensional tables. See e.g. \code{which(..., arr.ind = TRUE)}} |
| 97 |
|
| 98 |
\item{emphasize.verbatim.rows}{see \code{emphasize.italics.rows} but in verbatim} |
| 99 |
|
| 100 |
\item{emphasize.verbatim.cols}{see \code{emphasize.italics.cols} but in verbatim} |
| 101 |
|
| 102 |
\item{emphasize.verbatim.cells}{see \code{emphasize.italics.cells} but in verbatim} |
| 103 |
|
| 104 |
\item{...}{unsupported extra arguments directly placed into \code{/dev/null}} |
| 105 |
} |
| 106 |
\value{ |
| 107 |
By default this function outputs (see: \code{cat}) the result. If you would want to catch the result instead, then call \code{pandoc.table.return} instead. |
| 108 |
} |
| 109 |
\description{ |
| 110 |
Creates a Pandoc's markdown style table with optional caption and some other tweaks. See 'Details' below. |
| 111 |
} |
| 112 |
\details{ |
| 113 |
This function takes any tabular data as its first argument and will try to make it pretty like: rounding and applying \code{digits} and custom \code{decimal.mark} to numbers, auto-recognizing if row names should be included, setting alignment of cells and dropping trailing zeros by default. |
| 114 |
|
| 115 |
\code{pandoc.table} also tries to split large cells with line breaks or even the whole table to separate parts on demand. Other arguments lets the use to highlight some rows/cells/cells in the table with italic or bold text style. |
| 116 |
|
| 117 |
For more details please see the parameters above and passed arguments of \code{\link{panderOptions}}. |
| 118 |
} |
| 119 |
\note{ |
| 120 |
If \code{caption} is missing, then the value is first checked in \code{t} object's \code{caption} attribute and if not found in an internal buffer set by \code{link{set.caption}}. \code{justify} parameter works similarly, see \code{\link{set.alignment}} for details. |
| 121 |
} |
| 122 |
\examples{ |
| 123 |
pandoc.table(mtcars) |
| 124 |
|
| 125 |
# caption |
| 126 |
pandoc.table(mtcars, 'Motor Trend Car Road Tests') |
| 127 |
|
| 128 |
# other input/output formats |
| 129 |
pandoc.table(mtcars[, 1:3], decimal.mark = ',') |
| 130 |
pandoc.table(mtcars[, 1:3], decimal.mark = ',', justify = 'right') |
| 131 |
pandoc.table(matrix(sample(1:1000, 25), 5, 5)) |
| 132 |
pandoc.table(matrix(runif(25), 5, 5)) |
| 133 |
pandoc.table(matrix(runif(25), 5, 5), digits = 5) |
| 134 |
pandoc.table(matrix(runif(25),5,5), round = 1) |
| 135 |
pandoc.table(table(mtcars$am)) |
| 136 |
pandoc.table(table(mtcars$am, mtcars$gear)) |
| 137 |
pandoc.table(table(state.division, state.region)) |
| 138 |
pandoc.table(table(state.division, state.region), justify = 'centre') |
| 139 |
|
| 140 |
m <- data.frame(a = c(1, -500, 10320, 23, 77), |
| 141 |
b = runif(5), |
| 142 |
c = c('a', 'bb', 'ccc', 'dddd', 'eeeee')) |
| 143 |
pandoc.table(m) |
| 144 |
pandoc.table(m, justify = c('right', 'left', 'centre')) |
| 145 |
pandoc.table(m, justify = 'rlc') # Same as upper statement |
| 146 |
|
| 147 |
## splitting up too wide tables |
| 148 |
pandoc.table(mtcars) |
| 149 |
pandoc.table(mtcars, caption = 'Only once after the first part!') |
| 150 |
|
| 151 |
## tables with line breaks in cells |
| 152 |
## NOTE: line breaks are removed from table content in case keep.line.breaks is set to FALSE |
| 153 |
## and added automatically based on "split.cells" parameter! |
| 154 |
t <- data.frame(a = c('hundreds\nof\nmouses', '3 cats'), b=c('FOO is nice', 'BAR\nBAR2')) |
| 155 |
pandoc.table(t) |
| 156 |
pandoc.table(t, split.cells = 5) |
| 157 |
|
| 158 |
## exporting tables in other Pandoc styles |
| 159 |
pandoc.table(m) |
| 160 |
pandoc.table(m, style = "grid") |
| 161 |
pandoc.table(m, style = "simple") |
| 162 |
pandoc.table(t, style = "grid") |
| 163 |
pandoc.table(t, style = "grid", split.cells = 5) |
| 164 |
tryCatch(pandoc.table(t, style = "simple", split.cells = 5), |
| 165 |
error = function(e) 'Yeah, no newline support in simple tables') |
| 166 |
|
| 167 |
## highlight cells |
| 168 |
t <- mtcars[1:3, 1:5] |
| 169 |
pandoc.table(t$mpg, emphasize.italics.cells = 1) |
| 170 |
pandoc.table(t$mpg, emphasize.strong.cells = 1) |
| 171 |
pandoc.table(t$mpg, emphasize.italics.cells = 1, emphasize.strong.cells = 1) |
| 172 |
pandoc.table(t$mpg, emphasize.italics.cells = 1:2) |
| 173 |
pandoc.table(t$mpg, emphasize.strong.cells = 1:2) |
| 174 |
pandoc.table(t, emphasize.italics.cells = which(t > 20, arr.ind = TRUE)) |
| 175 |
pandoc.table(t, emphasize.italics.cells = which(t == 6, arr.ind = TRUE)) |
| 176 |
pandoc.table(t, emphasize.verbatim.cells = which(t == 6, arr.ind = TRUE)) |
| 177 |
pandoc.table(t, emphasize.verbatim.cells = which(t == 6, arr.ind = TRUE), |
| 178 |
emphasize.italics.rows = 1) |
| 179 |
## with helpers |
| 180 |
emphasize.cols(1) |
| 181 |
emphasize.rows(1) |
| 182 |
pandoc.table(t) |
| 183 |
|
| 184 |
emphasize.strong.cells(which(t > 20, arr.ind = TRUE)) |
| 185 |
pandoc.table(t) |
| 186 |
|
| 187 |
### plain.ascii |
| 188 |
pandoc.table(mtcars[1:3, 1:3], plain.ascii = TRUE) |
| 189 |
|
| 190 |
### keep.line.breaks |
| 191 |
x <- data.frame(a="Pandoc\nPackage") |
| 192 |
pandoc.table(x) |
| 193 |
pandoc.table(x, keep.line.breaks = TRUE) |
| 194 |
|
| 195 |
## split.cells |
| 196 |
x <- data.frame(a = "foo bar", b = "foo bar") |
| 197 |
pandoc.table(x, split.cells = 4) |
| 198 |
pandoc.table(x, split.cells = 7) |
| 199 |
pandoc.table(x, split.cells = c(4, 7)) |
| 200 |
pandoc.table(x, split.cells = c("20\%", "80\%"), split.tables = 30) |
| 201 |
|
| 202 |
y <- c("aa aa aa", "aaa aaa", "a a a a a", "aaaaa", "bbbb bbbb bbbb", "bb bbb bbbb") |
| 203 |
y <- matrix(y, ncol = 3, nrow = 2) |
| 204 |
rownames(y) <- c("rowname one", "rowname two") |
| 205 |
colnames(y) <- c("colname one", "colname two", "colname three") |
| 206 |
pandoc.table(y, split.cells = 2) |
| 207 |
pandoc.table(y, split.cells = 6) |
| 208 |
pandoc.table(y, split.cells = c(2, 6, 10)) |
| 209 |
pandoc.table(y, split.cells = c(2, Inf, Inf)) |
| 210 |
|
| 211 |
## first value used for rownames |
| 212 |
pander(y, split.cells = c(5, 2, Inf, Inf)) |
| 213 |
pandoc.table(y, split.cells = c(5, 2, Inf, 5, 3, 10)) |
| 214 |
|
| 215 |
## when not enough reverting to default values |
| 216 |
pandoc.table(y, split.cells = c(5, 2)) |
| 217 |
|
| 218 |
## split.cells with hyphenation |
| 219 |
x <- data.frame(a = "Can be also supplied as a vector, for each cell separately", |
| 220 |
b = "Can be also supplied as a vector, for each cell separately") |
| 221 |
pandoc.table(x, split.cells = 10, use.hyphening = TRUE) |
| 222 |
} |
| 223 |
\references{ |
| 224 |
John MacFarlane (2012): _Pandoc User's Guide_. \url{https://johnmacfarlane.net/pandoc/README.html} |
| 225 |
} |
| 226 |
\seealso{ |
| 227 |
\code{\link{set.caption}}, \code{\link{set.alignment}} |
| 228 |
} |