Skip to contents

ac_count_file() returns the number of pattern matches in each file.

Usage

ac_count_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, count overlapping matches. This is only supported when stream = FALSE and ac was built with match_kind = "standard".

Value

An integer vector with the same length as path.

Examples

ac <- ac_build(c("hello", "world"))
path <- tempfile()
writeLines("hello hello world", path)
ac_count_file(ac, path)
#> [1] 3