Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knitr - change code indentation

Tags:

r

knitr

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

like image 873
DavidC Avatar asked Jul 05 '13 08:07

DavidC


1 Answers

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.

like image 51
Yihui Xie Avatar answered Oct 14 '22 05:10

Yihui Xie