before: Extract the Elements of a Path Before/After a Regex...

Description Usage Arguments Value See Also Examples

Description

Extract the elements of a path before/after a regex occurrence. Stands in contrast to front,back, and index in that with the later three are element number/index focused whereas before/after are content focused.

Usage

1
2
3
before(x, pattern, include = FALSE, collapse = TRUE, ...)

after(x, pattern, include = FALSE, collapse = TRUE, ...)

Arguments

x

A parse_path object.

pattern

A character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Note that under the hood grep is used to locate the indices of path elements that match the regex condition. Only the first match will be used. The argument perl = TRUE is hard coded.

include

logical. If TRUE the element with the regex match will be included in the reconstructed sub-path.

collapse

logical. If TRUE the path elements will be collapsed with the "/" separator.

...

ignored.

Value

Returns a vector (either atomic or list of character path elements) of sub-paths.

See Also

Other sub-path manipulation functions: front, index, swap

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
(parsed <- list(c("a", "really", "boring", "path", "for", "R")))
before(parsed, "^bor")
before(parsed, "^bor", include = TRUE)

after(parsed, "^bor")
after(parsed, "^bor", include = TRUE)

library(magrittr)
files %>%
    parse_path() %>%
    after("^qdap$")

files %>%
    parse_path() %>%
    after("^qdap$", include = TRUE)

files %>%
    parse_path() %>%
    before("\\.R$")

trinker/pathr documentation built on May 31, 2019, 9:41 p.m.