我希望像50000
这样的数字打印在一个带有半空间作为千位分隔符的knitr文档中。在LaTeX中,我只使用50\,000
,我希望knitr通过Sexpr
命令打印它。也就是说,我希望函数reformat
在以下
\documentclass{standalone}
\begin{document}
<<>>=
num <- 50000
@
The number is \Sexpr{reformat(num)}.
\end{document}
半空间打印50 000。我遇到的问题是使用formatC
似乎不允许正确数量的反斜杠
formatC(num, format = "f", big.mark = "\,")
Error: '\,' is an unrecognized escape in character string starting ""\,"
formatC(num, format = "f", big.mark = "\\,")
[1] "50,000.0000"
formatC(num, format = "f", big.mark = "\\\,")
Error: '\,' is an unrecognized escape in character string starting ""\\\,"
代替reformat
的正确功能是什么?
答案 0 :(得分:1)
Roland和baptiste的解决方案都运行良好:
reformat <- function(num) formatC(num, format = "f", big.mark = "\\\\,")
reformat <- function(num) formatC(num, format = "f", big.mark = "\u2009")