In R markdown in RStudio, how can I prevent the source code from running off a pdf page?

Use the width.cutoff argument inside tidy.opts knitr options to specify the output width :

```{r, tidy=TRUE, tidy.opts=list(width.cutoff=60)}
plot(DT$age, DT$height, xlab = "Age of participant in Trials", ylab = "Height of participant in trials")
```

You can define this option globally for your whole file with a chunk like this :

```{r}
library(knitr)
opts_chunk$set(tidy.opts=list(width.cutoff=60),tidy=TRUE)
```

The tidy.opts options are passed to the formatR package which does the tidying (if I understand correctly). In-depth informations about formatR can be found here :

http://yihui.name/formatR/

Leave a Comment