Introduction

We identify relations to an individual using the family of get_*() functions.

We illustrate their functionality using the family below consisting of three generations: A pair of parents who has a single child (named ‘Main Person’). This person forms two separate family groups with two spouses, each resulting in two children.

library(tidyged)

three_gen <- gedcom(subm("Me")) |> 
  add_indi(qn = "Parent 1") |> 
  add_indi(qn = "Parent 2") |> 
  add_indi(qn = "Main Person") |> 
  add_indi(qn = "Spouse 1") |> 
  add_indi(qn = "Spouse 2") |>
  add_indi(qn = "Child 1") |> 
  add_indi(qn = "Child 2") |> 
  add_indi(qn = "Child 3") |> 
  add_indi(qn = "Child 4")
#> Added Unknown Individual: @I1@
#> Added Unknown Individual: @I2@
#> Added Unknown Individual: @I3@
#> Added Unknown Individual: @I4@
#> Added Unknown Individual: @I5@
#> Added Unknown Individual: @I6@
#> Added Unknown Individual: @I7@
#> Added Unknown Individual: @I8@
#> Added Unknown Individual: @I9@

p1_xref <- find_indi_name(three_gen, "Parent 1")
p2_xref <- find_indi_name(three_gen, "Parent 2")
main_xref <- find_indi_name(three_gen, "Main")
s1_xref <- find_indi_name(three_gen, "Spouse 1")
s2_xref <- find_indi_name(three_gen, "Spouse 2")
c12_xref <- find_indi_name_all(three_gen, "Child 1|Child 2")
c34_xref <- find_indi_name_all(three_gen, "Child 3|Child 4")

three_gen <- three_gen |>
  add_famg(p1_xref, p2_xref, children = main_xref) |> 
  add_famg(main_xref, s1_xref, children = c12_xref) |>
  add_famg(main_xref, s2_xref, children = c34_xref)
#> Added Family Group: @F1@
#> Added Family Group: @F2@
#> Added Family Group: @F3@

df_famg(three_gen) |> 
  knitr::kable()
xref husband wife relationship_type relationship_date relationship_place num_children last_modified
@F1@ Parent 1 Parent 2 1 22 JUN 2022
@F2@ Main Person Spouse 1 2 22 JUN 2022
@F3@ Main Person Spouse 2 2 22 JUN 2022

Immediate relations

The examples below illustrate the functions.

get_indi_partners(three_gen, main_xref) |> describe_records(gedcom = three_gen)
#> [1] "Individual @I4@, Spouse 1" "Individual @I5@, Spouse 2"
get_indi_parents(three_gen, main_xref) |> describe_records(gedcom = three_gen)
#> [1] "Individual @I1@, Parent 1" "Individual @I2@, Parent 2"
get_indi_children(three_gen, main_xref) |> describe_records(gedcom = three_gen)
#> [1] "Individual @I6@, Child 1, child of Main Person and Spouse 1"
#> [2] "Individual @I7@, Child 2, child of Main Person and Spouse 1"
#> [3] "Individual @I8@, Child 3, child of Main Person and Spouse 2"
#> [4] "Individual @I9@, Child 4, child of Main Person and Spouse 2"
get_indi_siblings(three_gen, find_indi_name(three_gen, "Child 1")) |> describe_records(gedcom = three_gen)
#> [1] "Individual @I7@, Child 2, child of Main Person and Spouse 1"
get_indi_siblings(three_gen, find_indi_name(three_gen, "Child 1"), inc_half_sibs = TRUE, return_name = TRUE)
#> [1] "Child 2" "Child 3" "Child 4"
get_families_as_child(three_gen, main_xref) |> describe_records(gedcom = three_gen)
#> [1] "Family @F1@, headed by Parent 1 and Parent 2, and children: Main Person"
get_families_as_partner(three_gen, main_xref) |> describe_records(gedcom = three_gen)
#> [1] "Family @F2@, headed by Main Person and Spouse 1, and children: Child 1, Child 2"
#> [2] "Family @F3@, headed by Main Person and Spouse 2, and children: Child 3, Child 4"
get_famg_partners(three_gen, "@F1@") |> describe_records(gedcom = three_gen)
#> [1] "Individual @I1@, Parent 1" "Individual @I2@, Parent 2"
get_famg_children(three_gen, "@F2@", return_name = TRUE)
#> [1] "Child 1" "Child 2"

