Learn R Programming

miscset (version 1.0.0)

textable: Table to Latex

Description

This function enhances xtable: It can write the latex code of the table directly to a file and optionally adds a header/footer for the document structure. Also a system command can be given to convert the tex file to a pdf document, for example.

Usage

textable(d, file, caption = NULL, label = NULL, align = NULL, rownames = FALSE, topcapt = TRUE, digits = NULL, as.document = FALSE, landscape = FALSE, margin = 2, pt.size = 10, cmd = NULL, ...)

Arguments

d
Object (will be coerced to data.frame) to transform to a latex table.
file
Character string with output file name. If missing or "", the output is printed to the screen.
caption
Character vector with title of table.
label
Character vector with the latex label or HTML anchor.
align
Character vector with 'l', 'c', 'r' for aligning the columns left, centered or right. Length is either one or 1 (for rownames column) + number of columns in d (even if rownames = FALSE)
rownames
Logical, include row names of d.
topcapt
Logical, put caption and label before 'tabular'.
digits
Number of digits to print from numeric values.
as.document
Logical. TRUE to add the document definition to the output. The document class is an article and the package a4paper is included.
landscape
Logical, use a landscape format for wider tables. Only with as.document=TRUE.
margin
Margin between table and page border in cm. Only with as.document=TRUE.
pt.size
Integer from 10 to 13 for the size of the characters. Only with as.document=TRUE.
cmd
A character vector with the system command to apply on the output file. Only if file is given and as.document is TRUE. NULL or an empty string system is not called.
...
Forwarded arguments to print.xtable.

Value

Returns a character vector invisible. If file is set, then the content is written to a file. Else it is printed to the console.

Details

Example for a system call: cmd = "pdflatex -output-directory /path/to/files/"

See Also

xtable

Examples

Run this code
#

## Not run: 
# d <- head(trees)
# dc <- 'R "trees" dataset.'
# textable(d, rownames=TRUE, digits=4, caption=dc)
# textable(d, '/tmp/trees.tex', caption=dc, as.document=TRUE, 
#   cmd='pdflatex --output-directory /tmp')
# ## End(Not run)

#

Run the code above in your browser using DataLab