diff --git a/R/detect-alignment.R b/R/detect-alignment.R index bf8ffbe7c..cab7e00a4 100644 --- a/R/detect-alignment.R +++ b/R/detect-alignment.R @@ -141,8 +141,8 @@ token_is_on_aligned_line <- function(pd_flat) { is_aligned <- length(unique(current_col)) == 1L if (!is_aligned || length(current_col) < 2L) { # check 2: left aligned after , (comma to next token) - current_col <- "^(,[\\s\\t]*)[^ ]*.*$" %>% - gsub("\\1", by_line, perl = TRUE) %>% + current_col <- + gsub(R"(^(,[\s\t]*)[^ ]*.*$)", R"(\1)", by_line, perl = TRUE) %>% nchar() %>% magrittr::subtract(1L) diff --git a/R/roxygen-examples-add-remove.R b/R/roxygen-examples-add-remove.R index 3a7ecb40b..f311c83e4 100644 --- a/R/roxygen-examples-add-remove.R +++ b/R/roxygen-examples-add-remove.R @@ -12,12 +12,8 @@ remove_dont_mask <- function(roxygen) { ) } -remove_blank_lines <- function(code) { - code[code != "\n"] -} - remove_roxygen_mask <- function(text) { - code_with_header <- gsub(pattern = "^#'\\s?", "", text) + code_with_header <- gsub(pattern = R"(^#'\s?)", "", text) remove_roxygen_header(code_with_header) } @@ -29,7 +25,7 @@ remove_roxygen_mask <- function(text) { #' #' @examples c(1, 2) #' @keywords internal remove_roxygen_header <- function(text) { - gsub("^[\\s\t]*@examples(If)?(\\s|\t)*", "", text, perl = TRUE) + gsub(R"(^[\s\t]*@examples(If)?(\s|\t)*)", "", text, perl = TRUE) } #' Add the roxygen mask to code diff --git a/R/roxygen-examples-find.R b/R/roxygen-examples-find.R index bf61983c9..49955265e 100644 --- a/R/roxygen-examples-find.R +++ b/R/roxygen-examples-find.R @@ -5,13 +5,13 @@ #' @param text A text consisting of code and/or roxygen comments. #' @keywords internal identify_start_to_stop_of_roxygen_examples_from_text <- function(text) { - starts <- grep("^#'(\\s|\t)*@examples(If\\s|\\s|\t|$)", text, perl = TRUE) + starts <- grep(R"{^#'(\s|\t)*@examples(If\s|\s|\t|$)}", text, perl = TRUE) if (length(starts) < 1L) { return(integer()) } stop_candidates <- which(magrittr::or( # starts with code or a tag - grepl("(^[^#]|^#'[\\s\t]*@)", text, perl = TRUE), + grepl(R"{(^[^#]|^#'[\s\t]*@)}", text, perl = TRUE), # starts with a roxygen comment with a blank line after grepl("^ *\t*$", text) & grepl("^#' *", lead(text)) )) %>%