Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for # %% for chunk demarcation in knitr::spin #2307

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.