如何在 knitr 的输出中忽略 '

How to ignore ' in output by knitr

是否可以使用 knitr 钩子或类似的东西让 knitr 忽略输出中的 ' 符号。问题是 knitr 将 ' 之后的文本突出显示为字符串。

示例:

在这个例子中,我不希望颜色变成绿色!

我在 R markdown 中使用 knitr 选项 comment=NA

无法使用以下设置重现您的错误:

<some latex packages>
\begin{document}
<<h,echo=TRUE>>=
library(knitr)
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)
cor.test(x,y,method="pearson")
@ 
\end{document}

这是我的 pdf 输出

library(knitr)
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6, 3.1, 2.5, 5.0, 3.6, 4.0, 5.2, 2.8, 3.8)
cor.test(x,y,method="pearson")

## 
## Pearson’s product-moment correlation
##
## data: x and y
## t = 1.841, df = 7, p-value = 0.1082
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.1497 0.8956
## sample estimates:
## cor
## 0.5712