diff --git a/NEWS.md b/NEWS.md index c0587f3976..5d623130c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ - 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 (thanks, @kylebutts, #2307). + ## BUG FIXES - `write_bib()` generated empty entries for packages without URLs (thanks, @bastistician, #2304). diff --git a/R/spin.R b/R/spin.R index 90c05293cb..6bb564c47d 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]) 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