Max*_*m.K 12 r syntax-highlighting knitr
我找不到有关是否可以在knitr中指定内联块的选项的信息.我只是尝试指定它们,就像在常规块中一样,但这会产生错误.
我需要的是在PDF中包含突出显示的R代码,但不进行评估.由于上下文的格式,这只能在内联块中发生.或许还有另一种方法可以包含突出显示的代码.
举一个例子,我需要以下几点:
Some text about something with `r eval=FALSE 1+1` inside the sentence.
Run Code Online (Sandbox Code Playgroud)
这个特殊的语法给出:
Error in parse(text = code, keep.source = FALSE) :
<text>:1:11: unexpected ','
1: eval=FALSE,
Run Code Online (Sandbox Code Playgroud)
感谢Yihui,你可以做到,
\documentclass{article}
<<setup, include=FALSE>>=
knit_hooks$set(inline = function(x) {
if (is.numeric(x)) return(knitr:::format_sci(x, 'latex'))
knitr:::hi_latex(x)
})
@
\begin{document}
the value of $\pi$ is \Sexpr{pi}, and the function to read a table is
\Sexpr{'read.table()'}.
<<test2>>=
rnorm(10)
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2626 次 |
| 最近记录: |