diff --git a/DESCRIPTION b/DESCRIPTION index 82e1e62b2f..613761f8af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 20641fe94a..a87189d377 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/parser.R b/R/parser.R index 930ec3f2bd..4b9bcc82e2 100644 --- a/R/parser.R +++ b/R/parser.R @@ -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')) {