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!
knitrautomatically tidies the R code. So to get line breaks, settidy=FALSE, i.e.