exportDF {rodeo} | R Documentation |
Export a Data Frame as HTML/TEX Code
Description
Generates code to include tabular data in a tex document or web site.
Usage
exportDF(
x,
tex = FALSE,
colnames = NULL,
width = NULL,
align = NULL,
funHead = NULL,
funCell = NULL,
lines = TRUE,
indent = 2
)
Arguments
x |
The data frame being exported. |
tex |
Logical. Allows to switch between generation of TEX code and HTML. |
colnames |
Displayed column names. If |
width |
Either |
align |
Either |
funHead |
Either |
funCell |
Like |
lines |
Logical. Switches table borders on/off. |
indent |
Integer. Number of blanks used to indent the generated code. |
Value
A character string (usually needs to be exported to a file).
Note
The functions funHead
and funCell
are useful to apply
formatting or character replacement. For example, one could use
function(x) {paste0("\\bold{",toupper(x),"}")}
to generate bold, uppercase column names in a TEX table.
Author(s)
David Kneis david.kneis@tu-dresden.de
See Also
The xtable
packages provides similar functionality with
more sophisticated options. Consider the 'pandoc' software do convert
documents from one markup language to another one. Finally, consider the
latex package 'datatools' for direct inclusion of delimited text files
(e.g. produced by write.table
) in tex documents.
Examples
# Create example table
df <- data.frame(stringsAsFactors=FALSE, name= c("growth", "dead"),
unit= c("1/d","1/d"), expression= c("r * N * (1 - N/K)"," d * N"))
# Export as TEX: header in bold, 1st colum in italics, last column as math
tex <- exportDF(df, tex=TRUE,
colnames=c(expression="process rate expression"),
width=c(expression=0.5),
align=c(expression="p"),
funHead=setNames(replicate(ncol(df),
function(x){paste0("\\textbf{",x,"}")}),names(df)),
funCell=c(name=function(x){paste0("\\textit{",x,"}")},
expression=function(x){paste0("$",x,"$")})
)
cat(tex,"\n")
# Export as HTML: non-standard colors are used for all columns
tf <- tempfile(fileext=".html")
write(x= exportDF(df, tex=FALSE,
funHead=setNames(replicate(ncol(df),
function(x){paste0("<font color='red'>",x,"</font>")}),names(df)),
funCell=setNames(replicate(ncol(df),
function(x){paste0("<font color='blue'>",x,"</font>")}),names(df))
), file=tf)
## Not run:
browseURL(tf)
file.remove(tf)
## End(Not run)