You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
YAML-style chunk options for plots are ignored when using hyphenated options (fig-height, fig-width) #11708
RStudio Edition : Desktop
RStudio Version : '2022.7.1.554'
OS Version : Mac OS X 12_4_0
R Version : 4.2.0
Steps to reproduce the problem
Using source mode or visual mode, modify plot dimensions with traditional knitr chunk options and YAML-styled #| options:
---
format: html
editor_options:
chunk_output_type: inline
---
This modifies appearance of plot
```{r, fig.width=12, fig.height = 5}
plot(mtcars$disp, mtcars$mpg)
```
But this doesn't:
```{r}
#| fig-width: 12
#| fig-height: 5
plot(mtcars$disp, mtcars$mpg)
```
Describe the problem in detail
When using knitr chunk options only using the older syntax r, fig.width=12, fig.height=5 modifies the appearance of inline plots in Quarto. Hashpipe/YAML style: #| fig-width: 12 doesn't modify the appearance.
Describe the behavior you expected
Both knitr style and YAML style chunk options do the same thing when rendering - would be ideal if that also affected interactive behavior in RStudio.
Tagging @debruine who reported the behavior initially - I was able to reprex.
I have installed the latest version of RStudio, and confirmed that the issue still persists.
If I am reporting an RStudio crash, I have included a diagnostics report.
I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Reacted by Andrés Castro Socolich, Andrei-WongE, Mark, Stephen Eglen, Jeremy Van Cleve, Vilmantas Gegzna, JMLuther, Lance Parsons, Cédric Scherer, Jim Gardner and 8 more
Since you are already into this, have you noticed a big difference in proportions between the plots shown in the code editor and the plots that get rendered into HTML? I first thought it was because of this issue but even using knitr chunk options I get a noticeable difference as if they were using different units. For "difference in proportions" I mean, for example, the text being way bigger in the HTML output relative to the rest of the plot than in the code editor.
These differences do not occur when knitting regular Rmd files, just with qmd files.
Also an issue on windows version. Same behavior as OP.
Would like to transition to this style of code in .qmd, but I rely on interactively adjusting the figure dimensions in RStudio. This is the bug that is keeping me from doing so.
─ Session info ───────────────────────────────────────────────────────────────────────────────
version R version 4.2.1 (2022-06-23 ucrt)
os Windows 10 x64 (build 19044)
system x86_64, mingw32
ui RStudio
rstudio 2022.07.1+554 Spotted Wakerobin (desktop)
version R version 4.2.1 (2022-06-23 ucrt)
os Windows 10 x64 (build 22000)
system x86_64, mingw32
ui RStudio
rstudio 2022.07.1+554 Spotted Wakerobin (desktop)
Reacted by Nick Youngblut, Kevin Reuning, Jeremy Van Cleve, Eric Green, Kadir Jun Ayhan, olivroy, Freya B-P, filip-tichanek, Ondrej Pekacek, Cédric Scherer and 2 more
Also an issue on windows version. Same behavior as OP. Would like to transition to this style of code in .qmd, but I rely on interactively adjusting the figure dimensions in RStudio. This is the bug that is keeping me from doing so.
─ Session info ───────────────────────────────────────────────────────────────────────────────
version R version 4.2.1 (2022-06-23 ucrt)
os Windows 10 x64 (build 19044)
system x86_64, mingw32
ui RStudio
rstudio 2022.07.1+554 Spotted Wakerobin (desktop)
Agreed, I'm in the same boat. Solving this would be great for facilitating my transition to qmd. I would appreciate it if someone can comment on the latest on this issue.
However there are a lot of places in our code where fig.height and fig.width are hard-coded (and perhaps other options as well) so I wonder if there's a more robust way to catch these kinds of issues without as much explicit string-checking. I think all hyphenated chunk options get converted to dot-style options when passed to the knitr engine for rendering, so we might want to do a similar thing for YAML style chunks in notebook execution
This seems to be where the translation from fig-width to fig.width is happening. However, I'm not sure this is exhaustive though because for example: #| out.width: 50% and #| out-width: 50% both work.
[Note: the fact that we don't handle all these translations is why for example, previewing a chunk with #| output: false will not suppress warnings or messages inline, only when rendered]
One source of the difference in syntax is that Quarto is more closely aligned with Pandoc format names and options (thus the use of - as a word separator rather than _).
How do these sizes make their way into the engine-level defaults for generating figures? This differs by engine:
For the Knitr engine, these values become the default values for the fig.width and fig.height chunk options. You can override these default values via chunk level options.
But it's not clear how many options that kind of translation applies to
Looks like we can potentially use the knitr:::fix_options function, but it would require a very recent version of knitr (I think 1.44 which is the latest release?) and is not an exported function currently. If it is not available, however, we could fallback to simply converting all - to . as that is one of the pieces of that function
Activity
andresrcs commentedon Aug 5, 2022
Since you are already into this, have you noticed a big difference in proportions between the plots shown in the code editor and the plots that get rendered into HTML? I first thought it was because of this issue but even using knitr chunk options I get a noticeable difference as if they were using different units. For "difference in proportions" I mean, for example, the text being way bigger in the HTML output relative to the rest of the plot than in the code editor.
These differences do not occur when knitting regular Rmd files, just with qmd files.
JMLuther commentedon Sep 17, 2022
Also an issue on windows version. Same behavior as OP.
Would like to transition to this style of code in .qmd, but I rely on interactively adjusting the figure dimensions in RStudio. This is the bug that is keeping me from doing so.
csthiago commentedon Nov 5, 2022
Same issue (windows)
version R version 4.2.1 (2022-06-23 ucrt)
os Windows 10 x64 (build 22000)
system x86_64, mingw32
ui RStudio
rstudio 2022.07.1+554 Spotted Wakerobin (desktop)
vancleve commentedon Nov 13, 2022
I'm also seeing this.
MarcellGranat commentedon Jan 3, 2023
For me only
#| out-height: 90%solves the issue.GegznaV commentedon Jan 31, 2023
Similar issue: https://community.rstudio.com/t/does-figure-size-in-quarto-qmd-documents-in-rstudio-need-to-be-specified-twice/158661
GegznaV commentedon Jan 31, 2023
What is the progress towards solving the issue??
caparks2 commentedon Jul 13, 2023
Same issue:
https://stackoverflow.com/q/76674526/11417996
atakanekiz commentedon Aug 25, 2023
Agreed, I'm in the same boat. Solving this would be great for facilitating my transition to qmd. I would appreciate it if someone can comment on the latest on this issue.
13 remaining items
jthomasmock commentedon Oct 4, 2023
Yah, Jackie's updated title is a better summary.
```{r fig.height}#| fig.heightfig-heightinstead offig.heightThe YAML style syntax for chunk options is not respected, as tested on
v2023.09.0+463jgutman commentedon Oct 4, 2023
I think this could be addressed somewhere around here:
rstudio/src/cpp/session/modules/rmarkdown/NotebookExec.cpp
Lines 206 to 207 in 11a6355
However there are a lot of places in our code where
fig.heightandfig.widthare hard-coded (and perhaps other options as well) so I wonder if there's a more robust way to catch these kinds of issues without as much explicit string-checking. I think all hyphenated chunk options get converted to dot-style options when passed to the knitr engine for rendering, so we might want to do a similar thing for YAML style chunks in notebook executionkevinushey commentedon Oct 4, 2023
Ah, thanks -- I misunderstood that. Does Quarto document all of the translations it does for "Quarto" options to "knitr" options?
jgutman commentedon Oct 4, 2023
I'm not sure if that documentation exists. But there are a few things I am aware of:
https://github.com/quarto-dev/quarto-cli/blob/1d7e53c99d62b9e2b5ffc1fa16cc5d3b4d0b6d6e/src/resources/rmd/execute.R#L263-L288
This seems to be where the translation from
fig-widthtofig.widthis happening. However, I'm not sure this is exhaustive though because for example:#| out.width: 50%and#| out-width: 50%both work.[Note: the fact that we don't handle all these translations is why for example, previewing a chunk with
#| output: falsewill not suppress warnings or messages inline, only when rendered]This documentation mentions that
This documentation mentions that
But it's not clear how many options that kind of translation applies to
kevinushey commentedon Oct 4, 2023
Nice find! https://github.com/quarto-dev/quarto-cli/blob/1d7e53c99d62b9e2b5ffc1fa16cc5d3b4d0b6d6e/src/resources/rmd/execute.R#L262-L278 seems like a great starting point, at least. I've also asked on the Quarto-dev channel for other pointers.
jgutman commentedon Oct 4, 2023
Looks like we can potentially use the
knitr:::fix_optionsfunction, but it would require a very recent version ofknitr(I think 1.44 which is the latest release?) and is not an exported function currently. If it is not available, however, we could fallback to simply converting all-to.as that is one of the pieces of that functionjonvanausdeln commentedon Oct 16, 2023
Verified with 2023.12.0-daily+170
Windows 11, MacOS 12.6
Chunks now render consistently.
andrewheiss commentedon Oct 16, 2023
Confirmed that this works on macOS 14.0 too
(The syntax highlighting of the inline chunk options is a nice touch too!)
andrewheiss commentedon Oct 16, 2023
(Though the Quarto tab completion of YAML keys doesn't work in this daily build, but that's definitely a separate issue)
kevinushey commentedon Oct 16, 2023
Is this a regression? If so, a bug report would definitely be appreciated!
andrewheiss commentedon Oct 16, 2023
Yeah, but only in untitled, unsaved .qmd files. Issue opened here: #13804