我想在LaTeX文件中包含R中的数据表。我使用xtable
,问题是函数sanitize.text.function
无法正常工作。 MWE:
> a <- matrix(c("name & surname", 12345), ncol = 2)
[,1] [,2]
[1,] "name & surname" "12345"
> print.xtable(xtable(a), type = "latex", sanitize.text.function = function(x){x}, file = "../R_out/prova.tex")
\begin{table}[ht]
\centering
\begin{tabular}{rll}
\hline
& 1 & 2 \\
\hline
1 & name & surname & 12345 \\
\hline
\end{tabular}
\end{table}
正如您所看到的,&
超出了{。}}。
我在stackoverflow上找到的唯一其他类似问题涉及选项sanitize.text.function
的位置,但在我的情况下,它应该正确放置。你能在这里看到问题吗?