Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

is_sub_path

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

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.