| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/paths.R |
| 3 |
\name{magic_path} |
| 4 |
\alias{magic_path} |
| 5 |
\title{Find a file or directory under a root directory} |
| 6 |
\usage{ |
| 7 |
magic_path( |
| 8 |
..., |
| 9 |
root = proj_root(), |
| 10 |
relative = TRUE, |
| 11 |
error = TRUE, |
| 12 |
message = getOption("xfun.magic_path.message", TRUE), |
| 13 |
n_dirs = getOption("xfun.magic_path.n_dirs", 10000) |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{...}{A character vector of path components.} |
| 18 |
|
| 19 |
\item{root}{The root directory under which to search for the path. If |
| 20 |
\code{NULL}, the current working directory is used.} |
| 21 |
|
| 22 |
\item{relative}{Whether to return a relative path.} |
| 23 |
|
| 24 |
\item{error}{Whether to signal an error if the path is not found, or multiple |
| 25 |
paths are found.} |
| 26 |
|
| 27 |
\item{message}{Whether to emit a message when multiple paths are found and |
| 28 |
\code{error = FALSE}.} |
| 29 |
|
| 30 |
\item{n_dirs}{The number of subdirectories to recursively search. The |
| 31 |
recursive search may be time-consuming when there are a large number of |
| 32 |
subdirectories under the root directory. If you really want to search for |
| 33 |
all subdirectories, you may try \code{n_dirs = Inf}.} |
| 34 |
} |
| 35 |
\value{ |
| 36 |
The path found under the root directory, or an error when \code{error = TRUE} and the path is not found (or multiple paths are found). |
| 37 |
} |
| 38 |
\description{ |
| 39 |
Given a path, try to find it recursively under a root directory. The input |
| 40 |
path can be an incomplete path, e.g., it can be a base filename, and |
| 41 |
\code{magic_path()} will try to find this file under subdirectories. |
| 42 |
} |
| 43 |
\examples{ |
| 44 |
\dontrun{ |
| 45 |
xfun::magic_path("mtcars.csv") # find any file that has the base name mtcars.csv |
| 46 |
} |
| 47 |
} |