From 0e6134f1ca9f3cc81ca83226926067c7ff0621af Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 25 Aug 2023 09:55:04 -0500 Subject: [PATCH 1/7] fix quarto-dev/quarto-cli#5852: normalize names of all chunk options (converting dashes to dots) --- R/parser.R | 2 -- R/utils.R | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/parser.R b/R/parser.R index 0f76ab62e1..bb78c94b63 100644 --- a/R/parser.R +++ b/R/parser.R @@ -314,8 +314,6 @@ partition_chunk = function(engine, code) { # normalize field name 'id' to 'label' if provided meta$label = unlist(meta[c('label', 'id')])[[1]] meta$id = NULL - # convert any option with fig- into fig. and out- to out. - names(meta) = sub('^(fig|out)-', '\\1.', names(meta)) # extract code if (length(code) > 0 && is_blank(code[[1]])) { diff --git a/R/utils.R b/R/utils.R index 23bd50ad92..223a1b1df7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -247,6 +247,10 @@ tikz_dict = function(path) { # but now also place to tweak default options fix_options = function(options) { options = as.strict_list(options) + # convert dashes in option names with dots + dashes = grep('-', names(options), value = TRUE) + options[gsub('-', '.', dashes)] = options[dashes] + options[dashes] = NULL # if you want to use subfloats, fig.show must be 'hold' if (length(options$fig.subcap)) options$fig.show = 'hold' From fd5473047a6860495ee3516732d605a3d3734eb6 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 25 Aug 2023 10:57:35 -0500 Subject: [PATCH 2/7] also normalize fig.dev -> dev, fig.dpi -> dpi --- R/utils.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/utils.R b/R/utils.R index 223a1b1df7..d55fc4570f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -252,6 +252,13 @@ fix_options = function(options) { options[gsub('-', '.', dashes)] = options[dashes] options[dashes] = NULL + # normalize aliases + aliases = c(fig.dev = 'dev', fig.dpi = 'dpi') + for (j in intersect(names(options), names(aliases))) { + options[[aliases[j]]] = options[[j]] + options[[j]] = NULL + } + # if you want to use subfloats, fig.show must be 'hold' if (length(options$fig.subcap)) options$fig.show = 'hold' # if the animation hook has been set, fig.show must be 'animate' From 2392c3b1670b1080034495645075888d302c6372 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 25 Aug 2023 12:50:36 -0500 Subject: [PATCH 3/7] add news [ci skip] --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index be77605d0f..d9c6d09371 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,10 @@ - Use the correct type of progress bar when rendering Quarto documents in RStudio, which takes place in RStudio's background jobs pane or build pane (thanks, @hadley, #2271). +## MAJOR CHANGES + +- Dashes (`-`) in the names of all chunk options are normalized to dots (`.`) now, e.g., `fig-height` will be converted to `fig.height`. This is to make **knitr** more compatible with Quarto since Quarto always use dashes in chunk option names (#2282). + ## MINOR CHANGES - In-body chunk options (`#|`) are now preserved when extracting code from a document via `purl()` (thanks, @LuisLauM, #2268). From b29023ec36572f2fa4827cf4e31cfb5e11d61e04 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 28 Aug 2023 11:13:03 +0200 Subject: [PATCH 4/7] alias for `dev` chunk option if `fig-format` --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index d55fc4570f..ac2102f0b3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -253,7 +253,7 @@ fix_options = function(options) { options[dashes] = NULL # normalize aliases - aliases = c(fig.dev = 'dev', fig.dpi = 'dpi') + aliases = c(fig.format = 'dev', fig.dpi = 'dpi') for (j in intersect(names(options), names(aliases))) { options[[aliases[j]]] = options[[j]] options[[j]] = NULL From 51f0e2821c9ebfe22111a2512cc6f34153f1b1c5 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 28 Aug 2023 11:17:17 +0200 Subject: [PATCH 5/7] Add some unit tests --- tests/testit/test-utils.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testit/test-utils.R b/tests/testit/test-utils.R index 46e573b181..688fe12846 100644 --- a/tests/testit/test-utils.R +++ b/tests/testit/test-utils.R @@ -238,3 +238,19 @@ assert('remove_urls() removes the link', { (remove_urls('a [b](c) d [e f+g](h) i.') %==% 'a b d e f+g i.') (remove_urls('a [b](c) `[d](e)` f.') %==% 'a b `[d](e)` f.') }) + +assert('options using `-` are converted to `.` and default value replaced', { + opts = opts_chunk$merge(list('fig-cap' = 'caption')) + (is.null(fix_options(opts)[['fig-cap']])) + (fix_options(opts)[['fig.cap']] == 'caption') + rm(opts) +}) + +assert('fig.format and fig.dpi', { + opts = opts_chunk$merge(list('fig-format' = 'svg', 'fig-dpi' = 750)) + (is.null(fix_options(opts)[['fig-format']])) + (is.null(fix_options(opts)[['fig-dpi']])) + (fix_options(opts)[['dev']] == 'svg') + (fix_options(opts)[['dpi']] == 750) + rm(opts) +}) From 621463454eabe2ef97ccf8bdaae21de2085bf88b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 28 Aug 2023 11:36:38 +0200 Subject: [PATCH 6/7] Add out-width in the test --- tests/testit/test-utils.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testit/test-utils.R b/tests/testit/test-utils.R index 688fe12846..2dda254f66 100644 --- a/tests/testit/test-utils.R +++ b/tests/testit/test-utils.R @@ -240,9 +240,11 @@ assert('remove_urls() removes the link', { }) assert('options using `-` are converted to `.` and default value replaced', { - opts = opts_chunk$merge(list('fig-cap' = 'caption')) + opts = opts_chunk$merge(list('fig-cap' = 'caption', 'out-width' = 300)) (is.null(fix_options(opts)[['fig-cap']])) + (is.null(fix_options(opts)[['out-width']])) (fix_options(opts)[['fig.cap']] == 'caption') + (fix_options(opts)[['out.width']] == 300) rm(opts) }) From baa42de78759be9b729478d001e719d309c3bc8f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 28 Aug 2023 11:41:29 +0200 Subject: [PATCH 7/7] Bump dev version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d2377a3903..a5492bcfc5 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.43.6 +Version: 1.43.7 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"),