MYaseen208
MYaseen208

Reputation: 23898

knitr: Chapter name is the name of R chunk code

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}

Upvotes: 1

Views: 168

Answers (2)

Rentrop
Rentrop

Reputation: 21497

In RMarkdown you can use the following code

# `r I(1+2)`

Upvotes: 2

Roman Luštrik
Roman Luštrik

Reputation: 70623

This works for me

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

\chapter*{Chapter \Sexpr{cn}}

Upvotes: 3

Related Questions