-
Notifications
You must be signed in to change notification settings - Fork 0
/
interrogate.R
87 lines (68 loc) · 2.55 KB
/
interrogate.R
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
unique_record_count <- function(gedcom, tag) {sum(gedcom$level == 0 & gedcom$tag == tag)}
#' Get the number of records in a tidyged object
#'
#' These functions return the number of records of a particular type in a tidyged object.
#'
#' @param gedcom A tidyged object.
#'
#' @return The number of records of the relevant type.
#' @examples
#' num_indi(sample555)
#' num_famg(sample555)
#' num_repo(sample555)
#' @export
num_indi <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_indi) }
#' @export
#' @rdname num_indi
num_famg <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_famg) }
#' @export
#' @rdname num_indi
num_subm <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_subm) }
#' @export
#' @rdname num_indi
num_media <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_obje) }
#' @export
#' @rdname num_indi
num_note <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_note) }
#' @export
#' @rdname num_indi
num_repo <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_repo) }
#' @export
#' @rdname num_indi
num_sour <- function(gedcom) { unique_record_count(gedcom, .pkgenv$record_tag_sour) }
is_record_type <- function(gedcom, xref, tag) {
record_type <- gedcom$tag[gedcom$record == xref][1]
if(is.na(record_type)) stop("There is no record with xref ", xref)
record_type == tag
}
#' Check whether a given record is a particular type
#'
#' @param gedcom A tidyged object.
#' @param xref The xref of the record.
#'
#' @return A logical indicating whether the record is of a particular type.
#' @examples
#' is_indi(sample555, "@I1@")
#' is_note(sample555, "@I1@")
#' is_famg(sample555, "@F2@")
#' is_repo(sample555, "@R1@")
#' @export
is_indi <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_indi) }
#' @export
#' @rdname is_indi
is_famg <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_famg) }
#' @export
#' @rdname is_indi
is_subm <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_subm) }
#' @export
#' @rdname is_indi
is_repo <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_repo) }
#' @export
#' @rdname is_indi
is_media <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_obje) }
#' @export
#' @rdname is_indi
is_note <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_note) }
#' @export
#' @rdname is_indi
is_sour <- function(gedcom, xref) { is_record_type(gedcom, xref, .pkgenv$record_tag_sour) }