Skip to content

Commit

Permalink
includePattern
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Apr 24, 2024
1 parent 61e2bee commit a761bd8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# findInFiles 0.5.0

* The arguments `excludePattern` and `excludeFoldersPattern` of the
`findInFiles` function can be some vectors now, to give multiple patterns.

* The `findInFiles` function has now an argument `includePattern`. If a vector
of patterns is supplied to this argument, then only the files whose name matches
one of these patterns are included in the search.

* The `findInFiles` function has two new arguments `maxCountPerFile` and
`maxCount`. If an integer is supplied to `maxCountPerFile`, then this integer
is passed to the `--max-count` option of the `grep` command and then `grep`
Expand Down
6 changes: 6 additions & 0 deletions R/findInFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#' @param wholeWord logical, whether to match the whole pattern
#' @param ignoreCase logical, whether to ignore the case
#' @param perl logical, whether \code{pattern} is a Perl regular expression
#' @param includePattern this argument is ignored if \code{depth} is not a
#' positive integer; it must be a pattern or a vector of patterns, and only
#' the files whose name matches this pattern or one of these patterns will be
#' included in the search
#' @param excludePattern a pattern or a vector of patterns; files and folders
#' whose name matches this pattern or one of these patterns will be excluded
#' from search
Expand Down Expand Up @@ -61,6 +65,7 @@
findInFiles <- function(
ext, pattern, depth = NULL, maxCountPerFile = NULL, maxCount = NULL,
wholeWord = FALSE, ignoreCase = FALSE, perl = FALSE,
includePattern = NULL,
excludePattern = NULL, excludeFoldersPattern = NULL,
root = ".", output = "viewer"
){
Expand Down Expand Up @@ -103,6 +108,7 @@ findInFiles <- function(
ext = ext, pattern = pattern, depth = depth,
maxCountPerFile = maxCountPerFile, maxCount = maxCount,
wholeWord = wholeWord, ignoreCase = ignoreCase, perl = perl,
includePattern = includePattern,
excludePattern = excludePattern,
excludeFoldersPattern = excludeFoldersPattern,
directory = root, output = output
Expand Down
14 changes: 13 additions & 1 deletion R/grepInFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ getFiles <- function(ext, depth){
grepInFiles <- function(
ext, pattern, depth, maxCountPerFile, maxCount,
wholeWord, ignoreCase, perl,
excludePattern, excludeFoldersPattern,
includePattern, excludePattern, excludeFoldersPattern,
directory, output
){
if(inSolaris()){
Expand Down Expand Up @@ -46,6 +46,18 @@ grepInFiles <- function(
if(wholeWord) opts <- c(opts, "-w")
if(ignoreCase) opts <- c(opts, "-i")
if(perl) opts <- c(opts, "-P")
if(!is.null(includePattern)){
check <- all(vapply(includePattern, isString, logical(1L)))
if(!check) {
stop("Invalid argument `includePattern`.")
}
opts <- c(
opts,
vapply(includePattern, function(pattern) {
paste0("--include=", shQuote(pattern))
}, character(1L))
)
}
if(!is.null(excludePattern)){
check <- all(vapply(excludePattern, isString, logical(1L)))
if(!check) {
Expand Down
7 changes: 7 additions & 0 deletions man/findInFiles.Rd

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

0 comments on commit a761bd8

Please sign in to comment.