Justace Clutter
Justace Clutter

Reputation: 2186

Knitr to PDF Does Not Honor Line Breaks?

I have a Rnw file that has a simple code chunk:

<<echo = TRUE, tidy = TRUE>>=
getNormIntegral = function(x, sd = 1) {
  res = pnorm(x*sd, sd = sd) - pnorm(-1*x*sd, sd = sd)  
  return(1.0 - res)
}
@

This looks good here, but when I render it to a pdf file using knitr, the code collapses into a single line and runs past the box. I have tried to set the width option with the following:

<<echo=FALSE>>=
  options(width=10)
@

but that did not have an affect. The resulting output in the pdf is:

enter image description here

(Ok, it is not extending past the box boundaries, but it is not honoring the manual line breaks that I put in the code...)

Any suggestions to make the output look like the code chunk that I typed in?

(I should add that I am using R 3.1.2, RStudio 0.99.34, and knitr 1.7)

Upvotes: 2

Views: 1382

Answers (1)

jonrobinson2
jonrobinson2

Reputation: 28

Just set tidy=FALSEin the chunk options. knitr automatically tidies your code.

Upvotes: 1

Related Questions