quarto-dev / quarto-dev/quarto-cli
Partial matching of parameters is confusing
Open
@cderv is already working on this.
Since Oct 31, 2023.
bug
engines-knitr
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
In Quarto 1.4.451, create the following dashboard with parameters:
---
title: "Sample dashboard"
format: dashboard
engine: knitr
params:
hello: 1
mello: "a character"
---
This should print out the value of `params$hello`: `{r} params$hello`.
This should print out the value of `params$mello`: `{r} params$mello`.
This shouldn't work because it's looking for a parameter that doesn't exist, `params$jello`: `{r} params$jello`.
This also shouldn't work because it's looking for a parameter that doesn't exist, `params$m`, but it does partial matching to `params$mello`, and the document renders: `{r} params$m`
It works, but I think it would be better if partial matching wasn't enabled by default for parameters.
Then add the following and re-render:
This doesn't work because it's doing partial matching and then failing when adding a number to a character `params$m + 2`: `{r} params$m + 2`.
You get the following error:
Quitting from lines 2-18 (untitled.qmd)
Error in `params$m + 2`:
! non-numeric argument to binary operator
Backtrace:
1. .QuartoInlineRender(params$m + 2)
Execution halted
It makes sense why this happens, but again, not doing partial matching by default would be less confusing.
Additionally, if I set partial matching to warn in the YAML of my document, e.g.,
knitr:
opts_chunk:
R.options:
warnPartialMatchDollar: true
the first example with partial matching still runs, which was even more surprising to me.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.