rr_records: A snapshot of records from given entries

Description Usage Arguments Details Value Examples

View source: R/rr_records.R

Description

Filters for entries up to a given entry-number or timestamp, then returns the latest entry per key.

Use rr_snapshot() for a snapshot of a whole register (both schema and data).

Usage

1
2
rr_records(entries, sequence = c("entry-number", "timestamp"),
  maximum = NULL, include_maximum = TRUE)

Arguments

entries

A data frame or tibble with at least the fields key and either entry-number or timestamp, depending on the value of sequence.

sequence

One of "entry-number" (default) or "timestamp". The snapshot is taken at the maximum value of this field of entries.

maximum

An integer if sequence is "entry-number" orPOSIXctifsequenceis"timestamp", giving the time at which to take the snapshot. Only the latest entry up to this value will be kept, perkey'. By default it is the maximum of all entries, to return the most recent state of the register.

include_maximum

Logical, whether to include entries whose entry-number or timestamp equals maximum.

Details

A record is the latest entry for a given key. 'Latest' can be either the maximum entry-number (recommended), or the maximum timestamp. An entry timestamp may be NA, and may not be unique. If the timestamp of any entry of a given key is NA, then no record for that key will be returned. If the timestamp is not unique, then the entry with the maximum entry-number will be chosen.

Value

A tibble of records (latest entry per key).

Examples

 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
country <- rr_register("country")

# There can be more than one entry per key
country$data %>%
  dplyr::filter(key == "CZ") %>%
  dplyr::select(`entry-number`, timestamp, name, `official-name`)

# Snapshot by entry number
country$data %>%
  rr_records(maximum = 64) %>%
  dplyr::filter(key == "CZ") %>%
  dplyr::select(`entry-number`, timestamp, name, `official-name`)

country$data %>%
  rr_records(maximum = 217, include_maximum = FALSE) %>%
  dplyr::filter(key == "CZ") %>%
  dplyr::select(`entry-number`, timestamp, name, `official-name`)

# Snapshot by entry timestamp
country$data %>%
  rr_records(sequence = "timestamp",
             maximum = as.POSIXct("2016-04-05 13:23:05", tz = "UTC")) %>%
  dplyr::filter(key == "CZ") %>%
  dplyr::select(`entry-number`, timestamp, name, `official-name`)

# When the timestamp of any entry of a key is missing, no entries are
# returned.
entries <- country$data
entries$timestamp[entries$`entry-number` == 64] <- NA
rr_records(entries, sequence = "timestamp") %>%
  dplyr::filter(key == "CZ")

# Not all entries are data, some are schema
country$schema$custodians %>%
  rr_records(maximum = 11) %>%
  dplyr::select(`entry-number`, timestamp, custodian)

nacnudus/registr documentation built on May 5, 2019, 12:31 p.m.