sub_all: Extract and replace all subsequences from a bstr sequences

Description Usage Arguments Examples

Description

Extract and replace all subsequences from a bstr sequences

Usage

1
2
3
4
5
6
7
bstr_sub_all(bstrobj, from = list(1L), to = list(-1L), length)

bstr_sub_all(bstrobj, from = list(1L), to = list(-1L), length, omit_na = FALSE) <- value

bstr_sub_replace_all(..., replacement, value = replacement)

bstr_sub_all_replace(..., replacement, value = replacement)

Arguments

bstrobj

bstr class object or character vector

from

a list of integer vectors giving the start indexes or a list of two-column matrices, each of type cbind(from, to)

to

a list of integer vectors giving the end indexes

length

a list of integer vectors giving the substring lengths

omit_na

a single logical value; indicates whether missing values in any of the indexes or in value leave the part of the corresponding input string unchanged [replacement function only]

value

a list of character vectors defining the replacement strings [replacement function only]

...

arguments to be passed to bstr_sub_all<-

replacement

alias of value [wherever applicable]

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
(temp <- dstr_rand_seq(3, 20, "[AT]", seed = 1))

(pos_A_trails <- stringr::str_locate_all(temp, "A{2,}"))

# Extract all A trails
bstr_sub_all(temp, pos_A_trails)

# Substitute all A trails by x
bstr_sub_all(temp, pos_A_trails) <- "x"
temp

# Substitute all A trails by case switched ones
original <- change <- dstr_rand_seq(2, 10, "[AaT]", seed = 1)
pos_A_trails <- stringr::str_locate_all(change, "[Aa]{2,}")
switched_A_trails <-
  bstr_sub_all(change, pos_A_trails) %>%
  lapply(bstr_switch_case)
bstr_sub_all(change, pos_A_trails) <- switched_A_trails
c(original[1], change[1], original[2], change[2])

t-arae/bstringr documentation built on March 18, 2021, 3:08 a.m.