Skip to contents

Counts the number of referendums per level in the Referendum Database (RDB).

Usage

count_rfrnds(
  is_draft = FALSE,
  country_code = NULL,
  subnational_entity_name = NULL,
  municipality = NULL,
  level = NULL,
  type = NULL,
  date_min = NULL,
  date_max = NULL,
  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,
  use_testing_server = pal::pkg_config_val(key = "use_testing_server", pkg = this_pkg)
)

Arguments

is_draft

TRUE means to include only referendum entries with draft status, FALSE to include only normal entries. Set to NULL in order to include both draft and normal entries.

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 date to be included. A date or something coercible to.

date_max

The maximum date to be included. A date or something coercible to.

date_time_created_min

The minimum date_time_created to 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_created to 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_edited to 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_edited to 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_filter is provided, the parameters country_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_min and date_time_last_edited_max are ignored.

use_testing_server

Whether or not to use the testing servers instead of the production servers for RDB Services API calls etc.

Value

A named list with level as names and referendum counts as values.

Examples

# the whole database (excl. drafts)
rdb::count_rfrnds()
#> $national
#> [1] 3098
#> 
#> $subnational
#> [1] 14632
#> 
#> $local
#> [1] 43
#> 

# only Swiss and Austrian referendums
rdb::count_rfrnds(country_code = c("CH", "AT"))
#> $national
#> [1] 688
#> 
#> $subnational
#> [1] 6848
#> 
#> $local
#> [1] 1
#> 

# only Swiss referendums created between 2020 and 2021
rdb::count_rfrnds(country_code = "CH",
                  date_time_created_min = "2020-01-01",
                  date_time_created_max = "2021-01-01")
#> $national
#> [1] 9
#> 
#> $subnational
#> [1] 105
#> 
#> $local
#> [1] 0
#>