root_criterion {rprojroot} | R Documentation |
Objects of the root_criterion
class decide if a
given directory is a project root.
root_criterion(testfun, desc, subdir = NULL) is.root_criterion(x) as.root_criterion(x) ## S3 method for class 'character' as.root_criterion(x) ## S3 method for class 'root_criterion' as.root_criterion(x) has_file(filepath, contents = NULL, n = -1L) has_file_pattern(pattern, contents = NULL, n = -1L) has_dirname(dirname, subdir = NULL)
testfun |
A function with one parameter that returns |
desc |
A textual description of the test criterion |
subdir |
Subdirectories to start the search in, if found |
x |
An object |
filepath |
File path (can contain directories) |
contents |
Regular expression to match the file 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. |
pattern |
Regular expression to match the file name |
dirname |
A directory name, without subdirectories |
Construct criteria using root_criterion
in a very general fashion
by specifying a function with a path
argument, and a description.
The as.root_criterion
function accepts objects of class
root_criterion
, and character values; the latter will be
converted to criteria using has_file
.
The has_file
function constructs a criterion that checks for the
existence of a specific file (which itself can be in a subdirectory of the
root) with specific contents.
The has_file_pattern
function constructs a criterion that checks for the
existence of a file that matches a pattern, with specific contents.
The has_dirname
function constructs a criterion that checks if the
dirname
has a specific name.
An S3 object of class root_criterion
wit the following members:
testfun
The testfun
argument
desc
The desc
argument
subdir
The subdir
argument
find_file
A function with ...
argument that returns
for a path relative to the root specified by this criterion.
The optional path
argument specifies the starting directory,
which defaults to "."
.
make_fix_file
A function with a path
argument that
returns a function that finds paths relative to the root. For a
criterion cr
, the result of cr$make_fix_file(".")(...)
is identical to cr$find_file(...)
. The function created by
make_fix_file
can be saved to a variable to be more independent
of the current working directory.
root_criterion(function(path) file.exists(file.path(path, "somefile")), "Has somefile") has_file("DESCRIPTION") is_r_package is_r_package$find_file ## Not run: is_r_package$make_fix_file(".") ## End(Not run)