Skip to content

Instantly share code, notes, and snippets.

@bearloga
Last active March 11, 2020 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearloga/aea03d3baf55ef555afcf9935bb41da1 to your computer and use it in GitHub Desktop.
Save bearloga/aea03d3baf55ef555afcf9935bb41da1 to your computer and use it in GitHub Desktop.
Automatically printing chunk engine in R Markdown

Printing chunk engine via hook

Engine: R

library(dplyr)

Engine: python

import pandas as pd

Refer to chunk hooks for more information.

---
title: "Printing chunk engine via hook"
output: github_document
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
print_engine_hook <- function(before, options, envir) {
if (before) {
return(paste("**Engine**:", options$engine))
}
}
knit_hooks$set(print_engine_hook = print_engine_hook)
opts_chunk$set(print_engine_hook = TRUE)
```
```{r}
library(dplyr)
```
```{python}
import pandas as pd
```
Refer to [chunk hooks](https://yihui.org/knitr/hooks/) for more information.
@bearloga
Copy link
Author

Thanks to Yihui Xie for suggestions on how to improve the code.

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