find_family: Find directories of a family

Description Usage Arguments Value Examples

View source: R/find_family.R

Description

Find directories of a family

Usage

1
2
3
4
5
6
7

Arguments

parent

A string giving a single path to the parent directory. The children directories should be nested one level under it.

regexp

A regular expression to match the name of the file that defines the family. You may pass it directly of with "options()", e.g. options(family.regexp = "^[.]us$").

self

Include the working directory in the output? Yes: TRUE; No: FALSE.

Value

A character vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library(fs)
library(family)

restore_working_directory <- getwd()

mother <- path(tempdir(), "mother")
siblings <- c("sister", "brother")
neighbour <- "neighbour"
dir_create(path(mother, c(siblings, neighbour)))

# Define the family with any identifying file in the root of each sibling
family_name <- ".us"
family_regexp <- "^[.]us$"
file_create(path(mother, siblings, family_name))

dir_tree(mother, recurse = TRUE, all = TRUE)

# Find the family from anywhere
find_family(parent = mother, regexp = family_regexp)

# Find the family from the parent, the siblings or their neighbours
setwd(path(mother, "neighbour"))
siblings(family_regexp, self = TRUE)

setwd(path(mother, "sister"))
siblings(family_regexp, self = TRUE)

siblings(family_regexp)

# Save typing and reuse code with other families
restore_options <- options(family.regexp = family_regexp)
siblings()

parent()

setwd(parent())
children()

# Cleanup
options(restore_options)
setwd(restore_working_directory)

maurolepore/family documentation built on Dec. 21, 2021, 3:50 p.m.