Skip to main content

Command Palette

Search for a command to run...

Include R code in an Rmarkdown figure caption

Published
1 min read
M

Spent over a decade helping organizations thrive through re-platforming, digital analytics, and marketing automation. Now, I’m pivoting to Data Privacy and Governance. I specialize in translating abstract frameworks into actionable practices ensuring growth and protection work in tandem.

Here how to include R code in an Rmarkdown with figure caption and then save to PDF file.

Use fig_caption: true in your YAML and opts_knit$set(eval.after = "fig.cap")


title: "Example" output: pdf_document:

fig_caption: true

```{r parameters} library(knitr) opts_knit$set(eval.after = "fig.cap") insert_custom <- "world"


followed by

```{r hello-world, fig.cap = paste('Hello', insert_custom)}
plot(rnorm(10))
14 views