grep_file {fritools2}R Documentation

Grep a Pattern from Files

Description

This is an approximation of the unix command grep.

Usage

grep_file(paths, pattern, a = 1, b = 1, ...)

Arguments

paths

A vector of file paths.

pattern

The pattern to grep.

a

Number of lines of trailing context before matching lines. Like grep's -A option.

b

Number of lines of leading context before matching lines. Like grep's -B option.

...

Arguments passed to list.files.

Value

A named list with one item per file path. Each item consists of a list of row numbers matching the pattern. Each item is a vector of the matching lines and b lines before and a lines after the matching lines.

See Also

Other searching functions: compare_vectors(), file_modified_last(), find_files(), fromto(), missing_docs, search_files(), search_rows(), summary.filesearch()

Other file utilities: clipboard_path(), delete_trailing_blank_lines(), delete_trailing_whitespace(), develop_test(), file_copy(), file_modified_last(), file_save(), find_files(), get_lines_between_tags(), get_mtime(), get_unique_string(), is_files_current(), is_path(), paths, search_files(), split_code_file(), touch()

Examples

file_paths <- list.files(path = system.file("tinytest",
                                            package = "fritools2"),
                         pattern = ".*\\.R", full.names = TRUE)
res <- grep_file(path = file_paths, pattern = "forSureNotThere",
                 a = 3, b = 2, ignore.case = TRUE)
tinytest::expect_true(all(res == FALSE))

[Package fritools2 version 4.1.0 Index]