DavidC
DavidC

Reputation: 377

knitr - change code indentation

I am working on a two-column (Rnw, latex) document where the width is at a premium. By default knitr indents the code blocks by 4 spaces. How can I reduce this default indentation?

Many thanks David

Upvotes: 6

Views: 1100

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30194

Either do not reformat the code (use the chunk option tidy=FALSE) and manually indent by two spaces,

<<tidy=FALSE>>=
if (TRUE) {
  # code here
}
@

or set the R option reindent.spaces to a smaller value, e.g.

options(reindent.spaces = 2)

This option is passed to the formatR package to reindent your code, and knitr uses formatR to reformat your R code by default.

Upvotes: 3

Related Questions