| root_criterion {rprojroot} | R Documentation |
Is a directory the project root?
Description
Objects of the root_criterion class decide if a
given directory is a project root.
Usage
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)
## S3 method for class 'root_criterion'
x | y
has_file(filepath, contents = NULL, n = -1L, fixed = FALSE)
has_dir(filepath)
has_file_pattern(pattern, contents = NULL, n = -1L, fixed = FALSE)
has_basename(basename, subdir = NULL)
Arguments
testfun |
|
desc |
|
subdir |
|
x |
|
y |
|
filepath |
|
contents, fixed |
|
n |
|
pattern |
|
basename |
|
Details
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.
Root criteria can be combined with the | operator. The result is a
composite root criterion that requires either of the original criteria to
match.
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_dir() function constructs a criterion that checks for the
existence of a specific directory.
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_basename() function constructs a criterion that checks if the
base::basename() of the root directory has a specific name,
with support for case-insensitive file systems.
Value
An S3 object of class root_criterion wit the following members:
testfunThe
testfunargumentdescThe
descargumentsubdirThe
subdirargumentfind_fileA function with
...andpatharguments that returns a path relative to the root, as specified by this criterion. The optionalpathargument specifies the starting directory, which defaults to".". The function forwards tofind_root_file(), which passes...directly tofile.path()if the first argument is an absolute path.make_fix_fileA function with a
pathargument that returns a function that finds paths relative to the root. For a criterioncr, the result ofcr$make_fix_file(".")(...)is identical tocr$find_file(...). The function created bymake_fix_file()can be saved to a variable to be more independent of the current working directory.
Examples
root_criterion(function(path) file.exists(file.path(path, "somefile")), "has somefile")
has_file("DESCRIPTION")
is_r_package
## Not run:
is_r_package$find_file
is_r_package$make_fix_file(".")
## End(Not run)