Thats what I use, but for the column names, I need subscripts and superscripts and the occasional equation which is translated by latex.
Code:
library(xtable)
#some code manipulating data into the format i like
amscols(my.data.frame) # <- formats column names from colname to $colname$
mytable <-xtable(
my.data.frame,
caption="\\\\ \\textit{This is an example table with good latex formatting}",
label="tab:mytable",
align="cccccccccc",
digits=2
)
print.xtable(
mytable,
type="latex",
file="filepath.tex",
include.rownames=F,
table.placement="H",
size="small" ,
caption.placement="top",
sanitize.colnames.function=function(x){x} # <- lifesaver
)