| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/paths.R |
| 3 |
\name{proj_root} |
| 4 |
\alias{proj_root} |
| 5 |
\alias{root_rules} |
| 6 |
\title{Return the (possible) root directory of a project} |
| 7 |
\usage{ |
| 8 |
proj_root(path = "./", rules = root_rules) |
| 9 |
|
| 10 |
root_rules |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{path}{The initial path to start the search. If it is a file path, its |
| 14 |
parent directory will be used.} |
| 15 |
|
| 16 |
\item{rules}{A matrix of character strings of two columns: the first column |
| 17 |
contains regular expressions to look for filenames that match the patterns, |
| 18 |
and the second column contains regular expressions to match the content of |
| 19 |
the matched files. The regular expression can be an empty string, meaning |
| 20 |
that it will match anything.} |
| 21 |
} |
| 22 |
\value{ |
| 23 |
Path to the root directory if found, otherwise \code{NULL}. |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Given a path of a file (or dir) in a potential project (e.g., an R package or |
| 27 |
an RStudio project), return the path to the project root directory. |
| 28 |
} |
| 29 |
\details{ |
| 30 |
The search for the root directory is performed by a series of tests, |
| 31 |
currently including looking for a \file{DESCRIPTION} file that contains |
| 32 |
\verb{Package: *} (which usually indicates an R package), and a |
| 33 |
\file{*.Rproj} file that contains \verb{Version: *} (which usually indicates |
| 34 |
an RStudio project). If files with the expected patterns are not found in the |
| 35 |
initial directory, the search will be performed recursively in upper-level |
| 36 |
directories. |
| 37 |
} |
| 38 |
\note{ |
| 39 |
This function was inspired by the \pkg{rprojroot} package, but is much |
| 40 |
less sophisticated. It is a rather simple function designed to be used in |
| 41 |
some of packages that I maintain, and may not meet the need of general |
| 42 |
users until this note is removed in the future (which should be unlikely). |
| 43 |
If you are sure that you are working on the types of projects mentioned in |
| 44 |
the \sQuote{Details} section, this function may be helpful to you, |
| 45 |
otherwise please consider using \pkg{rprojroot} instead. |
| 46 |
} |