问题
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