path_select_components: Select path components by their position/index.

View source: R/path_select.R

path_select_componentsR Documentation

Select path components by their position/index.

Description

path_select_components() allows to select individual components from an fs_path object via their index.

Usage

path_select_components(path, index, from = c("start", "end"))

Arguments

path

A path of class fs_path.

index

An integer vector of path positions. (A negative index will work according to R's usual subsetting rules.)

from

A character of either "start" or "end" to choose if indexing should start from the first or last component of the path.

Details

path_select_components() is vectorized.

Value

An fs_path object, which is a character vector that also has class fs_path.

Examples

path <- fs::path("some", "simple", "path", "to", "a", "file.txt")

path_select_components(path, 1:3)

path_select_components(path, 1:3, "end")

path_select_components(path, -1, "end")

path_select_components(path, 6)

r-lib/fs documentation built on July 4, 2025, 9:24 p.m.