Skip to contents

ac_extract_file() returns one list element per file. Each element contains the matched text and the corresponding pattern values.

Usage

ac_extract_file(ac, path, stream = FALSE, overlapping = FALSE)

Arguments

ac

An <ac_automaton> object created by ac_build().

path

A vector of file paths to search.

stream

If FALSE (default), each file is read into memory before searching. If TRUE, files are searched as streams. Stream search requires an automaton built with match_kind = "standard".

overlapping

Default is FALSE. If TRUE, extract overlapping matches. This is only supported when stream = FALSE and ac was built with match_kind = "standard".

Value

A list with the same length as path. Each element is a data frame with one row per match and two columns:

  • matches: Text matched in the file.

  • patterns: Pattern values corresponding to each match.

Examples

ac <- ac_build(c("hello", "world"))
path <- tempfile()
writeLines("hello world", path)
ac_extract_file(ac, path)
#> [[1]]
#>   matches patterns
#> 1   hello    hello
#> 2   world    world
#>