Skip to content

Commit

Permalink
close #2386: throw a warning when chunk options are duplicated in bot…
Browse files Browse the repository at this point in the history
…h chunk header and pipe comments
  • Loading branch information
yihui committed Jan 7, 2025
1 parent 3b67aee commit f67dd7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.49.2
Version: 1.49.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGES IN knitr VERSION 1.50

## MINOR CHANGES

- A warning will be issued when chunk options are duplicated in both the chunk header and pipe comments (thanks, @cderv, #2386). A chunk option should appear in only one of these places.

# CHANGES IN knitr VERSION 1.49

## NEW FEATURES
Expand Down
10 changes: 8 additions & 2 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ parse_block = function(code, header, params.src, markdown_mode = out_format('mar
# merge with possible chunk options written as (YAML or CSV) metadata in
# chunk, and remove metadata from code body
parts = partition_chunk(engine, code)
dup = intersect(names(params), names(parts$options))
params = merge_list(params, parts$options)
code = parts$code
label = params$label
if (length(dup)) warning(
"Duplicated chunk option(s) ", paste0("'", dup, "'", collapse = ', '),
" in both chunk header and pipe comments of the chunk '", label, "'.", call. = FALSE
)

label = params$label; .knitEnv$labels = c(.knitEnv$labels, label)
code = parts$code
.knitEnv$labels = c(.knitEnv$labels, label)
if (length(code) || length(params[['file']]) || length(params[['code']])) {
if (label %in% names(knit_code$get())) {
if (identical(getOption('knitr.duplicate.label'), 'allow')) {
Expand Down

0 comments on commit f67dd7f

Please sign in to comment.