find_root: Find the root of a directory hierarchy

View source: R/root.R

find_rootR Documentation

Find the root of a directory hierarchy

Description

A root is defined as a directory that contains a regular file whose name matches a given pattern and which optionally contains a given text. The search for a root starts at a given directory (the working directory by default), and proceeds up the directory hierarchy.

get_root_desc() returns the description of the criterion for a root path. This is especially useful for composite root criteria created with |.root_criterion().

Usage

find_root(criterion, path = ".")

get_root_desc(criterion, path)

Arguments

criterion

⁠[root_criterion]⁠
A criterion, one of the predefined criteria or created by root_criterion(). Will be coerced using as_root_criterion().

path

⁠[character(1)]⁠
The start directory.

Details

Starting from the working directory, the find_root() function searches for the root. If a root is found, the ... arguments are used to construct a path; thus, if no extra arguments are given, the root is returned. If no root is found, an error is thrown.

Value

The normalized path of the root as specified by the search criterion. Throws an error if no root is found

See Also

utils::glob2rx() file.path()

Examples

## Not run: 
find_root(glob2rx("DESCRIPTION"), "^Package: ")

## End(Not run)


rprojroot documentation built on Nov. 5, 2023, 5:06 p.m.