Skip to contents

[Experimental]

The greplDir function searches for a specified pattern in all files within a given directory. It allows for optional exclusion of files matching a specified regular expression. Note that all files are assumed to be a single string, with each line joined by the newline character "\n".

Usage

greplDir(fpattern, dirPath = getwd(), fIgnoreRegex = NULL, ...)

Arguments

fpattern

Character. The pattern to search for within the files.

dirPath

Character. The path to the directory containing files to be searched.

fIgnoreRegex

Character. A regular expression to match file names that should be ignored (default is NULL).

...

Additional arguments passed to listFiles(), which are passed to list.files()

Value

A named logical vector indicating which files contain the pattern. The names attribute contains the file names.

Examples

# \donttest{
result <- tryCatch(
  greplDir("error", fIgnoreRegex = "\\.log$"),
  warning = function(w) c(exFname = TRUE),
  error = function(e) c(exFname = TRUE)
)
# its even more useful to use `base::which` on the result to
# get matches and mismatches - this returns it with names
# by default
which(result)
#>    /home/runner/work/FastUtils/FastUtils/docs/dev/reference/evalText.html 
#>                                                                        13 
#> /home/runner/work/FastUtils/FastUtils/docs/dev/reference/fixColnames.html 
#>                                                                        15 
#>  /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getFailStr.html 
#>                                                                        18 
#>       /home/runner/work/FastUtils/FastUtils/docs/dev/reference/index.html 
#>                                                                        24 
which(!result)
#>     /home/runner/work/FastUtils/FastUtils/docs/dev/reference/FastUtils-package.html 
#>                                                                                   1 
#>                   /home/runner/work/FastUtils/FastUtils/docs/dev/reference/add.html 
#>                                                                                   2 
#>                 /home/runner/work/FastUtils/FastUtils/docs/dev/reference/bound.html 
#>                                                                                   3 
#>           /home/runner/work/FastUtils/FastUtils/docs/dev/reference/closestWord.html 
#>                                                                                   4 
#>         /home/runner/work/FastUtils/FastUtils/docs/dev/reference/colToRownames.html 
#>                                                                                   5 
#>            /home/runner/work/FastUtils/FastUtils/docs/dev/reference/createHash.html 
#>                                                                                   6 
#>         /home/runner/work/FastUtils/FastUtils/docs/dev/reference/createMutator.html 
#>                                                                                   7 
#>       /home/runner/work/FastUtils/FastUtils/docs/dev/reference/createPkgLoader.html 
#>                                                                                   8 
#>                /home/runner/work/FastUtils/FastUtils/docs/dev/reference/divide.html 
#>                                                                                   9 
#>               /home/runner/work/FastUtils/FastUtils/docs/dev/reference/enclose.html 
#>                                                                                  10 
#>             /home/runner/work/FastUtils/FastUtils/docs/dev/reference/encloseBr.html 
#>                                                                                  11 
#>           /home/runner/work/FastUtils/FastUtils/docs/dev/reference/enumerateit.html 
#>                                                                                  12 
#> /home/runner/work/FastUtils/FastUtils/docs/dev/reference/findMissingRdSections.html 
#>                                                                                  14 
#>             /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getAvgHex.html 
#>                                                                                  16 
#>               /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getChar.html 
#>                                                                                  17 
#>        /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getPkgKeywords.html 
#>                                                                                  19 
#>           /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getPlotDims.html 
#>                                                                                  20 
#>    /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getUniquePairsUpTo.html 
#>                                                                                  21 
#>              /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getfirst.html 
#>                                                                                  22 
#>               /home/runner/work/FastUtils/FastUtils/docs/dev/reference/getlast.html 
#>                                                                                  23 
# }