md_data: Create Markdown table from data frame

Description Usage Arguments Details Value Examples

Description

Converts a dataframe or matrix into a markdown table format.

Usage

1
2
md_data(x, row.index = NA, col.index = NA, row.names = NA, header = NA,
  align = NULL)

Arguments

x

An R object, typically a matrix or data frame

row.index, col.index

A numeric vector correspond to the index position of the rows/columns to be included. By default, all columns and rows are included.

row.names

Logical: whether to include row names. By default, row names are included if rownames(x) is neither NULL nor identical to 1:nrow(x).

header

A character vector of length = ncol to be used for the header of the table. If provided, the original header will be replaced.

align

Column alignment: a character vector consisting of 'l' (left), 'c' (center) and/or 'r' (right). By default or if align = NULL, numeric columns are right-aligned, and other columns are left-aligned. If align = 'l', all columns are left aligned. e.t.c.

Details

The output markdown source code is stored as character vector in R. It can be further copied and pasted for other usage.

Value

A character vector of the table source code.

Examples

1
2
3
4
5
6
z <- head(mtcars)
md_data(z)
md_data(z, 1:3,1:3)
md_data(z, 1:3,1:3, row.names = FALSE)
md_data(z, 1:3,1:3, row.names = FALSE, header = c("foo","bin","ha"))
md_data(z, 1:3,1:3, header = c("foo","bin","ha"), align = "c")

UBC-MDS/tidyplusR documentation built on May 25, 2019, 1:36 p.m.