rr_records.Rd
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).
rr_records(entries, sequence = c("entry-number", "timestamp"), maximum = NULL, include_maximum = TRUE)
entries | A data frame or tibble with at least the fields |
---|---|
sequence | One of |
maximum | An |
include_maximum | Logical, whether to include entries whose
|
A tibble of records (latest entry per key).
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.
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`)#> # A tibble: 2 x 4 #> `entry-number` timestamp name `official-name` #> <int> <dttm> <chr> <chr> #> 1 64 2016-04-05 13:23:05 Czech Republic The Czech Republic #> 2 217 2016-11-11 16:25:07 Czechia The Czech Republic# Snapshot by entry number country$data %>% rr_records(maximum = 64) %>% dplyr::filter(key == "CZ") %>% dplyr::select(`entry-number`, timestamp, name, `official-name`)#> # A tibble: 1 x 4 #> `entry-number` timestamp name `official-name` #> <int> <dttm> <chr> <chr> #> 1 64 2016-04-05 13:23:05 Czech Republic The Czech Republiccountry$data %>% rr_records(maximum = 217, include_maximum = FALSE) %>% dplyr::filter(key == "CZ") %>% dplyr::select(`entry-number`, timestamp, name, `official-name`)#> # A tibble: 1 x 4 #> `entry-number` timestamp name `official-name` #> <int> <dttm> <chr> <chr> #> 1 64 2016-04-05 13:23:05 Czech Republic The Czech Republic# 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`)#> # A tibble: 1 x 4 #> `entry-number` timestamp name `official-name` #> <int> <dttm> <chr> <chr> #> 1 64 2016-04-05 13:23:05 Czech Republic The Czech Republic# 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")#> # A tibble: 0 x 11 #> # ... with 11 variables: `entry-number` <int>, type <chr>, key <chr>, #> # timestamp <dttm>, hash <chr>, country <chr>, name <chr>, #> # `official-name` <chr>, `citizen-names` <chr>, `start-date` <chr>, #> # `end-date` <chr># Not all entries are data, some are schema country$schema$custodians %>% rr_records(maximum = 11) %>% dplyr::select(`entry-number`, timestamp, custodian)#> # A tibble: 1 x 3 #> `entry-number` timestamp custodian #> <int> <dttm> <chr> #> 1 2 2017-07-17 10:59:47 Tony Worron