get_eurostat_data: Download/extract Eurostat Data

Description Usage Arguments Details Value See Also Examples

View source: R/get_eurostat_data.R

Description

Download full or partial data set from Eurostat database.

Usage

1
2
3
4
5
get_eurostat_data(id, filters = NULL, exact_match = TRUE,
  date_filter = NULL, label = FALSE, select_freq = NULL,
  cache = TRUE, update_cache = FALSE, cache_dir = NULL,
  compress_file = TRUE, stringsAsFactors = default.stringsAsFactors(),
  keep_flags = FALSE, verbose = FALSE, ...)

Arguments

id

A code name for the dataset of interest. See search_eurostat_toc for details how to get an id.

filters

a string or a character vector containing words to filter by the different concepts or geographical location. If filter applied only part of the dataset is downloaded through the API. The words can be any words, Eurostat variable codes, and values available in the DSD search_eurostat_dsd. The default is NULL, in this case the whole dataset is returned via the bulk download. To filter by time see date_filter below. If after filtering still the dataset has more observations than the limit per query via the API, then the bulk download is used to retrieve the data.

exact_match

a boolean with the default value TRUE, if the strings provided in filters shall be matched exactly as it is or as a pattern.

date_filter

a vector which can be numeric or character containing dates to filter the dataset. If date filter applied only part of the dataset is downloaded through the API. The default is NULL, in this case the whole dataset is returned via the bulk download. If after filtering still the dataset has more observations than the limit per query via the API, then the bulk download is used to retrieve the data.

label

a boolean with the default FALSE. If it is TRUE then the code values are replaced by the name from the Data Structure Definition (DSD) get_eurostat_dsd. For example instead of "D1110A", "Raw cows' milk from farmtype" is used or "HU32" is replaced by "Észak-Alföld".

select_freq

a character symbol for a time frequency when a dataset has multiple time frequencies. Possible values are: A = annual, S = semi-annual, H = half-year, Q = quarterly, M = monthly, W = weekly, D = daily. The default is NULL as most datasets have just one time frequency and in this case if there are multiple frequencies, then only the most common frequency kept. If all the frequencies needed the get_eurostat_raw can be used.

cache

a logical whether to do caching. Default is TRUE. Affects only queries without filtering. If filters or date_filter is used then there is no caching.

update_cache

a logical with a default value FALSE, whether to update the data in the cache. Can be set also with options(restatapi_update=TRUE)

cache_dir

a path to a cache directory. The NULL (default) uses the memory as cache. If the folder cache_dir directory does not exist it saves in the 'restatapi' directory under the temporary directory from tempdir(). Directory can also be set with option(restatapi_cache_dir=...).

compress_file

a logical whether to compress the RDS-file in caching. Default is TRUE.

stringsAsFactors

if TRUE (the default) the non-numeric columns are converted to factors. If the value FALSE they are returned as a characters.

keep_flags

a logical whether the observation status (flags) - e.g. "confidential", "provisional", etc. - should be kept in a separate column or if they can be removed. Default is FALSE. For flag values see: http://ec.europa.eu/eurostat/data/database/information.

verbose

A boolean with default FALSE, so detailed messages (for debugging) will not printed. Can be set also with options(restatapi_verbose=TRUE)

...

further arguments to the for search_eurostat_dsd function, e.g.: ignore.case or name. If the ignore.case has the default value FALSE, then the strings provided in filters are matched as is, otherwise the case of the letters is ignored. If the name=FALSE then the pattern(s) provided in the filters argument is only searched in the code column of the DSD, and the names of the codes will not be searched.

Details

Data sets are downloaded from the Eurostat Web Services SDMX API if there is a filter otherwise the the Eurostat bulk download facility is used. If only the table id is given, the whole table is downloaded from the bulk download facility. If also filters or date_filter is defined then the SDMX API is used. In case after filtering the dataset has more rows than the limitation of the SDMX API (1 million values at one time) then the bulk download is used to retrieve the whole dataset .

By default all datasets cached as they are often rather large. The datasets cached in memory (default) or can be stored in a temporary directory if cache_dir or option(restatpi_cache_dir) is defined. The cache can be emptied with clean_restatapi_cache.

The id, is a value from the code column of the table of contents (get_eurostat_toc), and can be searched for with the search_eurostat_toc function. The id value can be retrieved from the Eurostat database as well. The Eurostat database gives codes in the Data Navigation Tree after every dataset in parenthesis.

Filtering can be done by the codes as described in the API documentation providing in the correct order and connecting with "." and "+". If we do not know the codes we can filter based on words or by the mix of the two putting in a vector like c("AT$","Belgium","persons","Total"). Be careful that the filter is case sensitive, if you do not know the code or label exactly you can use the option ignore.case=TRUE and exact_match=FALSE, but in this case the results may include unwanted elements as well. In the filters parameter regular expressions can be used as well. We do not have to worry about the correct order of the filter, it will be put in the correct place based on the DSD.

The date_filter shall be a string in the format yyyy[-mm][-dd]. The month and the day part is optional, but if we use the years and we have monthly frequency then all the data for the given year is retrieved. The string can be extended by adding the "<" or ">" to the beginning or to the end of the string. In this case the date filter is treated as range, and the date is used as a starting or end date. The data will include the observation of the start/end date. A single date range can be defined as well by concatenating two dates with the ":", e.g. "2016-08:2017-03-15". As seen in the exemple the dates can have different length: one defined only at year/month level, the other by day level. If a date range is defined with ":", it is not possible to use the "<" or ">" characters in the date filter. If there are multiple dates which is not a continuous range, it can be put in vector in any order like c("2016-08",2013:2015,"2017-07-01"). In this case, as well, it is not possible to use the "<" or ">" characters.

Value

a data.table. One column for each dimension in the data, the time column for a time dimension, the values column for numerical values and the flags column if the keep_flags=TRUE. Eurostat data does not include all missing values. The missing values are dropped if all dimensions are missing on particular time.

See Also

search_eurostat_toc,search_eurostat_dsd

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
load_cfg()
eu<-get("cc",envir=.restatapi_env)



dt<-get_eurostat_data("NAMA_10_GDP")
dt<-get_eurostat_data("nama_10_gdp",update_cache=TRUE)
dt<-get_eurostat_data("nama_10_gdp",cache_dir="/tmp")
options(restatapi_update=FALSE)
options(restatapi_cache_dir=file.path(tempdir(),"restatapi"))
dt<-get_eurostat_data("avia_gonc",select_freq="A",cache=FALSE)
dt<-get_eurostat_data("agr_r_milkpr",date_filter=2008,keep_flags=TRUE)
dt<-get_eurostat_data("avia_par_me",
                      filters="BE$",
                      exact_match=FALSE,
                      date_filter=c(2016,"2017-03","2017-07-01"),
                      select_freq="Q",
                      label=TRUE,
                      name=FALSE)
dt<-get_eurostat_data("agr_r_milkpr",
                      filters=c("BE$","Hungary"),
                      date_filter="2007-06<",
                      keep_flags=TRUE)
dt<-get_eurostat_data("nama_10_a10_e",
                      filters=c("Annual","EU28","Belgium","AT","Total","EMP_DC","person"),
                      date_filter=c("2008",2002,2013:2018))
dt<-get_eurostat_data("vit_t3",
                      filters=c("EU28",eu$EA15,"HU$"),
                      date_filter=c("2015",2007))
dt<-get_eurostat_data("avia_par_me",
                      filters="Q...ME_LYPG_HU_LHBP+ME_LYTV_UA_UKKK",
                      date_filter=c("2016-08","2017-07-01"),
                      select_freq="M")

restatapi documentation built on July 24, 2019, 1:05 a.m.