Many functions include a birth_only parameter which allows you to focus on purely biological relationships and/or a return_name parameter which allows you to return individual’s names instead.

Branches

One of the more sophisticated features of tidyged is the ability to manipulate entire branches of your tree.

Descendants

We use the get_descendants() function below to identify the descendants of Main Person. By default it will exclude the individual, all spouses, and all associated family groups:

get_descendants(three_gen, main_xref)
#> [1] "@I6@" "@I7@" "@I8@" "@I9@"

We can use the describe_records() function to see descriptions:

get_descendants(three_gen, main_xref) |>
  describe_records(gedcom = three_gen)
#> [1] "Individual @I6@, Child 1, child of Main Person and Spouse 1"
#> [2] "Individual @I7@, Child 2, child of Main Person and Spouse 1"
#> [3] "Individual @I8@, Child 3, child of Main Person and Spouse 2"
#> [4] "Individual @I9@, Child 4, child of Main Person and Spouse 2"

Setting inc_part = TRUE will include all partners and their descendants, and all descendants’ partners:

get_descendants(three_gen, main_xref, inc_part = TRUE) |>
  describe_records(gedcom = three_gen)
#> [1] "Individual @I4@, Spouse 1"                                  
#> [2] "Individual @I5@, Spouse 2"                                  
#> [3] "Individual @I6@, Child 1, child of Main Person and Spouse 1"
#> [4] "Individual @I7@, Child 2, child of Main Person and Spouse 1"
#> [5] "Individual @I8@, Child 3, child of Main Person and Spouse 2"
#> [6] "Individual @I9@, Child 4, child of Main Person and Spouse 2"

Setting inc_indi = TRUE will include the individual:

get_descendants(three_gen, main_xref, inc_indi = TRUE) |>
  describe_records(gedcom = three_gen)
#> [1] "Individual @I3@, Main Person, child of Parent 1 and Parent 2"
#> [2] "Individual @I6@, Child 1, child of Main Person and Spouse 1" 
#> [3] "Individual @I7@, Child 2, child of Main Person and Spouse 1" 
#> [4] "Individual @I8@, Child 3, child of Main Person and Spouse 2" 
#> [5] "Individual @I9@, Child 4, child of Main Person and Spouse 2"

Setting inc_famg = TRUE will include the individual’s families where they are a partner, and all descendants’ families:

get_descendants(three_gen, main_xref, inc_famg = TRUE) |>
  describe_records(gedcom = three_gen)
#> [1] "Family @F2@, headed by Main Person and Spouse 1, and children: Child 1, Child 2"
#> [2] "Family @F3@, headed by Main Person and Spouse 2, and children: Child 3, Child 4"
#> [3] "Individual @I6@, Child 1, child of Main Person and Spouse 1"                    
#> [4] "Individual @I7@, Child 2, child of Main Person and Spouse 1"                    
#> [5] "Individual @I8@, Child 3, child of Main Person and Spouse 2"                    
#> [6] "Individual @I9@, Child 4, child of Main Person and Spouse 2"

If we want to remove the individual and their partners, all descendants and their partners, and all families, we can remove them with remove_records():

get_descendants(three_gen, main_xref, inc_part = TRUE, inc_indi = TRUE, inc_famg = TRUE) |>
  remove_records(gedcom = three_gen) |> 
  df_famg() |> 
  knitr::kable()
#> Family @F2@, headed by Main Person and Spouse 1 removed
#> Family @F3@, headed by Main Person and Spouse 2 removed
#> Individual @I4@, Spouse 1 removed
#> Individual @I5@, Spouse 2 removed
#> Individual @I3@, Main Person removed
#> Individual @I6@, Child 1 removed
#> Individual @I7@, Child 2 removed
#> Individual @I8@, Child 3 removed
#> Individual @I9@, Child 4 removed
xref husband wife relationship_type relationship_date relationship_place num_children last_modified
@F1@ Parent 1 Parent 2 0 22 JUN 2022

This combination can result in the removal of a vast amount of data. It will tell the user precisely what it is removing. Be sure the function has done what you expect before accepting the results. It is recommended that you use this function with extreme caution if you think a descendant (or their spouse) may be connected to an individual on another branch of your tree.

This function will, by default, remove any dead references to records that have not been included in the subsetting.

Ancestors

We can deal with ancestors in a similar way using the get_ancestors() function.