Downloads the referendum data from the Referendum Database (RDB). See the codebook for a detailed description of all variables.
Usage
rfrnds(
country_code = NULL,
subnational_entity_name = NULL,
municipality = NULL,
level = NULL,
type = NULL,
date_min = NULL,
date_max = NULL,
is_draft = FALSE,
date_time_created_min = NULL,
date_time_created_max = NULL,
date_time_last_edited_min = NULL,
date_time_last_edited_max = NULL,
query_filter = NULL,
incl_archive = FALSE,
tidy = TRUE,
use_cache = TRUE,
max_cache_age = "1 week",
use_testing_server = funky::config_val("use_testing_server"),
quiet = FALSE
)Arguments
- country_code
The
country_code(s) to be included. A character vector.- subnational_entity_name
The
subnational_entity_name(s) to be included. A character vector.- municipality
The
municipality(s) to be included. A character vector.- level
The
level(s) to be included. A character vector.- type
The
type(s) to be included. A character vector.- date_min
The minimum
dateto be included. A date or something coercible to.- date_max
The maximum
dateto be included. A date or something coercible to.- is_draft
TRUEmeans to include only referendum entries with draft status,FALSEto include only normal entries. Set toNULLin order to include both draft and normal entries.- date_time_created_min
The minimum
date_time_createdto be included. A datetime, or something coercible to (like"2006-01-02"or"2006-01-02T15:04:05Z"; assumed to be in UTC if no timezone is given).- date_time_created_max
The maximum
date_time_createdto be included. A datetime, or something coercible to (like"2006-01-02"or"2006-01-02T15:04:05Z"; assumed to be in UTC if no timezone is given).- date_time_last_edited_min
The minimum
date_time_last_editedto be included. A datetime, or something coercible to (like"2006-01-02"or"2006-01-02T15:04:05Z"; assumed to be in UTC if no timezone is given).- date_time_last_edited_max
The maximum
date_time_last_editedto be included. A datetime, or something coercible to (like"2006-01-02"or"2006-01-02T15:04:05Z"; assumed to be in UTC if no timezone is given).- query_filter
A valid MongoDB JSON query filter document which allows for maximum control over what data is included. This takes precedence over all of the above listed parameters, i.e. if
query_filteris provided, the parameterscountry_code,subnational_entity_name,municipality,level,type,date_min,date_max,is_draft,date_time_created_min,date_time_created_max,date_time_last_edited_minanddate_time_last_edited_maxare ignored.- incl_archive
Whether or not to include an
archivecolumn containing data from an earlier, obsolete state of the Referendum Database (RDB).- tidy
Whether or not to tidy the referendum data, i.e. apply various data cleansing tasks and add additional variables. If
FALSE, the raw MongoDB referendum data will only be modified just enough to be able to return it as a tibble. Note that untidy data doesn't conform to the codebook (i.a. different variable names).- use_cache
Whether or not to return cached results if possible. If
FALSE, results are always newly fetched regardless ofmax_cache_age.- max_cache_age
Duration after which cached results are refreshed (i.e. newly fetched). A valid lubridate duration. Use
Infto disable cache expiry. Only relevant ifuse_cache = TRUE.- use_testing_server
Whether or not to use the testing servers instead of the production servers for RDB Services API calls etc.
- quiet
Whether or not to suppress printing status output from internal processing.
Value
A tibble.
See also
Other referendum data functions:
add_rfrnds(),
assert_vars(),
count_rfrnds(),
delete_rfrnds(),
download_file_attachment(),
edit_rfrnds(),
rfrnd(),
rfrnd_exists(),
rfrnds_bkp(),
validate_rfrnds()
Examples
# get all referendums (excl. drafts)
rdb::rfrnds()
#> # A tibble: 17,892 × 67
#> id id_official id_sudd country_code country_name subnational_entity_n…¹ municipality level date is_former_country title_en title_de title_fr
#> <chr> <chr> <chr> <fct> <fct> <chr> <chr> <ord> <date> <lgl> <chr> <chr> <chr>
#> 1 670cd145c3cd… NA NA CH Switzerland Zug NA subn… 2024-06-09 NA Cycling… Velonet… NA
#> 2 66fff490c3cd… NA NA LI Liechtenste… NA NA nati… 2024-09-22 NA Referen… Referen… NA
#> 3 66ffdfe3c3cd… NA NA CH Switzerland Jura NA subn… 2024-09-22 NA Act con… NA Acte re…
#> 4 66ffdc31c3cd… NA NA CH Switzerland Uri NA subn… 2024-09-22 NA Energy … Energie… NA
#> 5 66ffd956c3cd… NA NA CH Switzerland Uri NA subn… 2024-09-22 NA Partial… Teilrev… NA
#> 6 66ffbf93c3cd… NA NA CH Switzerland Nidwalden NA subn… 2024-09-22 NA Amendme… Änderun… NA
#> 7 66f686cfc3cd… NA NA CH Switzerland Bern NA subn… 2024-09-22 NA Concord… Konkord… NA
#> 8 66f68317c3cd… NA NA CH Switzerland Bern NA subn… 2024-09-22 NA Amendme… Änderun… NA
#> 9 66d6da9cc3cd… NA NA CH Switzerland Basel Landschaft NA subn… 2024-09-22 NA Partial… Teilrev… NA
#> 10 66cde603c3cd… NA NA CH Switzerland Graubünden NA subn… 2024-09-22 NA New civ… Neubau … NA
#> # ℹ 17,882 more rows
#> # ℹ abbreviated name: ¹subnational_entity_name
#> # ℹ 54 more variables: question <chr>, question_en <chr>, committee_name <chr>, result <fct>, subterritories_yes <dbl>, subterritories_no <dbl>,
#> # electorate_total <int>, electorate_abroad <int>, votes_yes <int>, votes_no <int>, votes_empty <int>, votes_invalid <int>, votes_per_subterritory <list>,
#> # lower_house_yes <int>, lower_house_no <int>, lower_house_abstentions <int>, upper_house_yes <int>, upper_house_no <int>, upper_house_abstentions <int>,
#> # position_government <fct>, topics_tier_1 <list>, topics_tier_2 <list>, topics_tier_3 <list>, remarks <chr>, files <list>, sources <chr>, is_draft <lgl>,
#> # date_time_created <dttm>, date_time_last_edited <dttm>, type <fct>, inst_legal_basis_type <ord>, inst_has_urgent_legal_basis <lgl>, …
# get only referendums in Austria and Australia on subnational level
rdb::rfrnds(country_code = c("AT", "AU"),
level = "subnational",
quiet = TRUE)
#> # A tibble: 31 × 67
#> id id_official id_sudd country_code country_name subnational_entity_n…¹ municipality level date is_former_country title_en title_de title_fr
#> <chr> <chr> <chr> <fct> <fct> <chr> <chr> <ord> <date> <lgl> <chr> <chr> <chr>
#> 1 5bbbfb4f92a2… 12707 NA AU Australia Northern Territory NA subn… 2001-10-24 NA Immedia… NA NA
#> 2 5bbbf9b192a2… 1219 NA AU Australia Christmas Island NA subn… 1999-11-06 NA Enhance… NA NA
#> 3 5bbbf92f92a2… 12706 NA AU Australia Northern Territory NA subn… 1999-05-12 NA NA NA Constit…
#> 4 5bbbf82092a2… 1710 NA AU Australia Northern Territory NA subn… 1998-08-26 NA Title n… NA NA
#> 5 5bbbf7ff92a2… 12705 NA AU Australia Northern Territory NA subn… 1998-05-14 NA Nominat… NA NA
#> 6 5bbbf70392a2… 12704 NA AU Australia Northern Territory NA subn… 1996-10-17 NA Plans f… NA NA
#> 7 5bbbf59192a2… 12703 NA AU Australia Northern Territory NA subn… 1995-03-15 NA Quarant… NA NA
#> 8 5bbbf4d492a2… 872 NA AU Australia Christmas Island NA subn… 1994-05-07 NA Nationa… NA NA
#> 9 5bbbf4d492a2… 871 NA AU Australia Christmas Island NA subn… 1994-05-07 NA Nationa… NA NA
#> 10 5bbbf29e92a2… 12694 NA AU Australia Northern Territory NA subn… 1991-01-02 NA NA NA Constit…
#> # ℹ 21 more rows
#> # ℹ abbreviated name: ¹subnational_entity_name
#> # ℹ 54 more variables: question <chr>, question_en <chr>, committee_name <chr>, result <fct>, subterritories_yes <dbl>, subterritories_no <dbl>,
#> # electorate_total <int>, electorate_abroad <int>, votes_yes <int>, votes_no <int>, votes_empty <int>, votes_invalid <int>, votes_per_subterritory <list>,
#> # lower_house_yes <int>, lower_house_no <int>, lower_house_abstentions <int>, upper_house_yes <int>, upper_house_no <int>, upper_house_abstentions <int>,
#> # position_government <fct>, topics_tier_1 <list>, topics_tier_2 <list>, topics_tier_3 <list>, remarks <chr>, files <list>, sources <chr>, is_draft <lgl>,
#> # date_time_created <dttm>, date_time_last_edited <dttm>, type <fct>, inst_legal_basis_type <ord>, inst_has_urgent_legal_basis <lgl>, …
# get referendums in 2020
rdb::rfrnds(date_min = "2020-01-01",
date_max = "2020-12-31",
quiet = TRUE)
#> # A tibble: 103 × 67
#> id id_official id_sudd country_code country_name subnational_entity_n…¹ municipality level date is_former_country title_en title_de title_fr
#> <chr> <chr> <chr> <fct> <fct> <chr> <chr> <ord> <date> <lgl> <chr> <chr> <chr>
#> 1 6010898bd129… NA NA VE Venezuela NA NA nati… 2020-12-12 NA Rejecti… Ablehnu… NA
#> 2 60108788d129… NA NA VE Venezuela NA NA nati… 2020-12-12 NA Initiat… Einleit… NA
#> 3 60108540d129… NA NA VE Venezuela NA NA nati… 2020-12-12 NA Free el… Freie W… NA
#> 4 601022ddd129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Electio… Wahlbes… NA
#> 5 6010202dd129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Electio… Wahlter… NA
#> 6 60101d90d129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Reducti… Kürzung… NA
#> 7 60101b85d129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Reducti… Kürzung… NA
#> 8 6010195ad129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Reducti… Kürzung… NA
#> 9 60101462d129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Reducti… Kürzung… NA
#> 10 60101127d129… NA NA LR Liberia NA NA nati… 2020-12-08 NA Reducti… Kürzung… NA
#> # ℹ 93 more rows
#> # ℹ abbreviated name: ¹subnational_entity_name
#> # ℹ 54 more variables: question <chr>, question_en <chr>, committee_name <chr>, result <fct>, subterritories_yes <dbl>, subterritories_no <dbl>,
#> # electorate_total <int>, electorate_abroad <int>, votes_yes <int>, votes_no <int>, votes_empty <int>, votes_invalid <int>, votes_per_subterritory <list>,
#> # lower_house_yes <int>, lower_house_no <int>, lower_house_abstentions <int>, upper_house_yes <int>, upper_house_no <int>, upper_house_abstentions <int>,
#> # position_government <fct>, topics_tier_1 <list>, topics_tier_2 <list>, topics_tier_3 <list>, remarks <chr>, files <list>, sources <chr>, is_draft <lgl>,
#> # date_time_created <dttm>, date_time_last_edited <dttm>, type <fct>, inst_legal_basis_type <ord>, inst_has_urgent_legal_basis <lgl>, …
# get referendums added to the database during the last 30 days
rdb::rfrnds(date_time_created_min = clock::date_today(zone = "UTC") |> clock::add_days(-30L),
date_time_created_max = clock::date_today(zone = "UTC"),
quiet = TRUE)
#> data frame with 0 columns and 0 rows
# provide custom `query_filter` for more complex queries like regex matches
# cf. https://docs.mongodb.com/manual/reference/operator/query/regex/
rdb::rfrnds(query_filter = '{"country_code":{"$regex":"A."}}',
quiet = TRUE)
#> # A tibble: 244 × 67
#> id id_official id_sudd country_code country_name subnational_entity_n…¹ municipality level date is_former_country title_en title_de title_fr
#> <chr> <chr> <chr> <fct> <fct> <chr> <chr> <ord> <date> <lgl> <chr> <chr> <chr>
#> 1 650034e4481d… NA au0120… AU Australia NA NA nati… 2023-10-14 NA Establi… Stimme … NA
#> 2 63bd3905a52c… NA as1120… AS American Sa… NA NA nati… 2022-11-08 NA Renamin… Umbenen… NA
#> 3 63bd2a63a52c… NA as1020… AS American Sa… NA NA nati… 2022-11-08 NA Renamin… Umbenen… NA
#> 4 63bd293ba52c… NA as0920… AS American Sa… NA NA nati… 2022-11-08 NA Renamin… Umbenen… NA
#> 5 63bd268ba52c… NA as0820… AS American Sa… NA NA nati… 2022-11-08 NA Removal… Absetzu… NA
#> 6 63bd25dea52c… NA as0720… AS American Sa… NA NA nati… 2022-11-08 NA Enlarge… Vergrös… NA
#> 7 63bd256ba52c… NA as0620… AS American Sa… NA NA nati… 2022-11-08 NA Voting … Stimmre… NA
#> 8 63bd24d7a52c… NA as0520… AS American Sa… NA NA nati… 2022-11-08 NA Annexat… Anschlu… NA
#> 9 63bd222ba52c… NA as0420… AS American Sa… NA NA nati… 2022-11-08 NA Enlarge… Vergrös… NA
#> 10 63bd2187a52c… NA as0320… AS American Sa… NA NA nati… 2022-11-08 NA No obje… Keine E… NA
#> # ℹ 234 more rows
#> # ℹ abbreviated name: ¹subnational_entity_name
#> # ℹ 54 more variables: question <chr>, question_en <chr>, committee_name <chr>, result <fct>, subterritories_yes <dbl>, subterritories_no <dbl>,
#> # electorate_total <int>, electorate_abroad <int>, votes_yes <int>, votes_no <int>, votes_empty <int>, votes_invalid <int>, votes_per_subterritory <list>,
#> # lower_house_yes <int>, lower_house_no <int>, lower_house_abstentions <int>, upper_house_yes <int>, upper_house_no <int>, upper_house_abstentions <int>,
#> # position_government <fct>, topics_tier_1 <list>, topics_tier_2 <list>, topics_tier_3 <list>, remarks <chr>, files <list>, sources <chr>, is_draft <lgl>,
#> # date_time_created <dttm>, date_time_last_edited <dttm>, type <fct>, inst_legal_basis_type <ord>, inst_has_urgent_legal_basis <lgl>, …