knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Sometimes you need to work with a family of repositories nested one level under a parent repository. Those sibling repositories usually have a number of unrelated neighbour repositories you with to ignore. Using the analogy form real families, the "family" package uses solves this problem with a small number of focused and intuitive tools.

Here we'll work with a collection of related packages ("sister", "brother", and "me") ignoring one unrelated neighbour ("them"), all under the same parent directory ("mother").

library(family)
library(fs)

mother <- path(tempdir(), "mother")
siblings <- c("sister", "brother")
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)
find_family(parent = mother, regexp = family_regexp)

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. This assumption makes the interface of the helpers simpler -- they all lack the parent argument.

setwd(mother)

children(family_regexp)
setwd(path(mother, "sister"))

siblings(family_regexp)

siblings(family_regexp, self = TRUE)
# Same
setwd(path(mother, "neighbour"))
siblings(family_regexp)

You may pass the family argument directly or via options().

setwd(path(mother, "sister"))
options(family.regexp = family_regexp)

siblings()
siblings(self = TRUE)

This saves you a little typing but most importantly allows you to reuse the code with other families.



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