str_truth {tinycodet}R Documentation

'stringi' Pattern Detection Operators

Description

The x %s{}% p operator checks for every string in character vector x if the pattern defined in p is present.

The x %s!{}% p operator checks for every string in character vector x if the pattern defined in p is NOT present.

Usage

x %s{}% p

x %s!{}% p

Arguments

x

a string or character vector.

p

either a list with 'stringi' arguments (see s_regex), or else a character vector of the same length as x with regular expressions.
[REGEX]
[FIXED]
[COLL]
[CHARCLASS]

Value

The x %s{}% p and x %s!{}% p operators return logical vectors, where TRUE indicates a pattern was found, and FALSE indicates a pattern was not found.

See Also

tinycodet_strings()

Examples


# simple pattern ====

x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
x %s{}% "a"
x %s!{}% "a"
which(x %s{}% "a")
which(x %s!{}% "a")
x[x %s{}% "a"]
x[x %s!{}% "a"]
x[x %s{}% "a"] <- 1
x[x %s!{}% "a"] <- 1
print(x)

x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
x %s{}% "1"
x %s!{}% "1"
which(x %s{}% "1")
which(x %s!{}% "1")
x[x %s{}% "1"]
x[x %s!{}% "1"]
x[x %s{}% "1"] <- "a"
x[x %s!{}% "1"] <- "a"
print(x)


#############################################################################

# ignore case pattern ====


x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
p <- list(regex = c("A", "A"), case_insensitive=TRUE)
x %s{}% p
x %s!{}% p
which(x %s{}% p)
which(x %s!{}% p)
x[x %s{}% p]
x[x %s!{}% p]
x[x %s{}% p] <- "hello"
x[x %s!{}% p] <- "hello"
print(x)


#############################################################################

# multi-character pattern ====

x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
p <- list(regex = rep("AB", 2), case_insensitive=TRUE)
x %s{}% p
x %s!{}% p
which(x %s{}% p)
which(x %s!{}% p)
x[x %s{}% p]
x[x %s!{}% p]
x[x %s{}% p] <- "CD"
x[x %s!{}% p] <- "CD"
print(x)




[Package tinycodet version 0.3.0 Index]