match_in_substr | R Documentation |
Match strings that have a needle near the start, end, or middle
match_in_substr(str, query, buffer = 0.25, from = "s", values = FALSE)
str |
(Character) The vector to be searched. |
query |
(Character) The regular expression to look for. If |
buffer |
(Numeric) The length of the substring to search. If given as a whole number,
it will be that many characters long. If given as a decimal number, it will be used
as a proportion of the length of each element in |
from |
(Character) If |
values |
(Logical) If |
A Logical vector if values == FALSE
(default), or a Character vector
if values == TRUE
.
sentences <- c(
"The word 'needle' appears at the start of this sentence.",
"But in this sentence, 'needle' doesn't.",
"If 'needle' appears several times in a sentence, then we have a lot of needles!",
"And in here, the word we want to find (needle) is near the middle of the sentence."
)
# Within 20 characters of the Start of the string
match_in_substr(sentences, "needle", 20, "s")
#> [1] TRUE FALSE TRUE FALSE
# In the last 25% of the string
match_in_substr(sentences, "needle", 0.25, "e")
#> [1] FALSE FALSE TRUE FALSE
# In the middle 1/3rd of the string
match_in_substr(sentences, "needle", 1/3, "m")
#> [1] FALSE FALSE FALSE TRUE
match_in_substr(sentences, "needle", 1/3, "m", values = TRUE)
#> [1] "And in here, the word we want to find (needle) is near the middle of the sentence."
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.