find_path | R Documentation |
Try to find path
under root directory even
if the original path is missing; see examples.
find_path(path, root_dir, all = FALSE)
path |
file path |
root_dir |
top directory of the search path |
all |
return all possible paths, default is false |
When file is missing, find_path
concatenates the
root directory and path combined to find the file. For example,
if path is "a/b/c/d"
,
the function first seek for existence of "a/b/c/d"
. If failed,
then "b/c/d"
, and then "~/c/d"
until reaching
root directory. If all=TRUE
, then all files/directories found
along the search path will be returned
The absolute path of file if exists, or NULL
if
missing/failed.
root <- tempdir()
# ------ Case 1: basic use case -------
# Create a path in root
dir_create2(file.path(root, 'a'))
# find path even it's missing. The search path will be
# root/ins/cd/a - missing
# root/cd/a - missing
# root/a - exists!
find_path('ins/cd/a', root)
# ------ Case 2: priority -------
# Create two paths in root
dir_create2(file.path(root, 'cc/a'))
dir_create2(file.path(root, 'a'))
# If two paths exist, return the first path found
# root/ins/cd/a - missing
# root/cd/a - exists - returned
# root/a - exists, but ignored
find_path('ins/cc/a', root)
# ------ Case 3: find all -------
# Create two paths in root
dir_create2(file.path(root, 'cc/a'))
dir_create2(file.path(root, 'a'))
# If two paths exist, return the first path found
# root/ins/cd/a - missing
# root/cd/a - exists - returned
# root/a - exists - returned
find_path('ins/cc/a', root, all = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.