I currently have some code that looks like so:
```{r, tidy=TRUE} plot(DT$age, DT$height, xlab = "Age of participant in Trials", ylab = "Height of participant in Trials") ```
Now, it was my understanding that setting tidy
to TRUE
would make it so that when I knit the code together, the code would not go running off the page and would wrap by itself. However, I sporadically still get run off source code displays when I do commands like the one above. Is there another function that would guarantee the wrapping of code? Thanks!
include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks. echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.
However, if you are using RStudio on a Windows computer, you can usually use Esc to stop a currently executing R script. Then, we can press Esc to interrupt the loop.
To insert a code chunk, press Ctrl + Alt + I in the source pane (top left pane in the default settings of RStudio). A code chunk will appear: Inside the code chunk you can write and run R-code.
To exit early from the knitting process, you may use the function knitr::knit_exit() anywhere in the source document (in a code chunk or inline expression). Once knit_exit() is called, knitr will ignore all the rest of the document and write out the results it has collected so far.
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/
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