Skip to content

Commit

Permalink
feat: add fixed = TRUE argument to cursor_reach
Browse files Browse the repository at this point in the history
fix #567
  • Loading branch information
davidgohel committed May 5, 2024
1 parent d55fe2e commit 762d475
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions R/docx_cursor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion man/cursor.Rd

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

0 comments on commit 762d475

Please sign in to comment.