find_file_content: Find files containing pattern match

View source: R/utils.R

find_file_contentR Documentation

Find files containing pattern match

Description

Identify files within provided path that contain text that match a particular pattern.

Usage

find_file_content(
  path,
  file_pattern = NULL,
  text_pattern,
  recursive = FALSE,
  locale = readr::default_locale(),
  ...
)

Arguments

path

File path that contains files of interest (can look into child folders using recursive = T)

file_pattern

Basic regular expression to pick up file name pattern (e.g. '\.(R|Rmd)')

text_pattern

Grab the n-th file from the list (descending order by date). Default set to NULL, entire list is returned. Set to 1 if want just the latest match returned.

recursive

Reduce set of discovered file based upon a date threshold (default: NULL, no filtering occurs).

locale

Passed to read_file, controls encoding and similar file properties.

...

Additional parameters passed to grepl, helpful to add perl capabilities in pattern search.

Details

This function is often useful to quickly scan folders containing code that you need to find a particular key-phrase.

Value

Returns character vector for file names with matches

Examples


# Find pattern within set of files
find_file_content('./R', file_pattern = '\\.(R|Rmd)', text_pattern = 'sapply')


al-obrien/farrago documentation built on April 14, 2023, 6:20 p.m.