is_sub_path: Test if a path is a subpath of a dir

View source: R/paths.R

is_sub_pathR Documentation

Test if a path is a subpath of a dir

Description

Check if the path starts with the dir path.

Usage

is_sub_path(x, dir, n = nchar(dir))

Arguments

x

A vector of paths.

dir

A vector of directory paths.

n

The length of dir paths.

Value

A logical vector.

Note

You may want to normalize the values of the x and dir arguments first (with xfun::normalize_path()), to make sure the path separators are consistent.

Examples

xfun::is_sub_path("a/b/c.txt", "a/b")  # TRUE
xfun::is_sub_path("a/b/c.txt", "d/b")  # FALSE
xfun::is_sub_path("a/b/c.txt", "a\\b")  # FALSE (even on Windows)

xfun documentation built on Nov. 17, 2022, 1:06 a.m.