rstudio / rstudio

RStudio is an integrated development environment (IDE) for R
https://posit.co/products/open-source/rstudio/
Other
4.69k stars 1.09k forks source link

fig captions with chunk option `fig.cap` do not display when executing chunks inline #11113

Open jgutman opened 2 years ago

jgutman commented 2 years ago

System details

RStudio Edition : Desktop
RStudio Version : 2022.06.0+333
OS Version      : Mac 12.3.1
R Version       : 

Steps to reproduce the problem

Create an Rmd with an R code chunk

```{r message=FALSE, warning=FALSE, fig.cap="This is a caption"}

library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) + 
        geom_point() + 
        geom_smooth(method = "loess", se = FALSE)


When knitting, the figure caption displays in the rendered HTML/PDF below the plot. When running the chunk in the console, the plot renders inline but the figure caption is not displayed

### Describe the problem in detail
Inline chunk execution should show same behavior as knitr chunk execution, e.g. a figure caption should be displayed below the plot/figure when supplied

### Describe the behavior you expected

<!-- 
Please keep the below portion in your issue, and check `[x]` the applicable boxes.
-->

- [X] I have read the guide for [submitting good bug reports](https://github.com/rstudio/rstudio/wiki/Writing-Good-Bug-Reports).
- [X] I have installed the latest version of RStudio, and confirmed that the issue still persists.
- [X] If I am reporting an RStudio crash, I have included a [diagnostics report](https://support.rstudio.com/hc/en-us/articles/200321257-Running-a-Diagnostics-Report).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
ronblum commented 2 years ago

Note: Also reproducible in

jgutman commented 2 years ago

Question: for python chunks, is the corresponding option fig-cap? With a dash rather than dot?

In quarto documentation, the following example is given, so we'd want to check that this is supported as well:


title: "matplotlib demo" format: html: code-fold: true jupyter: python3

For a demonstration of a line plot on a polar axis, see @fig-polar.

#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"

import numpy as np
import matplotlib.pyplot as plt

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
  subplot_kw = {'projection': 'polar'} 
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()