From a60203cf903a32deca92922093e57d0ba64ca815 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 1 Nov 2024 10:55:08 -0500 Subject: [PATCH] need local chunk options in hook_purl() to check if user has set error=TRUE for that chunk also close #2338 --- NEWS.md | 2 +- R/hooks-extra.R | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 096b79ad88..9430600b6a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,7 +18,7 @@ - Unbalanced chunk delimiters (fences) in R Markdown documents are strictly prohibited now. -- For code chunks with `error = TRUE`, `purl()` and `hook_purl()` will wrap the code in `try({...})` (thanks, @jeroen, #2368). +- For code chunks with `error = TRUE`, `purl()` and `hook_purl()` will wrap the code in `try({...})` (thanks, @bastistician #2338, @jeroen #2368). ## MINOR CHANGES diff --git a/R/hooks-extra.R b/R/hooks-extra.R index 8085127c93..8cff592aeb 100644 --- a/R/hooks-extra.R +++ b/R/hooks-extra.R @@ -146,7 +146,10 @@ hook_purl = function(before, options, ...) { .knitEnv$tangle.params = NULL } - code = tangle_mask(options$code, options$eval, options$error) + # `options` contains merged chunk options, but we need to check if + # `error=TRUE` in local chunk options, so retrieve options from knit_code + error = attr(knit_code$get(options$label), 'chunk_opts')[['error']] + code = tangle_mask(options$code, options$eval, error) if (is.character(output)) { code = c( if (file.exists(output)) read_utf8(output),