ipat: Simplified string indexing for fixed patterns

View source: R/ipat.R

ipatR Documentation

Simplified string indexing for fixed patterns

Description

Logically index, numerically index, and count the number of times a pattern occurs.

Usage

ipat(x, pat)

has_pat(x, pat)

wpat(x, pat)

npat(x, pat)

ppat(x, pat)

ppats(x, pat)

Arguments

x

A character vector.

pat

A fixed value complete string scalar pattern to search for in x.

Details

  has_pat   Evaluates whether each element of x contains the string in pat.
   
  ppats Identifies the position of the first character of every instance of a pattern in each element of a character vector.
   
  ppat Identifies the position of the first character of the first instance of a pattern in each element of a character vector.
   
  npat Counts the number of times a pattern appears in each element of a character vector.
   
  ipat Logically indexes character vector elements containing a pattern as TRUE or FALSE.
   
  wpat Numerically indexes character vector elements containing a pattern as integer element numbers.



These functions Always atomizes ... to create a single character vector to search for a fixed pattern.

Value

A positive whole number vlist

ppats

A positive whole number vector

⁠wpat, npat, ppat⁠

A logical scalar

⁠has_pat, ipat⁠

See Also

Other strings: blank(), chn(), delim(), fsub(), gr, makestr(), markdown_help(), maxnch(), ox(), ox_vals(), pgrid_help(), revstr(), spaces(), ss_help(), tocase(), weave()

Examples

words <- c("apple", "banana", "carrot")
has_pat(words, "a")
ipat(words, "a")
has_pat(words, "b")
ipat(words, "b")
wpat(words, "a")
wpat(words, "b")
npat(words, "a")
npat(words, "b")
ppat(words, "a")
ppat(words, "b")
ppats(words, "a")
ppats(words, "b")

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.