Skip to content

Document engine-agnostic approach to conditional execution #13514

@cwickham

Description

@cwickham

With QUARTO_EXECUTE_INFO, we now have an approach to conditional execution that works across engines.

For example, for code that should be only executed for HTML formats:

R:

```{r}
execute_info <- jsonlite::read_json(Sys.getenv("QUARTO_EXECUTE_INFO"))
is_html <- execute_info[["format"]][["identifier"]][["base-format"]] == "html"

if (is_html) {
  "HTML"
} 
```

Python:

```{python}
import json
import os

with open(os.getenv("QUARTO_EXECUTE_INFO")) as f:
    execute_info = json.load(f)

is_html = execute_info["format"]["identifier"]["base-format"] == "html"

if is_html:
    print("HTML")
```

Users often want to combine this with conditional content.

This could be documented:

  • as a section of /docs/computations/execution-options.qmd
  • its own "Conditional Execution" page under Guide > Computations
  • as an example wherever the docs for QUARTO_EXECUTE_INFO end up
  • as a blog post on "Conditional Execution"

Regardless of where the examples end up, it should be mentioned and linked to from:

Some relevant issues and discussions this would resolve:

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationDoc improvements & quarto-web

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions