【问题标题】:knitr: Chapter name is the name of R chunk codeknitr:章节名称是R块代码的名称
【发布时间】:2014-10-04 19:57:41
【问题描述】:

我想使用 R 块代码输出作为章节名称,但不知道如何做到这一点。下面是我的最小工作示例。

\documentclass{book}
\usepackage[T1]{fontenc}

\begin{document}

\chapter{cat(
<< label=Test1, echo=FALSE, results="asis">>=
2+1
@
)
}

Chapter name is the output of R chunk Code.

\end{document}

【问题讨论】:

  • 对于Sweave 格式我想你想使用Sexpr{}

标签: r latex knitr sweave


【解决方案1】:

这对我有用

<< label=Test1, echo=FALSE>>=
cn <- 2+1
@

\chapter*{Chapter \Sexpr{cn}}

【讨论】:

  • 感谢@Roman 的精彩回答。如果您指导我如何正确运行此代码,我将不胜感激。 &lt;&lt; label=Test1, echo=FALSE&gt;&gt;= library(noamtools) # install_github("noamtools", "noamross") cn &lt;- help_console(topic=lm, format = "text", lines=1) @ \chapter{\Sexpr{cn}} 期待您的帮助。谢谢
  • 你必须输入 {Chapter \Sexpr{cn}}`,@MYaseen208。
【解决方案2】:

在 RMarkdown 中你可以使用下面的代码

# `r I(1+2)`

【讨论】:

  • 我在考虑 Rmarkdown 他们的 \Sexpr{...}r ... 并且它适用于 Rmd。没想到...相应地编辑了我的答案
猜你喜欢
  • 1970-01-01
  • 2017-03-29
  • 2019-10-23
  • 1970-01-01
  • 2010-09-10
  • 1970-01-01
  • 2011-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多