fedstat_post_data_ids_filtered: Post data filters ids to fedstat.ru and download specified...

View source: R/fedstat_post_data_ids_filtered.R

fedstat_post_data_ids_filteredR Documentation

Post data filters ids to fedstat.ru and download specified subset of data

Description

For advanced use. Most downloads should use fedstat_download(), which splits large selections, pauses between requests and saves progress.

Creates a request body from data_ids and sends it to https://www.fedstat.ru/indicator/downloadData.do?format={format}. Gets an sdmx or excel with data in binary format.

The request includes a CSRF token that is automatically extracted by fedstat_get_data_ids and passed through via data.frame attributes. Token reuse may succeed, but Fedstat can reject a token at any time. This primitive sends one POST; the convenience wrapper and batch downloader own retry and token-refresh decisions.

If no CSRF token is found in data_ids attributes (e.g. when using cached data_ids from a previous session), the function will attempt to fetch a fresh token automatically, using the same HTTP configuration.

sdmx raw bytes can be passed to fedstat_parse_sdmx_to_table to create a data.frame or to rawToChar and writeLines to create an xml file

excel raw bytes can be passed to writeBin to create an xls file

Request size is limited to protect Fedstat. Size is the number of filter combinations: the product of the number of selected values of every filter. Above 50,000 combinations this function warns, above 100,000 it stops unless allow_large_requests = TRUE, and above 250,000 it always stops. fedstat_download() splits larger selections into parts.

Usage

fedstat_post_data_ids_filtered(
  data_ids,
  ...,
  data_format = c("sdmx", "excel"),
  timeout_seconds = 180,
  retry_max_times = 3,
  httr_verbose = NULL,
  allow_large_requests = FALSE
)

Arguments

data_ids

data.frame, a result of fedstat_data_ids_filter to download a subset of the available data (all data of an indicator usually exceed the size limit)

...

other arguments passed to httr::POST

data_format

string, one of sdmx, excel

timeout_seconds

numeric, maximum time before POST request times out

retry_max_times

numeric, not used for POST (exports are not retried here), but used for fallback GET if CSRF token needs to be fetched

httr_verbose

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

allow_large_requests

logical. TRUE turns off the warning above 50,000 filter combinations and allows up to 250,000. Larger requests are always refused.

Value

raw bytes (sdmx or excel)

See Also

fedstat_parse_sdmx_to_table

Examples

## Not run: 
# Get data filters identificators for CPI
# filter the data_ids to get data for january of 2023
# for all goods and services for Russian Federation
# POST filters and download data in sdmx format
data <- fedstat_get_data_ids("31074") %>%
    fedstat_data_ids_filter(
        filters = list(
            "Territory" = "Russian Federation",
            "Year" = "2023",
            "Period" = "January",
            "Types of goods and services" = "*"
        )
    ) %>%
    fedstat_post_data_ids_filtered()

# Not actual filter field titles and filter values titles because of ASCII requirement for CRAN

## End(Not run)

fedstatAPIr documentation built on Nov. 4, 2026, 9:07 a.m.