John
John

Reputation: 1947

Is there any possibility to save kable table in .tex or .markdown?

Let's consider very simple kable table for reproducible example:

df <- data.frame("X_1" = c(1, 2), "X_2" =c(3,4))
df <- kable(df, format = 'latex')
df

\begin{tabular}{r|r}
\hline
X\_1 & X\_2\\
\hline
1 & 3\\
\hline
2 & 4\\
\hline
\end{tabular}

Is there any possibility to have this file saved as .tex or .markdown ? I looked for function save_kable but it seems that it only supports .png, .pdf or .jpeg formats.

Upvotes: 6

Views: 4508

Answers (2)

BlueJ
BlueJ

Reputation: 61

i am using save_kable and specifying tex with no problems e.g. %>% save_kable(paste(resultspath,"DescTableStroops.tex"),float = FALSE)

Upvotes: 6

Yihui Xie
Yihui Xie

Reputation: 30104

knitr::kable() returns a character vector, which you can definitely write to a file, e.g.,

df <- data.frame("X_1" = c(1, 2), "X_2" =c(3,4))
df <- knitr::kable(df, format = 'latex')
writeLines(df, 'df.tex')

Upvotes: 9

Related Questions