Find an xref of a record given a set of search terms

find_xref(
  gedcom,
  search_patterns,
  mode = "strict",
  multiple = FALSE,
  ignore_case = FALSE
)

Arguments

gedcom

A tidyged object.

search_patterns

A named vector of terms to search for (see Details).

mode

Whether to only return an xref if all patterns are matched ("strict"). A value of "best" will return the xref with the most matches. If either of these still result in more than one xref it will return an error unless multiple is TRUE.

multiple

If more than one xref is found (according to mode), whether to return all xrefs or throw an error.

ignore_case

Should case differences be ignored in the match?

Value

A vector of one or more xrefs.

Details

This is a helper function to identify the xref of a record given information such as a name or reference number. You provide a named search_patterns vector of namespaced tag-pattern pairs, such as:

c(INDI.NAME = "Homer", INDI.SEX = "M", INDI.BIRT.DATE = "JAN 1974")

If you're not sure what namespace to use, use the mutate_tag_namespace function.

The search patterns will be treated as regular expressions, so they will match a value if it contains the pattern provided. You can anchor your search pattern if you want an exact match, e.g. "^JAN 1974$". If you're not familiar with regular expressions, you may need to escape certain characters such as brackets and a full-stop/period (i.e. \\.).

Examples

find_xref(sample555, c(INDI.BURI.PLAC = "Spring Hill"), multiple = FALSE)
#> [1] "@I1@"
find_xref(sample555, c(INDI.SEX = "M"), multiple = TRUE)
#> [1] "@I1@" "@I3@"
find_xref(sample555, c(FAM.MARR.DATE = "1859"), multiple = FALSE)
#> [1] "@F1@"
find_xref(sample555, c(REPO.ADDR.CITY = "Salt Lake"), multiple = TRUE)
#> [1] "@R1@"
find_xref(sample555, c(INDI.NAME.SURN = "Williams", INDI.ADOP.DATE = "Never"), 
mode = "best", multiple = TRUE)
#> [1] "@I1@" "@I3@"