Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass an R vector to fig-subcap with YAML validation, but works without #12044

Open
jack-davison opened this issue Feb 7, 2025 · 5 comments
Assignees
Labels
bug Something isn't working knitr needs-discussion Issues that require a team-wide discussion before proceeding further yaml-validation Issues with YAML validation and autocompletion in quarto
Milestone

Comments

@jack-davison
Copy link

Bug description

When YAML validation is on, I can't pass an R vector to fig-subcap:. I get the below error.

Watching files for changes
In file qmd.qmd
(line 20, columns 16--29) Field "fig-subcap" has value !expr 'yaxes', which must instead be 'true'

When I set validate-yaml: false it progresses and produces the desired output:

Image

Clearly fig-subcap doesn't want/need a value true.

Steps to reproduce

This fails:

---
title: "Quarto Playground"
format: html
engine: knitr
execute:
  echo: false
---

```{r}
library(ggplot2)

dat <- mtcars

yaxes <- names(mtcars)[names(mtcars) != "mpg"]
```

```{r}
#| label: fig-polarplots
#| fig-cap: !expr 'paste("Air", "Quality")'
#| fig-subcap: !expr 'yaxes'
#| layout-ncol: 2

purrr::map(yaxes, \(x) plot(mtcars[["mpg"]], mtcars[[x]]))
```

This works:

---
title: "Quarto Playground"
format: html
engine: knitr
validate-yaml: false
execute:
  echo: false
---

```{r}
library(ggplot2)

dat <- mtcars

yaxes <- names(mtcars)[names(mtcars) != "mpg"]
```

```{r}
#| label: fig-polarplots
#| fig-cap: !expr 'paste("Air", "Quality")'
#| fig-subcap: !expr 'yaxes'
#| layout-ncol: 2

purrr::map(yaxes, \(x) plot(mtcars[["mpg"]], mtcars[[x]]))
```

Expected behavior

Either:

  • Yaml validation shouldn't complain being given a R vector via !expr.

  • Passing an R vector to fig-subcap should never work (note: I'd much rather this wasn't the case unless there was some alternative to dynamically setting fig subcaps!)

Actual behavior

See bug description - errors w/ yaml validation.

Your environment

  • IDE: RStudio 2024.12.0.467
  • OS: Windows 11

Quarto check output

[>] Checking environment information...
      Quarto cache location: C:\Users\JD38\AppData\Local\quarto
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.6.39
      Path: C:\Users\JD38\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Using: TinyTex
      Path: C:\Users\JD38\AppData\Roaming\TinyTeX\bin\windows\
      Version: 2024

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....(None)

      Unable to locate an installed version of Python 3.
      Install Python 3 from https://www.python.org/downloads/

[>] Checking R installation...........OK
      Version: 4.4.2
      Path: C:/PROGRA~1/R/R-44~1.2
      LibPaths:
        - C:/Users/JD38/AppData/Local/R/win-library/4.4
        - C:/Program Files/R/R-4.4.2/library
      knitr: 1.49
      rmarkdown: 2.29

[>] Checking Knitr engine render......OK
@jack-davison jack-davison added the bug Something isn't working label Feb 7, 2025
@mcanouil mcanouil added yaml-validation Issues with YAML validation and autocompletion in quarto triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. labels Feb 7, 2025
@cderv
Copy link
Collaborator

cderv commented Feb 10, 2025

Is this happening in RStudio IDE context ?

I see the linting problem

Image

But it does not prevent rendering for me.

Anyhow, this is another case where !expr should be allowed in knitr engine context for the YAML validation

purrr::map(yaxes, (x) plot(mtcars[["mpg"]], mtcars[[x]]))

BTW I change this to purrr::walk() to avoid NULL being printed in output

@cderv cderv added knitr and removed triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. labels Feb 10, 2025
@cderv cderv added this to the v1.7 milestone Feb 10, 2025
@cderv
Copy link
Collaborator

cderv commented Feb 10, 2025

Our schema does support string or array of string

- name: fig-subcap
schema:
anyOf:
- enum: [true]
- maybeArrayOf: string
description: Figure subcaptions

So not sure why the first value only is seen 🤔

it does not prevent rendering for me.

Same in Positron BTW I can render with error

@cderv cderv added the needs-discussion Issues that require a team-wide discussion before proceeding further label Feb 10, 2025
@cderv
Copy link
Collaborator

cderv commented Feb 10, 2025

@cscheid do we have specific treatment somewhere for which fields could support !expr in knitr cell ?

I am interested to have a discussion on this at our next meeting so that I can know what to look for on my own for those type of enhancement.

@jack-davison
Copy link
Author

Is this happening in RStudio IDE context ?

I see the linting problem

Image

But it does not prevent rendering for me.

It is preventing rendering for me - I don't know if its my specific version of RStudio/Quarto (in original post) or something I/our IT has done to configure it, but it very much stops rendering when the YAML fails.

@cderv
Copy link
Collaborator

cderv commented Feb 10, 2025

I am running 2025.04.0-daily+281 version of RStudio. I'll try with the same as you.
For Quarto, I tried with 1.6.40.

I think it is expected to get rendering error on YAML validation failure, so not sure why I don't have it.

Anyhow, thanks for the report. We'll try to fix the validation for this specific !expr usage. This is knitr specific support and not cross engine, so it makes it harder to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working knitr needs-discussion Issues that require a team-wide discussion before proceeding further yaml-validation Issues with YAML validation and autocompletion in quarto
Projects
None yet
Development

No branches or pull requests

3 participants