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!
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)
@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With