Search for regex patterns in a text column and display matching tokens,
counts, and highlighted text. Unlike other pipeline functions, edstr_view()
does not save results — it is meant for iterating on patterns before
extraction.
Usage
edstr_view(
data,
text_input = getOption("edstr_text"),
id = NULL,
replace = NULL,
pattern = NULL,
ngrams = 1,
...
)Arguments
- data
<data.frame>The data to search.- text_input
<character(1)>Name of the text column. Defaults to theedstr_textoption set byedstr_config().- id
<character(1)>Name of the unique identifier column. If not supplied, detected automatically: the one column with no duplicates and noNA, aborting if none or several qualify.- replace
A named character vector or list of named character vectors. Optional regex replacements applied to the text before matching (see
edstr_clean()for details).- pattern
<character(1)>Regex pattern to search for. Required.- ngrams
<integer(1)>Width of the regex window captured around a match, the matched word included (default1).edstr_view()does not tokenise: the value widenspatternby up tongrams - 1further words, songrams = 3withpattern = "diabete"matches"diabete type 2". Distinct from thengram_maxargument ofedstr_extract(), which sets the n-gram sizes searched rather than a display window.- ...
Additional arguments passed to
stringr::str_view().
Value
Invisibly returns a list with three elements:
matchA tibble of all matches with the
idandmatchcolumns.countA tibble of distinct matches with their frequency.
textOutput of
stringr::str_view()for visual inspection.
Examples
df <- data.frame(
id = 1:3,
note = c("diabete type 2", "bilan normal", "diabete gestationnel")
)
edstr_view(data = df, text_input = "note", pattern = "diabete", ngrams = 3)
#>
#> ── edstr_view ──────────────────────────────────────────────────────────────────
#>
#> # A tibble: 2 × 2
#> match n
#> <chr> <int>
#> 1 diabete gestationnel 1
#> 2 diabete type 2 1
#>
#> ────────────────────────────────────────────────────────────────────────────────
#>
#> Full steps: 0.02 sec elapsed
#>
#> ℹ Documents: 3 id
#>
#> ℹ Matches
#> • Total: 2 across 2 id (66.7% id)
#> • Distinct: 2
#>
#> ────────────────────────────────────────────────────────────────────────────────
#>