Skip to content

YAML-style chunk options for plots are ignored when using hyphenated options (fig-height, fig-width) #11708

Closed

Description

@jthomasmock

System details

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.

image

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.

https://twitter.com/lisadebruine/status/1555506264519630849?s=21&t=9xOZw-tSkKLd8IayCK0ajw

  • I have read the guide for submitting good bug reports.
  • 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.

Activity

  1. andresrcs commented on Aug 5, 2022

    @andresrcs

    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.

  2. JMLuther commented on Sep 17, 2022

    @JMLuther

    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)
    
  3. csthiago commented on Nov 5, 2022

    @csthiago

    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)

  4. vancleve commented on Nov 13, 2022

    @vancleve

    I'm also seeing this.

    RStudio 2022.07.2 Build 576
    R version 4.2.2 (2022-10-31)
    Platform: x86_64-apple-darwin21.6.0 (64-bit)
    Running under: macOS Monterey 12.6
    
  5. MarcellGranat commented on Jan 3, 2023

    @MarcellGranat

    For me only #| out-height: 90% solves the issue.

  6. GegznaV commented on Jan 31, 2023

    @GegznaV

    What is the progress towards solving the issue??

  7. added this to the Backlog-1 milestone on May 23, 2023
  8. caparks2 commented on Jul 13, 2023

    @caparks2
  9. atakanekiz commented on Aug 25, 2023

    @atakanekiz

    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.

  10. removed this from the Backlog-1 milestone on Sep 19, 2023
  11. 13 remaining items

  12. jthomasmock commented on Oct 4, 2023

    @jthomasmock
    ContributorAuthor

    Yah, Jackie's updated title is a better summary.

    • YAML style in terms of location IE
      • Chunk ```{r fig.height}
      • YAML: hashpipe, #| fig.height
    • YAML style in terms of syntax
      • fig-height instead of fig.height

    The YAML style syntax for chunk options is not respected, as tested on v2023.09.0+463

  13. jgutman commented on Oct 4, 2023

    @jgutman
    Contributor

    I think this could be addressed somewhere around here:

    double figWidth = options_.getOverlayOption("fig.width", 0.0);
    double figHeight = options_.getOverlayOption("fig.height", 0.0);

    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

  14. kevinushey commented on Oct 4, 2023

    @kevinushey
    Collaborator

    Ah, thanks -- I misunderstood that. Does Quarto document all of the translations it does for "Quarto" options to "knitr" options?

  15. jgutman commented on Oct 4, 2023

    @jgutman
    Contributor

    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-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]

    This documentation mentions that

    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 _).

    This documentation mentions that

    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

  16. kevinushey commented on Oct 4, 2023

    @kevinushey
    Collaborator
  17. jgutman commented on Oct 4, 2023

    @jgutman
    Contributor

    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

  18. jonvanausdeln commented on Oct 16, 2023

    @jonvanausdeln

    Verified with 2023.12.0-daily+170
    Windows 11, MacOS 12.6

    Chunks now render consistently.

  19. andrewheiss commented on Oct 16, 2023

    @andrewheiss

    Confirmed that this works on macOS 14.0 too

    (The syntax highlighting of the inline chunk options is a nice touch too!)

    image
  20. andrewheiss commented on Oct 16, 2023

    @andrewheiss

    (Though the Quarto tab completion of YAML keys doesn't work in this daily build, but that's definitely a separate issue)

  21. kevinushey commented on Oct 16, 2023

    @kevinushey
    Collaborator

    (Though the Quarto tab completion of YAML keys doesn't work in this daily build, but that's definitely a separate issue)

    Is this a regression? If so, a bug report would definitely be appreciated!

  22. andrewheiss commented on Oct 16, 2023

    @andrewheiss

    (Though the Quarto tab completion of YAML keys doesn't work in this daily build, but that's definitely a separate issue)

    Is this a regression? If so, a bug report would definitely be appreciated!

    Yeah, but only in untitled, unsaved .qmd files. Issue opened here: #13804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions