Created
August 24, 2016 08:30
-
-
Save sachsmc/8acf23ab8683f7e49a2eefcfd697019f to your computer and use it in GitHub Desktop.
How to delay chunk echo and easily print all code at the end using knitr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Untitled" | |
author: "Michael C Sachs" | |
date: "24 augusti 2016" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
library(knitr) | |
delay_code_labels <- NULL | |
knit_hooks$set(delay = function(before, options, envir) { | |
if (before) { | |
delay_code_labels <<- append(delay_code_labels, options$label) | |
return(NULL) ## otherwise knitr will print delay_code_labels every time | |
} else { | |
} | |
}) | |
opts_chunk$set(delay = TRUE, echo = FALSE, message = FALSE, warning = FALSE, | |
fig.width = 6, fig.asp = 0.618) | |
``` | |
## R Markdown | |
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. | |
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: | |
```{r norm} | |
rnorm(10) | |
``` | |
```{r cars} | |
summary(cars) | |
``` | |
## Including Plots | |
You can also embed plots, for example: | |
```{r pressure} | |
plot(pressure) | |
``` | |
## Appendix | |
### Code | |
```{r codeprint, echo = TRUE, eval = FALSE, ref.label = delay_code_labels, delay = FALSE} | |
``` | |
```{r} | |
sessionInfo() | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very useful! thanks