Skip to contents

Installs the weft-check Lua filter (rule 2.5.3) as a project extension, and the pre-render and post-render scripts (rules 2.5.4, 2.6.6, 2.9.4), and names them in _quarto.yml. It says what it will write before it writes anything.

Usage

use_quarto(path = ".")

Arguments

path

A directory in the project. use_quarto() walks up from it to the directory that holds _quarto.yml, says which directory it took, and writes there. Where there is none, it stops: it does not turn a directory into a Quarto project.

Value

The paths it wrote or changed, relative to path, invisibly.

Details

It writes:

  • _extensions/weft-check/_extension.yml, weft-check.lua and weft-output.lua (the rendered-output check, rule 2.5.5)

  • _weft/pre-render.R and _weft/post-render.R

  • _weft.yml, only when there is none (empty but for a comment)

and edits _quarto.yml: weft-check is added under filters:, then a path: _extensions/weft-check/weft-output.lua entry with at: post-render (an extension cannot place a filter after Quarto's own; a project set up before this check gets the entry when use_quarto() is run again), and the two scripts under project: pre-render: and post-render:. The file is edited as text, line by line, and never rewritten from parsed YAML: every other line, comments and anchors included, stays as it was. When the edit cannot be made safely (a flow-style filters: [a, b], say) use_quarto() stops before it writes anything and prints the lines to add by hand. Running it again changes nothing.

The scripts are plain base R and run when weft is not installed. The pre-render script fails the render, before anything renders, on a .qmd that holds a construct and has no engine: knitr in its own front matter (9.2.8). It also opens the collection file .weft/failures.jsonl, which the filter and the documents append to and the post-render script reports.

Examples

dir <- tempfile("weft-example")
dir.create(dir)
writeLines("project:\n  type: default", file.path(dir, "_quarto.yml"))
writeLines("", file.path(dir, "_weft.yml"))
use_quarto(dir)
#> weft will write, under /tmp/Rtmp62bcEi/weft-example1a3c3b2bf9a2:
#>   _extensions/weft-check/_extension.yml, weft.lua, weftlib/ and weft-check.lua  (the weft filters)
#>   _extensions/weft-check/weft-output.lua  (the rendered-output check; it runs after Quarto's own filters)
#>   _weft/pre-render.R   (fails a .qmd with constructs and no `engine: knitr`; opens .weft/failures.jsonl)
#>   _weft/post-render.R  (reports what the render collected)
#>   _weft.yml  (exists: left as it is)
#>   _quarto.yml  (adds the filter weft-check, the weft-output.lua filter entry, and the two scripts under project:)
#> Wrote: _extensions/weft-check/_extension.yml, _extensions/weft-check/weft.lua, _extensions/weft-check/weftlib/cond.lua, _extensions/weft-check/weftlib/config.lua, _extensions/weft-check/weftlib/ledger.lua, _extensions/weft-check/weftlib/lines.lua, _extensions/weft-check/weftlib/num.lua, _extensions/weft-check/weftlib/report.lua, _extensions/weft-check/weftlib/stamp.lua, _extensions/weft-check/weftlib/words.lua, _extensions/weft-check/weft-check.lua, _extensions/weft-check/weft-output.lua, _weft/pre-render.R, _weft/post-render.R, _quarto.yml
unlink(dir, recursive = TRUE)