Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linebreaks with knitr [duplicate]

Tags:

r

latex

knitr

Possible Duplicate:
Adding a line break to code blocks in R Markdown

Is there any option in knitr to preserve linebreaks in R code? After compiling the document, the code should be displayed like in the following example:

\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

<<hist>>=
df <- data.frame(x=rnorm(100,100,20))
library(lattice)
histogram(~x,
      df,
      main="histogram",
      nint=20)
@ 

\end{document}

Thanks for your help!

like image 482
beginneR Avatar asked Jul 10 '12 20:07

beginneR


1 Answers

knitr automatically tidies the R code. So to get line breaks, set tidy=FALSE, i.e.

<<hist, tidy=FALSE>>=
df <- data.frame(x=rnorm(100,100,20))
library(lattice)
histogram(~x,
      df,
      main="histogram",
      nint=20)
@ 
like image 159
csgillespie Avatar answered Oct 11 '22 13:10

csgillespie