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

!expr invalide with message in chunk option #11897

Open
LBeaulaton opened this issue Jan 18, 2025 · 2 comments
Open

!expr invalide with message in chunk option #11897

LBeaulaton opened this issue Jan 18, 2025 · 2 comments
Labels
enhancement New feature or request yaml-validation Issues with YAML validation and autocompletion in quarto

Comments

@LBeaulaton
Copy link

LBeaulaton commented Jan 18, 2025

Bug description

!expr in chunk option don't work for message while it works e.g. error.

Steps to reproduce

---
title: test knitr
# validate-yaml: false
---

```{r}
#| label: chunk1

show.message <- FALSE
```

```{r}
#| label: chunk2
#| error: !expr "show.message"

message("this works")
```

```{r}
#| label: chunk3
#| message: !expr "show.message"

message("this doesn't work")
```

Expected behavior

This should not produce an error message.
Note that with validate-yaml: false not commented I'm able to render the quarto file

Actual behavior

Produce the following error message:

ERROR: Validation of YAML cell metadata failed.
In file test.qmd
(line 21, columns 13--33) Field "message" has value !expr "show.message", which must instead be one of: `true`, `false`, `NA`

Your environment

Ubuntu 24.04
Quarto 16.04
VSCodium 1.92.2

Quarto check output

quarto check
Quarto 1.6.40
[✓] Checking environment information...
      Quarto cache location: /home/lbeaulaton/.cache/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.40
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /usr/bin
      Version: 2023

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.3
      Path: /usr/bin/python3
      Jupyter: 5.3.2
      Kernels: python3

(\) Checking Jupyter engine render....Traceback (most recent call last):
  File "/opt/quarto/share/jupyter/jupyter.py", line 21, in <module>
    from notebook import notebook_execute, RestartKernel
  File "/opt/quarto/share/jupyter/notebook.py", line 20, in <module>
    from nbclient import NotebookClient
ModuleNotFoundError: No module named 'nbclient'
[✓] Checking Jupyter engine render....OK
@LBeaulaton LBeaulaton added the bug Something isn't working label Jan 18, 2025
@cderv
Copy link
Collaborator

cderv commented Jan 20, 2025

Thanks for opening the issue. !expr is tricky as this is only a knitr engine feature kept for backward compatibility.

First, I can't reproduce any rendering error. And there should not be, because the YAML field inside knitr cells are directly processed by knitr AFAIK. So this renders for me

---
title: test knitr
---

```{r}
#| label: chunk1

show.message <- FALSE
```

```{r}
#| label: chunk2
#| error: !expr "show.message"

message("this works")
```

```{r}
#| label: chunk3
#| message: !expr "show.message"

message("this doesn't work")
```

However, I get the validation linting error in RStudio IDE

Image

And IMO this is because we added autocompletion for true, false, NA which are the fields supported - !expr being an edge case we don't validate againt.

I need to see how our validation system can correctly support official values for fields, while also supporting !expr if possible for knitr engine.

@cderv
Copy link
Collaborator

cderv commented Jan 20, 2025

@cscheid I added some specific to message field for knitr at

I believe this now prevents the validation to accept a string and does the !expr specific exception

How can I tell the schema that these are the accepted values

- name: message
tags:
engine: knitr
schema:
enum: [true, false, NA]

and offers to auto complete them.

but also accept string so that !expr syntax does pass in knitr cells ?

I know this is not Quarto feature, but it would be good if we good have a way to accept !expr field in our validation. I don't know how to express this in our YAML schema.

@cderv cderv added yaml-validation Issues with YAML validation and autocompletion in quarto enhancement New feature or request and removed bug Something isn't working labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request yaml-validation Issues with YAML validation and autocompletion in quarto
Projects
None yet
Development

No branches or pull requests

2 participants