Skip to content

Commit

Permalink
get_engine_pattern returns a constant.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert committed Feb 9, 2018
1 parent 1e381d9 commit 87bebd4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
16 changes: 15 additions & 1 deletion R/transform-code.R
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ separate_chunks <- function(lines) {
#' whose name matches `engine-pattern` are considered as R code. #' whose name matches `engine-pattern` are considered as R code.
#' @inheritParams separate_chunks #' @inheritParams separate_chunks
#' @param engine_pattern A regular expression that must match the engine name. #' @param engine_pattern A regular expression that must match the engine name.
identify_r_raw_chunks <- function(lines, engine_pattern = "[rR]") { identify_r_raw_chunks <- function(lines, engine_pattern = get_engine_pattern()) {
pattern <- get_knitr_pattern(lines) pattern <- get_knitr_pattern(lines)
if (is.null(pattern$chunk.begin) || is.null(pattern$chunk.end)) { if (is.null(pattern$chunk.begin) || is.null(pattern$chunk.end)) {
stop("Unrecognized chunk pattern!", call. = FALSE) stop("Unrecognized chunk pattern!", call. = FALSE)
Expand All @@ -83,6 +83,20 @@ identify_r_raw_chunks <- function(lines, engine_pattern = "[rR]") {
list(starts = starts[is_r_code], ends = ends[is_r_code]) list(starts = starts[is_r_code], ends = ends[is_r_code])
} }


#' What's the engine pattern for rmd code chunks?
#'
#' The function returns the regular expression pattern that identifies
#' all r engines in Rmd chunks. Defaults to `[Rr]`. You probably only want to
#' change this if you create a knitr engine that processes R code but is not
#' the default engine `r`.
#' The pattern must be followed by a space (in the case the chunk is given
#' a name), a comma (if no name is given but further options are passed to the
#' engine) or a closing curly brace (in case no option and no name is given to
#' the chunk).
get_engine_pattern <- function() {
"[rR]"
}

#' Get chunk pattern #' Get chunk pattern
#' #'
#' Determine a regex pattern for identifying R code chunks. #' Determine a regex pattern for identifying R code chunks.
Expand Down
18 changes: 18 additions & 0 deletions man/get_engine_pattern.Rd

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

2 changes: 1 addition & 1 deletion man/identify_r_raw_chunks.Rd

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

2 changes: 1 addition & 1 deletion man/separate_chunks.Rd

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

0 comments on commit 87bebd4

Please sign in to comment.