Skip to content

Instantly share code, notes, and snippets.

@nutterb
Created April 8, 2016 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nutterb/f9fb89d35766022b0f75c90b24d45033 to your computer and use it in GitHub Desktop.
Save nutterb/f9fb89d35766022b0f75c90b24d45033 to your computer and use it in GitHub Desktop.
When I'm developing packages, sometimes I just want to find the files that contain a particular variable. This helps me search all of the files for the existence of a string pattern.
directorySearch <- function(dir, pattern, ...)
{
files <- list.files(dir)
suppressWarnings(
Code <- lapply(file.path(dir, files),
readLines)
)
files[vapply(Code,
function(x, pattern, ...) any(grepl(pattern, x, ...)),
logical(1),
pattern = pattern,
...)]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment