在 knitr 块中写乳胶方程

Write latex equation inside knitr chunks

我正在尝试在一个块中写一个等式。我需要使用 '\sum' 但 R 不接受它。我收到错误:

'\s' is an unrecognized escape in character string

我也尝试了一些包没有成功。

如何传递这个转义字符?

示例如下:

\documentclass{article}

\begin{document}

<<results='asis',echo=FALSE>>=
#library(lazyWeave)
#library(hwriterPlus)
 #hwriteLatex(as.latex("\bar{R}_{i}=\frac{\sum_{t=1}^{T}{R_{i,t}}}{8}"))
#
cat('\bar{R}_{i}=\frac{\sum_{t=1}^{T}{R_{i,t}}}{8}')

#cat("$$","\bar{R}_{i}=\frac{\sum_{t=1}^{T}{R_{i,t}}}{8}","$$",sep="")

cat("Typically we want our paragraphs to be left
justified. This is often what we expect to see when reading.")

@

\end{document}

编辑。我读了一些类似的例子,但没有一个涉及转义字符。

您需要将转义字符加倍。

> cat('\bar{R}_{i}=\frac{\sum_{t=1}^{T}{R_{i,t}}}{8}')
\bar{R}_{i}=\frac{\sum_{t=1}^{T}{R_{i,t}}}{8}>