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

is_sub_path {xfun} | R 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)

[Package xfun version 0.23 Index]