Skip to content

Commit

Permalink
Add support for # %% for chunk demarcation in knitr::spin (#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebutts committed Nov 27, 2023
1 parent c9473ad commit a51a7a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 4 additions & 3 deletions R/spin.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions man/spin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a51a7a0

Please sign in to comment.