root_criterion | 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)
## 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)
testfun |
|
desc |
|
subdir |
|
x |
|
y |
|
filepath |
|
contents , fixed |
|
n |
|
pattern |
|
basename |
|
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.
An S3 object of class root_criterion
with the following members:
testfun
The testfun
argument
desc
The desc
argument
subdir
The subdir
argument
find_file
A function with ...
and path
arguments
that returns a path relative to the root,
as specified by this criterion.
The optional path
argument specifies the starting directory,
which defaults to "."
.
The function forwards to find_root_file()
,
which passes ...
directly to file.path()
if the first argument is an absolute path.
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
## Not run:
is_r_package$find_file
is_r_package$make_fix_file(".")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.