Usage
split_by_pattern(
x,
start_pattern = "^# |^## |---",
end_pattern = NULL,
name_list = TRUE,
include_start = FALSE
)
Arguments
- x
A
character
vector.- start_pattern
(Optional) A string with the start pattern (Default:
"^# |^## |---"
).- end_pattern
(Optional) A string with the end pattern. Use
NULL
if there isn't one (Default:NULL
).- name_list
(Optional) A
logical
flag indicating if each output item should have a name (Default:TRUE
).- include_start
(Optional) A
logical
flag indicating if the line flagged in the start pattern should be included in the split (Default:FALSE
).
Value
A list with the split character vector.
Examples
x <- c(
"# Title 1",
"## Subtitle 1",
"Content 1",
"Content 2",
"# Title 2",
"## Subtitle 2",
"Content 3",
"Content 4"
)
split_by_pattern(
x,
start_pattern = "^# |^## |---",
end_pattern = NULL,
name_list = TRUE,
include_start = FALSE
)
#> $`# Title 1 [line 1]`
#> character(0)
#>
#> $`## Subtitle 1 [line 2]`
#> [1] "Content 1" "Content 2"
#>
#> $`# Title 2 [line 5]`
#> character(0)
#>
#> $`## Subtitle 2 [line 6]`
#> [1] "Content 3" "Content 4"
#>