knitr: Chapter name is the name of R chunk code

余生长醉 提交于 2019-12-11 06:29:23

问题


I want to use the R chunk code output as the Chapter Name but could not figured out how to do this. Below is my minimum working example.

\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}

回答1:


This works for me

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

\chapter*{Chapter \Sexpr{cn}}



回答2:


In RMarkdown you can use the following code

# `r I(1+2)`


来源:https://stackoverflow.com/questions/26196609/knitr-chapter-name-is-the-name-of-r-chunk-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!