diff --git a/DESCRIPTION b/DESCRIPTION index fd646f98..fd7c6833 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: officer Type: Package Title: Manipulation of Microsoft Word and PowerPoint Documents -Version: 0.6.6.002 +Version: 0.6.6.003 Authors@R: c( person("David", "Gohel", role = c("aut", "cre"), email = "david.gohel@ardata.fr"), person("Stefan", "Moog", role = "aut", email = 'moogs@gmx.de'), diff --git a/NEWS.md b/NEWS.md index c534c11e..e1571329 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,8 @@ ## Features - add coverage to rtf, contributions from Davide Garolini at roche. +- `cursor_reach()` gains new argument `fixed` to enable exact matching. +It defaults to FALSE for backward compatibility. # officer 0.6.5 diff --git a/R/docx_cursor.R b/R/docx_cursor.R index c95f3bd7..2a32ac7a 100644 --- a/R/docx_cursor.R +++ b/R/docx_cursor.R @@ -131,11 +131,12 @@ cursor_end <- function(x) { #' @export #' @rdname cursor #' @param keyword keyword to look for as a regular expression +#' @param fixed logical. If TRUE, pattern is a string to be matched as is. #' @section cursor_reach: #' Set the cursor on the first element of the document #' that contains text specified in argument \code{keyword}. #' The argument \code{keyword} is a regexpr pattern. -cursor_reach <- function(x, keyword) { +cursor_reach <- function(x, keyword, fixed = FALSE) { nodes_with_text <- xml_find_all( x$doc_obj$get(), "/w:document/w:body/*|/w:ftr/*|/w:hdr/*" @@ -146,7 +147,7 @@ cursor_reach <- function(x, keyword) { } text_ <- xml_text(nodes_with_text) - test_ <- grepl(pattern = keyword, x = text_) + test_ <- grepl(pattern = keyword, x = text_, fixed = fixed) if (!any(test_)) { stop(keyword, " has not been found in the document", call. = FALSE) } diff --git a/man/cursor.Rd b/man/cursor.Rd index 0f9e04da..2a42bba9 100644 --- a/man/cursor.Rd +++ b/man/cursor.Rd @@ -16,7 +16,7 @@ cursor_bookmark(x, id) cursor_end(x) -cursor_reach(x, keyword) +cursor_reach(x, keyword, fixed = FALSE) cursor_reach_test(x, keyword) @@ -30,6 +30,8 @@ cursor_backward(x) \item{id}{bookmark id} \item{keyword}{keyword to look for as a regular expression} + +\item{fixed}{logical. If TRUE, pattern is a string to be matched as is.} } \description{ A set of functions is available to manipulate