Skip to content

Instantly share code, notes, and snippets.

@njtierney
Last active June 3, 2019 13:27
Show Gist options
  • Save njtierney/d5a877a6dc8a97f2b4a5 to your computer and use it in GitHub Desktop.
Save njtierney/d5a877a6dc8a97f2b4a5 to your computer and use it in GitHub Desktop.
This chunk is what I usually write at the start of most rmarkdown documents.
```{r global_options, include=FALSE, cache=FALSE}
library(knitr)
# Set basic options. You usually do not want your code, messages, warnings etc.
# to show in your actual manuscript however for the first run or two these will
# be set on.
opts_chunk$set(echo=FALSE,
warning=FALSE,
message=FALSE,
cache = TRUE,
include = FALSE,
results = 'hide',
error = TRUE)
# setup changes according to html or docx
output <- opts_knit$get("rmarkdown.pandoc.to")
if (output=="html") {
opts_chunk$set(fig.width=11,
fig.height=11)
} # # end html `if` statement
## setting up the figure parameters for docx
if (output=="docx") {
opts_chunk$set(dev = 'pdf',
fig.width = 6,
fig.height = 6)
} # end docx `if` statement
```
@njtierney
Copy link
Author

The second part is really nifty.

It basically means that I can set different image heights, and other settings, depending on whether I decide to knit the document into html or docx formats. You could also include one for pdf if you wanted by mimicking the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment