Skip to content

Commit 057ee64

Browse files
Allow for enigne agnistic code.
find chunk start and ends via odd / even regex matches that are engine agnostic.
1 parent fb6a498 commit 057ee64

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

R/transform-code.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ identify_r_raw_chunks <- function(lines, engine_pattern = get_engine_pattern())
7373
if (is.null(pattern$chunk.begin) || is.null(pattern$chunk.end)) {
7474
stop("Unrecognized chunk pattern!", call. = FALSE)
7575
}
76-
starts <- grep("^[\t >]*```+\\s*\\{\\s*([a-zA-Z0-9]+.*)\\}\\s*$", lines, perl = TRUE)
77-
ends <- grep("^[\t >]*```+\\s*$", lines, perl = TRUE)
76+
chunks <- grep("^[\t >]*```+\\s*", lines, perl = TRUE)
77+
starts <- odd(chunks)
78+
ends <- even(chunks)
7879

7980
if (length(starts) != length(ends)) {
8081
stop("Malformed file!", call. = FALSE)

R/utils.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
parse_text <- function(x) parse(text = x)[[1L]]
22

3+
line_col_names <- function() {
4+
c("line1", "line2", "col1", "col2")
5+
}
6+
7+
#' Check whether two columns match
8+
#'
9+
#' @param col1,col2 Column names as string.
10+
#' @param data The data frames that contains `col1` and `col2`.
11+
two_cols_match <- function(col1, col2, data) {
12+
all(unlist(data[col1]) == unlist(data[col2]))
13+
}
14+
15+
odd <- function(x) {
16+
x[seq(1L, length(x), by = 2)]
17+
}
18+
19+
even <- function(x) {
20+
x[seq(2L, length(x), by = 2)]
21+
}
22+
323
#' Repeat elements of a character vector `times` times and collapse it
424
#'
525
#' @param char A character vector.

0 commit comments

Comments
 (0)