Code highlighting with flair

code highlighting syntax highlighting flair

Custom code highlighting with flair R package

Emil Hvitfeldt true
05-22-2021

The flair package can be used to provide custom highlighting to code chunks. The most important thing is to make sure that the chunk names match.

Result

Rmd

---
output:
  xaringan::moon_reader:
    css: ["default"]
    lib_dir: libs
    seal: FALSE
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, echo=FALSE}
library(flair)
```

# Highlighting code with {flair}

```{r lm, include = FALSE}
lm(mpg ~ disp, data = mtcars)
```

```{r lm_flair, echo = FALSE}
decorate("lm") %>%
  flair("mpg", color = "orange") %>%
  flair("disp", color = "lightblue") %>%
  flair("mtcars", color = "lightpink")
```

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Hvitfeldt (2021, May 22). Xaringan Gallery: Code highlighting with flair. Retrieved from https://xaringan.gallery/examples/flair-highlight/

BibTeX citation

@misc{hvitfeldt2021code,
  author = {Hvitfeldt, Emil},
  title = {Xaringan Gallery: Code highlighting with flair},
  url = {https://xaringan.gallery/examples/flair-highlight/},
  year = {2021}
}