Open mine-cetinkaya-rundel opened 11 months ago
I am personally not sure this should be changed as it is R/knitr specific and the default R behaviour. Was this different in Rmarkdown? (I never use partial matching in R)
It happens also with rmarkdown
---
title: "Sample dashboard"
output: html_document
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`
The R options does not work when pass to opts_chunk
because it is too late. params
are not evaluated as part of a chunk.
However, if you do set the options before rendering you'll see the warning
> withr::with_options(list(warnPartialMatchDollar = TRUE), rmarkdown::render("test.Rmd"))
processing file: test.Rmd
output file: test.knit.md
"C:/Users/chris/scoop/shims/pandoc" +RTS -K512m -RTS test.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.html --lua-filter "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmarkdown\lua\latex-div.lua" --embed-resources --standalone --variable bs3=TRUE --section-divs --template "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\chris\AppData\Local\Temp\Rtmp0MhBRB\rmarkdown-str9a3c29ea589e.html"
Output created: test.html
Message d'avis :
Dans params$m : correspondance partielle de 'm' en 'mello'
Partial Matching is really a R thing that happens with $
operator. It is on by default, and I don't think it can be deactivated.
Good practice to avoid it is
warnPartialMatchDollar
in its Rprofile
. That way a user will see the warning and can make a correction. [[
always as it does not support partial matching (see about this in https://adv-r.hadley.nz/subsetting.html#section-1) I don't think there is anything we can do here as this is related to how R works, and not really Quarto, dashboard, knitr, or rmarkdown.
Though we could think of something - like decide to activate the warning options for a quarto rendering maybe...
In Quarto 1.4.451, create the following dashboard with parameters:
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:
You get the following error:
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.,
the first example with partial matching still runs, which was even more surprising to me.