Skip to content

Commit f67dd7f

Browse files
committed
close #2386: throw a warning when chunk options are duplicated in both chunk header and pipe comments
1 parent 3b67aee commit f67dd7f

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: knitr
22
Type: Package
33
Title: A General-Purpose Package for Dynamic Report Generation in R
4-
Version: 1.49.2
4+
Version: 1.49.3
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
77
person("Abhraneel", "Sarma", role = "ctb"),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGES IN knitr VERSION 1.50
22

3+
## MINOR CHANGES
4+
5+
- 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.
6+
37
# CHANGES IN knitr VERSION 1.49
48

59
## NEW FEATURES

R/parser.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@ parse_block = function(code, header, params.src, markdown_mode = out_format('mar
113113
# merge with possible chunk options written as (YAML or CSV) metadata in
114114
# chunk, and remove metadata from code body
115115
parts = partition_chunk(engine, code)
116+
dup = intersect(names(params), names(parts$options))
116117
params = merge_list(params, parts$options)
117-
code = parts$code
118+
label = params$label
119+
if (length(dup)) warning(
120+
"Duplicated chunk option(s) ", paste0("'", dup, "'", collapse = ', '),
121+
" in both chunk header and pipe comments of the chunk '", label, "'.", call. = FALSE
122+
)
118123

119-
label = params$label; .knitEnv$labels = c(.knitEnv$labels, label)
124+
code = parts$code
125+
.knitEnv$labels = c(.knitEnv$labels, label)
120126
if (length(code) || length(params[['file']]) || length(params[['code']])) {
121127
if (label %in% names(knit_code$get())) {
122128
if (identical(getOption('knitr.duplicate.label'), 'allow')) {

0 commit comments

Comments
 (0)