Allow arrays and booleans for knitr cache-globals cell option - #14736
Merged
cderv merged 2 commits intoJul 28, 2026
Conversation
cache-globals was declared as a bare `string`, while the analogous cache-vars uses `maybeArrayOf: string`. Since `maybeArrayOf: string` desugars to `anyOf(string, arrayOf(string))` and plain `string` does not, a YAML array failed cell metadata validation -- which runs before the engine, so it failed even with no R installed. The same declaration rejected `cache-globals: false`, a value the option's own long description documents, so the schema contradicted its own prose. knitr's cache_globals() takes a character vector directly, treats FALSE as "find all symbols", and otherwise auto-detects; it declares the option as a list type in opts_chunk_attr. Per knitr's NEWS.md, vectors are supported since 1.17 and booleans since 1.34. Widen the schema to `anyOf(maybeArrayOf: string, boolean)`, matching dependson in the same file, and regenerate the editor tooling artifacts. Fixes quarto-dev#14735 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Covers the array, boolean and single-string forms through parseAndValidateCellOptions, the function render itself calls. Runs without an R toolchain, since the defect was in TypeScript-side schema validation that happens before any engine runs. Initializes via setInitializer(initYamlIntelligenceResourcesFromFilesystem) rather than fullInit(): fullInit() also runs ensureSchemaResources(), which overlays the source schema yml on top of the generated artifact, so a test using it would pass even when dev-call build-artifacts had not been re-run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #14735
cache-globalswas declared as a barestringinsrc/resources/schema/cell-cache.yml, while the analogouscache-varsusesmaybeArrayOf: string. SincemaybeArrayOf: stringdesugars toanyOf(string, arrayOf(string))and plainstringdoes not, a YAML array was rejected during cell metadata validation — which runs before the engine is invoked, so it fails even with no R installed:The same declaration also rejected
cache-globals: false, a value the option's ownlongdescription documents ("In addition,cache-globals: falsemeans detecting all variables in a code chunk"). The schema therefore contradicted its own prose, and users hit a validation error that disagreed with the documentation.Both forms are valid for knitr.
cache_globals()inknitr/R/block.Rtakes a character vector directly, treatsFALSEas "find all symbols", and otherwise auto-detects; knitr declares the option aslistinopts_chunk_attr. Per knitr'sNEWS.md, vectors are supported since 1.17 and booleans since 1.34, so this is safe for any knitr Quarto supports.The fix widens the schema using the same
anyOf+maybeArrayOfshape thatdependsonuses further down the same file:Editor tooling artifacts are regenerated via
dev-call build-artifacts.Test
tests/unit/schema-validation/cell-options-knitr-cache-globals.test.tscovers the array, boolean and single-string forms throughparseAndValidateCellOptions, the same function reached during render fromvalidate-document.tsviapartitionCellOptionsMapped. It needs no R toolchain, since the defect was in TypeScript-side validation that runs before any engine. Verified to fail against the pre-fix generated artifact and to pass after (3 passed, ~0.4s).It initializes via
setInitializer(initYamlIntelligenceResourcesFromFilesystem)rather thanfullInit().fullInit()also runsensureSchemaResources(), which overlays the source schema yml on top of the generated artifact, so a test using it would pass even whendev-call build-artifactshad not been re-run.Also verified manually against knitr 1.45 and 1.51, though not kept as a test: the array reaches knitr as a
charactervector andfalseaslogical FALSE, and withcache: truethe cache database records the manually supplied globals forautodep.smoke/yaml-intelligence/yaml-intelligence-code-cell-options.test.tsstill passes (6 passed).Checklist
I have (if applicable):
The option description in
cell-cache.ymlalready documented the boolean form, so no wording change was needed — the generated docs were correct prose sitting on a schema that disagreed with them.AI-assisted PR
quarto-cli; local clone ofyihui/knitrforR/block.R,R/defaults.RandNEWS.md