Skip to content

Commit

Permalink
fix tests/testthat/public-api/xyzfile_rmd: Code was duplicated previo…
Browse files Browse the repository at this point in the history
…usly!
  • Loading branch information
lorenzwalthert committed May 6, 2021
1 parent 8703691 commit 70e4d29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 8 additions & 8 deletions R/transform-code.R
Expand Up @@ -72,6 +72,10 @@ separate_chunks <- function(lines, filetype) {
#' Raw in the sense that these chunks don't contain pure R code, but they
#' contain a header and footer of markdown. Only code chunks that have an engine
#' whose name matches `engine-pattern` are considered as R code.
#' For every opening, we match the next closing. If there are not the same
#' amount of closing and openings after this matching, we throw an error.
#' Similarly, if there are two openings before a closing, the closing gets
#' matched twice, on which we throw an error.
#' @inheritParams separate_chunks
#' @param engine_pattern A regular expression that must match the engine name.
#' @importFrom rlang abort
Expand All @@ -85,14 +89,10 @@ identify_raw_chunks <- function(lines, filetype, engine_pattern = get_engine_pat
if (filetype == "Rmd") {
starts <- grep("^[\t >]*```+\\s*\\{([Rr]( *[ ,].*)?)\\}\\s*$", lines, perl = TRUE)
ends <- grep("^[\t >]*```+\\s*$", lines, perl = TRUE)

if (length(starts) != length(ends)) {
# for each start, match next end, required for nested chunks
ends <- purrr::imap_int(starts, ~ ends[which(ends > .x)[1]]) %>%
na.omit()
if (length(starts) != length(ends)) {
abort("Malformed file!")
}
ends <- purrr::imap_int(starts, ~ ends[which(ends > .x)[1]]) %>%
na.omit()
if (length(starts) != length(ends) || anyDuplicated(ends) != 0) {
abort("Malformed file!")
}
} else if (filetype == "Rnw") {
starts <- grep(pattern$chunk.begin, lines, perl = TRUE)
Expand Down
4 changes: 4 additions & 0 deletions man/identify_raw_chunks.Rd

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

0 comments on commit 70e4d29

Please sign in to comment.