fedstat_data_load_with_filters: Download subset of indicator data from fedstat.ru by...

View source: R/fedstat_data_load_with_filters.R

fedstat_data_load_with_filtersR Documentation

Download subset of indicator data from fedstat.ru by specifying filters in JSON

Description

This function is a wrapper for the other functions of the package to provide a simple one function API for fedstat.ru

There are two basic terms in this API: filter_field and filter_value

The ⁠filter field⁠ reflects the individual property of the data point. For example, Year, Region, Unit of measurement, etc. Each filter field has its own title (filter_field_title), it is simply a human-readable word or phrase (e.g. "Year", "Region") that reflects the essence of the property by which filtering takes place

The ⁠filter value⁠ reflects the individual property specific value of the data point. (e.g. 2021 for the Year, "Russian Federation" for the region, etc.) It also has a title (filter_value_title) with the same purpose as filter_field_title

filters should use filter_field_title in names and filter_value_title in values as they are presented on fedstat.ru. If for some reason the specified filters do not return the expected result, it is worth using fedstat_get_data_ids separately and inspecting possible filter values in data_ids to see if the strings are defined correctly (e.g. encoding issues, mixing latin and cyrillic symbols)

filter_value_title currently supports the following special values:

  1. asterix (*), alias for "select all possible filter values for this filter field"

Unspecified filters use asterix as a default (i.e. all possible filter values are selected and a warning is given)

Internally normalized filter_field_title and filter_value_title are used (all lowercase, removed extra whitespaces) to compare the equality of data_ids and filters

Usage

fedstat_data_load_with_filters(
  indicator_id,
  ...,
  filters = list(),
  timeout_seconds = 180,
  retry_max_times = 3,
  disable_warnings = FALSE,
  httr_verbose = NULL,
  loading_steps_verbose = TRUE,
  return_type = c("data", "dictionary"),
  try_to_parse_ObsValue = TRUE
)

Arguments

indicator_id

character, indicator id/code from indicator URL. For example for indicator with URL https://www.fedstat.ru/indicator/37426 indicator id will be 37426

...

other arguments passed to httr::GET and httr::POST

filters

JSON in R list form. The structure should be like this:

{
 "filter_field_title1": ["filter_value_title1", "filter_value_title2"],
 "filter_field_title2": ["filter_value_title1", "filter_value_title2"],
 ...
}

Where for example filter_field_title1 could be a string "Year" with filter_value_title1 equal to 2020 and filter_field_title2 could be a string "OKATO" with filter_value_title1 equal to "Russian Federation" Not actual filter field titles and filter values titles because of ASCII requirement for CRAN

timeout_seconds

numeric, maximum time before a new GET and POST request is tried

retry_max_times

numeric, maximum number of tries to GET and POST data_ids

disable_warnings

bool, enables or disables following warnings:

  1. About non matched filter_value_title in filters and filter_value_title from data_ids;

  2. About unspecified filter_filed_title in filters.

httr_verbose

httr::verbose() or NULL, outputs messages to the console about the processing of the request

loading_steps_verbose

logical, print data loading steps to console

return_type

character, "data" or "dicionary", data for actual data, dictionary for sdmx lookup table (full data codes dictionary)

try_to_parse_ObsValue

logical, try to parse ObsValue column from character to R numeric type

Value

data.frame with filtered indicator data from fedstat.ru

See Also

fedstat_get_data_ids, fedstat_data_ids_filter, fedstat_post_data_ids_filtered, fedstat_parse_sdmx_to_table

Examples

## Not run: 
# Download CPI data
# for all goods and services for Russian Federation
data <- fedstat_data_load_with_filters(
  indicator_id = "31074",
  filters = list(
    "Territory" = "Russian Federation",
    "Year" = "2023",
    "Period" = "January",
    "Types of goods and services" = "*"
  )
)
# Not actual filter field titles and filter values titles because of ASCII requirement for CRAN

## End(Not run)

fedstatAPIr documentation built on March 31, 2023, 9:16 p.m.