EVOLUTION-MANAGER
Edit File: root_criterion.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Is a directory the project root?</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for root_criterion {rprojroot}"><tr><td>root_criterion {rprojroot}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Is a directory the project root?</h2> <h3>Description</h3> <p>Objects of the <code>root_criterion</code> class decide if a given directory is a project root. </p> <h3>Usage</h3> <pre> 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) has_dir(filepath) has_file_pattern(pattern, contents = NULL, n = -1L) has_dirname(dirname, subdir = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>testfun</code></td> <td> <p>A function with one parameter that returns <code>TRUE</code> if the directory specified by this parameter is the project root, and <code>FALSE</code> otherwise. Can also be a list of such functions.</p> </td></tr> <tr valign="top"><td><code>desc</code></td> <td> <p>A textual description of the test criterion, of the same length as <code>testfun</code></p> </td></tr> <tr valign="top"><td><code>subdir</code></td> <td> <p>Subdirectories to start the search in, if found</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>An object</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>An object</p> </td></tr> <tr valign="top"><td><code>filepath</code></td> <td> <p>File path (can contain directories)</p> </td></tr> <tr valign="top"><td><code>contents</code></td> <td> <p>Regular expression to match the file contents</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>integer. The (maximal) number of lines to read. Negative values indicate that one should read up to the end of input on the connection.</p> </td></tr> <tr valign="top"><td><code>pattern</code></td> <td> <p>Regular expression to match the file name</p> </td></tr> <tr valign="top"><td><code>dirname</code></td> <td> <p>A directory name, without subdirectories</p> </td></tr> </table> <h3>Details</h3> <p>Construct criteria using <code>root_criterion</code> in a very general fashion by specifying a function with a <code>path</code> argument, and a description. </p> <p>The <code>as.root_criterion()</code> function accepts objects of class <code>root_criterion</code>, and character values; the latter will be converted to criteria using <code>has_file</code>. </p> <p>Root criteria can be combined with the <code>|</code> operator. The result is a composite root criterion that requires either of the original criteria to match. </p> <p>The <code>has_file()</code> 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. </p> <p>The <code>has_dir()</code> function constructs a criterion that checks for the existence of a specific directory. </p> <p>The <code>has_file_pattern()</code> function constructs a criterion that checks for the existence of a file that matches a pattern, with specific contents. </p> <p>The <code>has_dirname()</code> function constructs a criterion that checks if the <code><a href="../../base/html/dirname.html">base::dirname()</a></code> has a specific name. </p> <h3>Value</h3> <p>An S3 object of class <code>root_criterion</code> wit the following members: </p> <dl> <dt><code>testfun</code></dt><dd><p>The <code>testfun</code> argument</p> </dd> <dt><code>desc</code></dt><dd><p>The <code>desc</code> argument</p> </dd> <dt><code>subdir</code></dt><dd><p>The <code>subdir</code> argument</p> </dd> <dt><code>find_file</code></dt><dd><p>A function with <code>...</code> argument that returns for a path relative to the root specified by this criterion. The optional <code>path</code> argument specifies the starting directory, which defaults to <code>"."</code>. </p> </dd> <dt><code>make_fix_file</code></dt><dd><p>A function with a <code>path</code> argument that returns a function that finds paths relative to the root. For a criterion <code>cr</code>, the result of <code>cr$make_fix_file(".")(...)</code> is identical to <code>cr$find_file(...)</code>. The function created by <code>make_fix_file</code> can be saved to a variable to be more independent of the current working directory. </p> </dd> </dl> <h3>Examples</h3> <pre> 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) </pre> <hr /><div style="text-align: center;">[Package <em>rprojroot</em> version 1.3-2 <a href="00Index.html">Index</a>]</div> </body></html>