Skip to content

Instantly share code, notes, and snippets.

@bearloga
Last active Mar 11, 2020
Embed
What would you like to do?
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

bearloga commented Mar 11, 2020

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