Skip to content

Commit 87bebd4

Browse files
get_engine_pattern returns a constant.
1 parent 1e381d9 commit 87bebd4

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

R/transform-code.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ separate_chunks <- function(lines) {
6464
#' whose name matches `engine-pattern` are considered as R code.
6565
#' @inheritParams separate_chunks
6666
#' @param engine_pattern A regular expression that must match the engine name.
67-
identify_r_raw_chunks <- function(lines, engine_pattern = "[rR]") {
67+
identify_r_raw_chunks <- function(lines, engine_pattern = get_engine_pattern()) {
6868
pattern <- get_knitr_pattern(lines)
6969
if (is.null(pattern$chunk.begin) || is.null(pattern$chunk.end)) {
7070
stop("Unrecognized chunk pattern!", call. = FALSE)
@@ -83,6 +83,20 @@ identify_r_raw_chunks <- function(lines, engine_pattern = "[rR]") {
8383
list(starts = starts[is_r_code], ends = ends[is_r_code])
8484
}
8585

86+
#' What's the engine pattern for rmd code chunks?
87+
#'
88+
#' The function returns the regular expression pattern that identifies
89+
#' all r engines in Rmd chunks. Defaults to `[Rr]`. You probably only want to
90+
#' change this if you create a knitr engine that processes R code but is not
91+
#' the default engine `r`.
92+
#' The pattern must be followed by a space (in the case the chunk is given
93+
#' a name), a comma (if no name is given but further options are passed to the
94+
#' engine) or a closing curly brace (in case no option and no name is given to
95+
#' the chunk).
96+
get_engine_pattern <- function() {
97+
"[rR]"
98+
}
99+
86100
#' Get chunk pattern
87101
#'
88102
#' Determine a regex pattern for identifying R code chunks.

man/get_engine_pattern.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/identify_r_raw_chunks.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/separate_chunks.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)