Skip to content
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
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Imports:
magrittr (>= 2.0.0),
purrr (>= 0.2.3),
R.cache (>= 0.15.0),
rematch2 (>= 2.0.1),
rlang (>= 0.1.1),
rprojroot (>= 1.1),
tibble (>= 1.4.2),
Expand Down
2 changes: 1 addition & 1 deletion R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ start_comments_with_space <- function(pd, force_one = FALSE) {
return(pd)
}

comments <- rematch2::re_match(
comments <- re_match(
pd$text[is_comment],
"^(?<prefix>#+['\\*]*)(?<space_after_prefix> *)(?<text>.*)$"
)
Expand Down
26 changes: 26 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ ensure_last_n_empty <- function(x, n = 1) {
c(x, rep("", n))
}

#' @note Slightly simplified version of `rematch2::re_match()` (License: MIT).
#' @keywords internal
#' @noRd
re_match <- function(text, pattern) {
stopifnot(is.character(pattern), length(pattern) == 1L, !is.na(pattern))
text <- as.character(text)
match <- regexpr(pattern, text, perl = TRUE)
start <- as.vector(match)
length <- attr(match, "match.length")
end <- start + length - 1L
matchstr <- substring(text, start, end)
matchstr[start == -1] <- NA_character_
res <- data.frame(stringsAsFactors = FALSE, .text = text, .match = matchstr)

gstart <- attr(match, "capture.start")
glength <- attr(match, "capture.length")
gend <- gstart + glength - 1L
groupstr <- substring(text, gstart, gend)
groupstr[gstart == -1] <- NA_character_
dim(groupstr) <- dim(gstart)
res <- cbind(groupstr, res, stringsAsFactors = FALSE)

names(res) <- c(attr(match, "capture.names"), ".text", ".match")
res
}

#' Replace the newline character with a line break
#'
#' @param text A character vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("roxzgen code examples are written to cache as whole expressions bring
# don't use full cache, only roxygen cache
styled[1] <- "#' This is a nother text"
second <- system.time(style_text(styled))
expect_gt(first["elapsed"], 5 * second["elapsed"])
expect_gt(first["elapsed"], 4 * second["elapsed"])
})

test_that("cache is deactivated at end of caching related testthat file", {
Expand Down