Learn R Programming

FastUtils (version 0.2.1)

greplDir: Search for a Pattern in Files within a Directory

Description

[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, ...)

Value

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

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()

Examples

Run this code
# \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)
which(!result)
# }

Run the code above in your browser using DataLab