front: Extract the First/Last N Elements of a Path

Description Usage Arguments Value See Also Examples

Description

front - Extract the first n elements of a path. Similar to head (uses head under the hood). Compare the defualt settings to basename and dirname.

back - Extract the first n elements of a path. Similar to tail (uses tail under the hood).

Usage

1
2
3
front(x, n = -1, collapse = TRUE, ...)

back(x, n = 1, collapse = TRUE, ...)

Arguments

x

A parse_path object.

n

A single integer. If positive, size for the resulting object: number of elements for a vector. If negative, all but the n last/first number of elements of x.

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

basename, dirname

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
front(list(1:8), 3)
front(list(1:8), -3)

back(list(1:8), 3)
back(list(1:8), -3)

library(magrittr)
files %>%
    parse_path() %>%
    front()

files %>%
    parse_path() %>%
    front(3)

files %>%
    parse_path() %>%
    back()

files %>%
    parse_path() %>%
    back(3)

## Compare to basename/dirname
(fls <- file.path("","p1","p2","p3", c("file.pdf", "file.txt", "file.Rmd")))

basename(fls)
fls %>%
    parse_path() %>%
    back()

dirname(fls)
fls %>%
    parse_path() %>%
    front()

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