Last active
January 1, 2016 21:09
-
-
Save bryanmayer/8202052 to your computer and use it in GitHub Desktop.
Automatic italics into latex tables using xtable in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(xtable) | |
library(plyr) | |
fakedata = data.frame( | |
Bacteria = c("G. vaginalis", "L. crispatus"), | |
Count = log10(rlnorm(2*100, 13.5)) | |
) | |
table1 = ddply(fakedata, .(Bacteria), summarize, | |
Bacteria = paste("\\textit{",unique(Bacteria),"}", sep=""), | |
meanCount = mean(Count) | |
) | |
#the unique statement is a hack to get around a ddply grouping issue | |
# \ in front of \textit is an escape character | |
#normal xtable call | |
print(xtable(table1), include.rownames=FALSE) | |
#turning off sanitize | |
print(xtable(table1), include.rownames=FALSE, sanitize.text.function = identity) | |
#first xtable call output | |
#> print(xtable(table1), include.rownames=FALSE) | |
#% latex table generated in R 3.0.1 by xtable 1.7-1 package | |
#% Tue Dec 31 12:40:34 2013 | |
#\begin{table}[ht] | |
#\centering | |
#\begin{tabular}{lr} | |
# \hline | |
#Bacteria & meanCount \\ | |
# \hline | |
#$\backslash$textit\{G. vaginalis\} & 5.87 \\ | |
# $\backslash$textit\{L. crispatus\} & 5.87 \\ | |
# \hline | |
#\end{tabular} | |
#\end{table} | |
#second xtable call output | |
#> print(xtable(table1), include.rownames=FALSE, sanitize.text.function = identity) | |
#\begin{table}[ht] | |
#\centering | |
#\begin{tabular}{lr} | |
# \hline | |
#Bacteria & meanCount \\ | |
# \hline | |
#\textit{G. vaginalis} & 5.87 \\ | |
# \textit{L. crispatus} & 5.87 \\ | |
# \hline | |
#\end{tabular} | |
#\end{table} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment