eurostat (version 3.7.10)

get_eurostat_json: Get Data from Eurostat API in JSON

Description

Retrieve data from Eurostat API in JSON format.

Usage

get_eurostat_json(
  id,
  filters = NULL,
  type = c("code", "label", "both"),
  lang = c("en", "fr", "de"),
  stringsAsFactors = FALSE,
  ...
)

Arguments

id

A code name for the dataset of interested. See the table of contents of eurostat datasets for more details.

filters

A named list of filters. Names of list objects are Eurostat variable codes and values are vectors of observation codes. If NULL (default) the whole dataset is returned. See details for more on filters and limitations per query.

type

A type of variables, "code" (default), "label" or "both". The "both" will return a data_frame with named vectors, labels as values and codes as names.

lang

A language used for metadata (en/fr/de).

stringsAsFactors

if TRUE (the default) variables are converted to factors in original Eurostat order. If FALSE they are returned as a character.

...

Arguments passed on to httr::GET

url

the url of the page to retrieve

config

Additional configuration settings such as http authentication (authenticate()), additional headers (add_headers()), cookies (set_cookies()) etc. See config() for full details and list of helpers.

handle

The handle to use with this request. If not supplied, will be retrieved and reused from the handle_pool() based on the scheme, hostname and port of the url. By default httr requests to the same scheme/host/port combo. This substantially reduces connection time, and ensures that cookies are maintained over multiple requests to the same host. See handle_pool() for more details.

Value

A dataset as a data_frame.

Details

Data to retrieve from The Eurostat Web Services can be specified with filters. Normally, it is better to use JSON query through get_eurostat(), than to use get_eurostat_json() directly.

Queries are limited to 50 sub-indicators at a time. A time can be filtered with fixed "time" filter or with "sinceTimePeriod" and "lastTimePeriod" filters. A sinceTimePeriod = 2000 returns observations from 2000 to a last available. A lastTimePeriod = 10 returns a 10 last observations.

To use a proxy to connect, a httr::use_proxy() can be passed to httr::GET(). For example get_eurostat_json(id, filters, config = httr::use_proxy(url, port, username, password)).

References

See citation("eurostat"):

# 
# Kindly cite the eurostat R package as follows:
# 
#   (C) Leo Lahti, Janne Huovari, Markus Kainu, Przemyslaw Biecek.
#   Retrieval and analysis of Eurostat open data with the eurostat
#   package. R Journal 9(1):385-392, 2017. doi: 10.32614/RJ-2017-019
#   Package URL: http://ropengov.github.io/eurostat Article URL:
#   https://journal.r-project.org/archive/2017/RJ-2017-019/index.html
# 
# A BibTeX entry for LaTeX users is
# 
#   @Article{,
#     title = {Retrieval and Analysis of Eurostat Open Data with the eurostat Package},
#     author = {Leo Lahti and Janne Huovari and Markus Kainu and Przemyslaw Biecek},
#     journal = {The R Journal},
#     volume = {9},
#     number = {1},
#     pages = {385--392},
#     year = {2017},
#     doi = {10.32614/RJ-2017-019},
#     url = {https://doi.org/10.32614/RJ-2017-019},
#   }

See Also

httr::GET()

Examples

Run this code
# NOT RUN {
# nama_gdp_c has been discontinued since 2/2018 and this example has ceased working.
# }
# NOT RUN {
tmp <- get_eurostat_json("cdh_e_fos")
yy <- get_eurostat_json(id = "nama_gdp_c", filters = list(
  geo = c("EU28", "FI"),
  unit = "EUR_HAB",
  indic_na = "B1GM"
))
# }

Run the code above in your browser using DataLab