Skip to content

fix(knitr): code compiles when eval = FALSE - #548

Merged
JosiahParry merged 4 commits into
extendr:mainfrom
kbvernon:knitr-eval
Sep 25, 2026
Merged

JosiahParry merged 4 commits into
extendr:mainfrom
kbvernon:knitr-eval

Conversation

@kbvernon

Copy link
Copy Markdown
Collaborator

Closes #547.

I think the original intent maybe was something like this (from the knitr-engine test):

Define variable `_x`:

```{extendr chunk_x, eval = FALSE}
let _x = 1;
```

Define variable `_y`:

```{extendr chunk_y, eval = FALSE}
let _y = 2;
```

Print:

```{extendr out, preamble = c("chunk_x", "chunk_y")}
rprintln!("x = {}, y = {}", _x, _y);
```

but this actually still works with a guard to return early when eval = FALSE because the preamble chunks are combined with the out chunk, compiled, and evaluated there.

Note: in knitr_engine.R, I took the liberty of cleaning up some of the code, e.g., using rlang::is_* functions and replacing lapply(options$preamble, knitr::knit_code$get) with knitr::knit_code$get(options$preamble) since it is already vectorized (or anyway it just subsets a list of code chunks with the character vector in preamble).

Comment thread R/knitr_engine.R Outdated
@JosiahParry
JosiahParry merged commit aa123f6 into extendr:main Sep 25, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(knitr): code compiles when eval = FALSE

2 participants