View source: R/plainMethod_exportDF.r
exportDF | R Documentation |
Generates code to include tabular data in a tex document or web site.
exportDF(
x,
tex = FALSE,
colnames = NULL,
width = NULL,
align = NULL,
funHead = NULL,
funCell = NULL,
lines = TRUE,
indent = 2
)
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. |
A character string (usually needs to be exported to a file).
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.
David Kneis david.kneis@tu-dresden.de
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.