Create a table
Creates a Pandoc's markdown style table with optional caption and some other tweaks. See 'Details' below.
pandoc.table.return(t, caption, digits = panderOptions("digits"), decimal.mark = panderOptions("decimal.mark"), big.mark = panderOptions("big.mark"), round = panderOptions("round"), missing = panderOptions("missing"), justify, style = c("multiline", "grid", "simple", "rmarkdown", "jira"), split.tables = panderOptions("table.split.table"), split.cells = panderOptions("table.split.cells"), keep.trailing.zeros = panderOptions("keep.trailing.zeros"), keep.line.breaks = panderOptions("keep.line.breaks"), plain.ascii = panderOptions("plain.ascii"), use.hyphening = panderOptions("use.hyphening"), row.names, col.names, emphasize.rownames = panderOptions("table.emphasize.rownames"), emphasize.rows, emphasize.cols, emphasize.cells, emphasize.strong.rows, emphasize.strong.cols, emphasize.strong.cells, emphasize.italics.rows, emphasize.italics.cols, emphasize.italics.cells, emphasize.verbatim.rows, emphasize.verbatim.cols, emphasize.verbatim.cells, ...)
t |
data frame, matrix or table |
caption |
caption (string) to be shown under the table |
digits |
passed to |
decimal.mark |
passed to |
big.mark |
passed to |
round |
passed to |
missing |
string to replace missing values |
justify |
defines alignment in cells passed to |
style |
which Pandoc style to use: |
split.tables |
where to split wide tables to separate tables. The default value ( |
split.cells |
where to split cells' text with line breaks. Default to |
keep.trailing.zeros |
to show or remove trailing zeros in numbers on a column basis width |
keep.line.breaks |
(default: |
plain.ascii |
(default: |
use.hyphening |
boolean (default: |
row.names |
if |
col.names |
a character vector of column names to be used in the table |
emphasize.rownames |
boolean (default: |
emphasize.rows |
deprecated for |
emphasize.cols |
deprecated for |
emphasize.cells |
deprecated for |
emphasize.strong.rows |
see |
emphasize.strong.cols |
see |
emphasize.strong.cells |
see |
emphasize.italics.rows |
a vector for a two dimensional table specifying which rows to emphasize |
emphasize.italics.cols |
a vector for a two dimensional table specifying which cols to emphasize |
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. |
emphasize.verbatim.rows |
see |
emphasize.verbatim.cols |
see |
emphasize.verbatim.cells |
see |
... |
unsupported extra arguments directly placed into |
This function takes any tabular data as its first argument and will try to make it pretty like: rounding and applying digits
and custom decimal.mark
to numbers, auto-recognizing if row names should be included, setting alignment of cells and dropping trailing zeros by default.
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.
For more details please see the parameters above and passed arguments of panderOptions
.
By default this function outputs (see: cat
) the result. If you would want to catch the result instead, then call pandoc.table.return
instead.
If caption
is missing, then the value is first checked in t
object's caption
attribute and if not found in an internal buffer set by link{set.caption}
. justify
parameter works similarly, see set.alignment
for details.
John MacFarlane (2012): _Pandoc User's Guide_. http://johnmacfarlane.net/pandoc/README.html
pandoc.table(mtcars) # caption pandoc.table(mtcars, 'Motor Trend Car Road Tests') # other input/output formats pandoc.table(mtcars[, 1:3], decimal.mark = ',') pandoc.table(mtcars[, 1:3], decimal.mark = ',', justify = 'right') pandoc.table(matrix(sample(1:1000, 25), 5, 5)) pandoc.table(matrix(runif(25), 5, 5)) pandoc.table(matrix(runif(25), 5, 5), digits = 5) pandoc.table(matrix(runif(25),5,5), round = 1) pandoc.table(table(mtcars$am)) pandoc.table(table(mtcars$am, mtcars$gear)) pandoc.table(table(state.division, state.region)) pandoc.table(table(state.division, state.region), justify = 'centre') m <- data.frame(a = c(1, -500, 10320, 23, 77), b = runif(5), c = c('a', 'bb', 'ccc', 'dddd', 'eeeee')) pandoc.table(m) pandoc.table(m, justify = c('right', 'left', 'centre')) pandoc.table(m, justify = 'rlc') # Same as upper statement ## splitting up too wide tables pandoc.table(mtcars) pandoc.table(mtcars, caption = 'Only once after the first part!') ## tables with line breaks in cells ## NOTE: line breaks are removed from table content in case keep.line.breaks is set to FALSE ## and added automatically based on "split.cells" parameter! t <- data.frame(a = c('hundreds\nof\nmouses', '3 cats'), b=c('FOO is nice', 'BAR\nBAR2')) pandoc.table(t) pandoc.table(t, split.cells = 5) ## exporting tables in other Pandoc styles pandoc.table(m) pandoc.table(m, style = "grid") pandoc.table(m, style = "simple") pandoc.table(t, style = "grid") pandoc.table(t, style = "grid", split.cells = 5) tryCatch(pandoc.table(t, style = "simple", split.cells = 5), error = function(e) 'Yeah, no newline support in simple tables') ## highlight cells t <- mtcars[1:3, 1:5] pandoc.table(t$mpg, emphasize.italics.cells = 1) pandoc.table(t$mpg, emphasize.strong.cells = 1) pandoc.table(t$mpg, emphasize.italics.cells = 1, emphasize.strong.cells = 1) pandoc.table(t$mpg, emphasize.italics.cells = 1:2) pandoc.table(t$mpg, emphasize.strong.cells = 1:2) pandoc.table(t, emphasize.italics.cells = which(t > 20, arr.ind = TRUE)) pandoc.table(t, emphasize.italics.cells = which(t == 6, arr.ind = TRUE)) pandoc.table(t, emphasize.verbatim.cells = which(t == 6, arr.ind = TRUE)) pandoc.table(t, emphasize.verbatim.cells = which(t == 6, arr.ind = TRUE), emphasize.italics.rows = 1) ## with helpers emphasize.cols(1) emphasize.rows(1) pandoc.table(t) emphasize.strong.cells(which(t > 20, arr.ind = TRUE)) pandoc.table(t) ### plain.ascii pandoc.table(mtcars[1:3, 1:3], plain.ascii = TRUE) ### keep.line.breaks x <- data.frame(a="Pandoc\nPackage") pandoc.table(x) pandoc.table(x, keep.line.breaks = TRUE) ## split.cells x <- data.frame(a = "foo bar", b = "foo bar") pandoc.table(x, split.cells = 4) pandoc.table(x, split.cells = 7) pandoc.table(x, split.cells = c(4, 7)) pandoc.table(x, split.cells = c("20%", "80%"), split.tables = 30) y <- c("aa aa aa", "aaa aaa", "a a a a a", "aaaaa", "bbbb bbbb bbbb", "bb bbb bbbb") y <- matrix(y, ncol = 3, nrow = 2) rownames(y) <- c("rowname one", "rowname two") colnames(y) <- c("colname one", "colname two", "colname three") pandoc.table(y, split.cells = 2) pandoc.table(y, split.cells = 6) pandoc.table(y, split.cells = c(2, 6, 10)) pandoc.table(y, split.cells = c(2, Inf, Inf)) ## first value used for rownames pander(y, split.cells = c(5, 2, Inf, Inf)) pandoc.table(y, split.cells = c(5, 2, Inf, 5, 3, 10)) ## when not enough reverting to default values pandoc.table(y, split.cells = c(5, 2)) ## split.cells with hyphenation x <- data.frame(a = "Can be also supplied as a vector, for each cell separately", b = "Can be also supplied as a vector, for each cell separately") pandoc.table(x, split.cells = 10, use.hyphening = TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.