quarto-dev / quarto-dev/quarto-cli

Reconciling #| eval: !expr behaviour with knitr error handling

Open
#5,182 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

engines-knitr enhancement lint
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Bug description

I am not sure if this is a bug or not but I thought to report it regardless.

Sometimes it is helpful to set the knitr error option to TRUE so that a document will render no matter what.

At the same time I find using the #| eval: !expr approach pretty useful to defensively only render certain chunks based on a condition. Unfortunately these two error handling strategies don't seem to mesh together and I wondering if that is on purpose. In the reprex below I've set the knitr option error = TRUE globally. That works to catch any errors in chunks. However if I try to pass a variable that has not been created because of an error in a previous chunk to #| eval: !expr the document will fail to render.

My mental model was the knitr option should override that but the appears to not be the case. Any thoughts on whether this is a bad mental model?

Thanks so much for all the continued work on quarto.

---
title: "Untitled"
format: 
  html: 
    self_contained: true
---

```{r setup}
knitr::opts_chunk$set(error = TRUE)
```

```{r}
stop("an error")
```

```{r}
var <- 1 + "2b"
```

```{r}
#| eval: !expr "var > 1"

message("chunk worked")
```

Using MacOS and VS code to render quarto.

quarto check:

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.323
      Path: /Applications/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.16 (Conda)
      Path: /Users/samalbers/mambaforge/bin/python
      Jupyter: 4.11.1
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.2.3
      Path: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources
      LibPaths:
        - /Users/samalbers/Library/R/arm64/4.2/library
        - /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
      knitr: 1.41
      rmarkdown: 2.18

[✓] Checking Knitr engine render......OK
Checklist
  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.
  • Please provide the output of quarto check so we know which version of quarto and its dependencies you're running.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied .qmd reproduction, the #| eval: !expr entry point, and the knitr::opts_chunk$set(error = TRUE) setting; run it with the reported Quarto and R versions. Determine whether knitr's error handling is expected to govern evaluation expressions, then verify and document the intended behavior for this combination.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.