8.6 Some tips and tricks
When rendering my R markdown document to pdf my code runs off the edge of the page.
Add a global_options argument at the start of your .Rmd file in a code chunk:
This code chunk won’t be displayed in the final document due to the
include = FALSE argument and you should place the code chunk immediately after the YAML header to affect everything below that.
tidy.opts = list(width.cutoff = 60), tidy=TRUE defines the margin cutoff point and wraps text to the next line. Play around with this value to get it right (60-80 should be OK for most documents).
When I load a package in my R markdown document my rendered output contains all of the startup messages and/or warnings.
You can load all of your packages at the start of your R markdown document in a code chunk along with setting your global options.
warning=FALSE arguments suppress messages and warnings. The
suppressPackageStartupMessages(library(ggplot2)) will load the
ggplot2 package but suppress startup messages.
When rendering my R markdown document to pdf my tables and/or figures are split over two pages.
Add a page break using the LateX
\pagebreak notation before your offending table or figure
The code in my rendered document looks ugly!
Add the argument
tidy=TRUE to your global arguments. Sometimes, however, this can cause problems especially with correct code indentation.