From d135da0211ee1074d5c9f0ade4e9a1a1cd0d88a6 Mon Sep 17 00:00:00 2001 From: Kyle Butts Date: Sun, 26 Nov 2023 09:50:35 -0500 Subject: [PATCH 1/3] Add support for `# %%` for chunk demarcation --- R/spin.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/spin.R b/R/spin.R index 90c05293cb..6fca52be04 100644 --- a/R/spin.R +++ b/R/spin.R @@ -3,8 +3,8 @@ #' This function takes a specially formatted R script and converts it to a #' literate programming document. By default normal text (documentation) should #' be written after the roxygen comment (\code{#'}) and code chunk options are -#' written after \code{#+} or \code{#-} or \code{# ----} or any of these -#' combinations replacing \code{#} with \code{--}. +#' written after \code{#+} or \code{# %%} or \code{#-} or \code{# ----} or +#' any of these combinations replacing \code{#} with \code{--}. #' #' Obviously the goat's hair is the original R script, and the wool is the #' literate programming document (ready to be knitted). @@ -90,7 +90,8 @@ spin = function( # R code; #+/- indicates chunk options block = strip_white(block) # rm white lines in beginning and end if (!length(block)) next - if (length(opt <- grep(rc <- '^(#|--)+(\\+|-| ----+| @knitr)', block))) { + rc <- '^(#|--)+(\\+|-|\\s+%%| ----+| @knitr)' + if (length(opt <- grep(rc, block))) { opts = gsub(paste0(rc, '\\s*|-*\\s*$'), '', block[opt]) opts = paste0(ifelse(opts == '', '', ' '), opts) block[opt] = paste0(p[1L], opts, p[2L]) From c7d4741ea613b2062b0a1550175f733834f2c8e0 Mon Sep 17 00:00:00 2001 From: Kyle F Butts Date: Mon, 27 Nov 2023 16:24:15 -0500 Subject: [PATCH 2/3] Add `# %%` support to news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c0587f3976..ef86abaa2d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## NEW FEATURES - Added a new chunk option `tab.cap` to specify the table caption for `kable()` (thanks, @ulyngs, #1679). Previously, the caption could only be specified via the `caption` argument of `kable()`. Now you can set it in the chunk header if you want. Please note that this chunk option only works with a single `kable()` in each code chunk, and its value must be of length 1. +- `knitr::spin()` now recognizes `# %%` as a valid code chunk delimiter. ## BUG FIXES From abe34489b1c47318ef934b1cc21eba0ba15fb024 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 27 Nov 2023 16:02:20 -0600 Subject: [PATCH 3/3] roxygenize [ci skip] --- NEWS.md | 3 ++- R/spin.R | 2 +- man/spin.Rd | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index ef86abaa2d..5d623130c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,8 @@ ## NEW FEATURES - Added a new chunk option `tab.cap` to specify the table caption for `kable()` (thanks, @ulyngs, #1679). Previously, the caption could only be specified via the `caption` argument of `kable()`. Now you can set it in the chunk header if you want. Please note that this chunk option only works with a single `kable()` in each code chunk, and its value must be of length 1. -- `knitr::spin()` now recognizes `# %%` as a valid code chunk delimiter. + +- `knitr::spin()` now recognizes `# %%` as a valid code chunk delimiter (thanks, @kylebutts, #2307). ## BUG FIXES diff --git a/R/spin.R b/R/spin.R index 6fca52be04..6bb564c47d 100644 --- a/R/spin.R +++ b/R/spin.R @@ -3,7 +3,7 @@ #' This function takes a specially formatted R script and converts it to a #' literate programming document. By default normal text (documentation) should #' be written after the roxygen comment (\code{#'}) and code chunk options are -#' written after \code{#+} or \code{# %%} or \code{#-} or \code{# ----} or +#' written after \code{#+} or \code{# \%\%} or \code{#-} or \code{# ----} or #' any of these combinations replacing \code{#} with \code{--}. #' #' Obviously the goat's hair is the original R script, and the wool is the diff --git a/man/spin.Rd b/man/spin.Rd index c4a9f084fd..67913bbcb2 100644 --- a/man/spin.Rd +++ b/man/spin.Rd @@ -59,8 +59,8 @@ If \code{text} is \code{NULL}, the path of the final output document, This function takes a specially formatted R script and converts it to a literate programming document. By default normal text (documentation) should be written after the roxygen comment (\code{#'}) and code chunk options are -written after \code{#+} or \code{#-} or \code{# ----} or any of these -combinations replacing \code{#} with \code{--}. +written after \code{#+} or \code{# \%\%} or \code{#-} or \code{# ----} or +any of these combinations replacing \code{#} with \code{--}. } \details{ Obviously the goat's hair is the original R script, and the wool is the