如何将变量用于块选项?

我尝试在执行R块以定义大小块选项后评估变量:

---
title: "R Notebook"
output:
  pdf_document: default
  html_notebook: default
---

```{r setup}
library("tidyverse")

theme_set(theme_bw())
theme_update(strip.background = element_blank())

knitr::opts_chunk$set(out.width = "80%",
                      out.height = "80%",
                      eval.after = c("fig.height", "fig.width"))
```

# Example chunk attempting to eval.after

```{r fig.width=figWidth, fig.height=figHeight}
plt <- ggplot(iris,
       aes(x = Sepal.Length,
           y = Sepal.Width,
           color = Petal.Length/Petal.Width)) +
  geom_point() +
  facet_wrap(~Species, ncol = 1)
figWidth <- 7*max(ggplot2::ggplot_build(plt)$layout$layout$COL)
figHeight <- 3.5*max(ggplot2::ggplot_build(plt)$layout$layout$ROW)
plt
```

错误示例:

enter image description here

评论