Find the root of a directory hierarchy

Usage

find_root(filename, contents = NULL, n = -1L, path = getwd())

Arguments

filename
Regular expressions to match the file name or contents
contents
Regular expressions to match the file name or contents
n
integer. The (maximal) number of lines to read. Negative values indicate that one should read up to the end of input on the connection.
path
The start directory

Value

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

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.

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.

Examples

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

See also

glob2rx file.path