README.md

family

R-CMD-check Codecov test
coverage

The goal of the this package is to make it easy to reference a family of related directories, with one or more children directories under the same parent directory.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("maurolepore/family")

Example

library(family)
library(fs)

Here is a collection of related packages (“sister”, “brother”) and one unrelated neighbour (“them”), all under the same parent directory (“mother”).

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

To define the family we add an empty file under the root of each sibling. You may name it anything, maybe starting with “.” so the file is hidden.

family_name <- ".us"
family_regexp <- "^[.]us$"
file_create(path(mother, siblings, family_name))

dir_tree(mother, recurse = TRUE, all = TRUE)
#> /tmp/RtmpYYiJt1/mother
#> ├── brother
#> │   └── .us
#> ├── neighbour
#> └── sister
#>     └── .us

find_family() finds the family from anywhere.

find_family(parent = mother, regexp = family_regexp)
#> [1] "/tmp/RtmpYYiJt1/mother/brother" "/tmp/RtmpYYiJt1/mother/sister"

A handful of other functions help you work more comfortably when your working directory is set to either the parent directory or one level under it. For example, siblngs() finds the family from any family member or unrelated neighbour.

setwd(path(mother, "neighbour"))
siblings(family_regexp, self = TRUE)
#> [1] "/tmp/RtmpYYiJt1/mother/brother" "/tmp/RtmpYYiJt1/mother/sister"

setwd(path(mother, "sister"))
siblings(family_regexp, self = TRUE)
#> [1] "/tmp/RtmpYYiJt1/mother/brother" "/tmp/RtmpYYiJt1/mother/sister"

siblings(family_regexp)
#> [1] "/tmp/RtmpYYiJt1/mother/brother"

# Save typing and reuse code with other families
options(family.regexp = family_regexp)
siblings()
#> [1] "/tmp/RtmpYYiJt1/mother/brother"


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