Download data sets from Eurostat database .

get_eurostat_raw(
  id,
  mode = "txt",
  cache = TRUE,
  update_cache = FALSE,
  cache_dir = NULL,
  compress_file = TRUE,
  stringsAsFactors = FALSE,
  keep_flags = FALSE,
  check_toc = FALSE,
  melt = TRUE,
  verbose = FALSE,
  ...
)

Arguments

id

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

mode

defines the format of the downloaded dataset. It can be txt (the default value) for Tab Separated Values (TSV), or csv for SDMX-CSV, or xml for the SDMX-ML version.

cache

a logical whether to do caching. Default is TRUE.

update_cache

a logical with a default value FALSE, whether to update 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 if the 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 variables which are not numeric are converted to factors. The default value FALSE, in this case they are returned as 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: https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/codelist/ESTAT/OBS_STATUS/?compressed=false&format=TSV&lang=en.

check_toc

a boolean whether to check the provided id in the Table of Contents (TOC) or not. The default value FALSE, in this case the base URL for the download link is retrieved from the configuration file. If the value is TRUE then the TOC is downloaded and the id is checked in it. If it found then the download link is retrieved form the TOC.

melt

a boolean with default value TRUE and used only if the mode="txt". In case it is FALSE, the downloaded tsv file is not melted, the time dimension remains in columns and it does not process the flags.

verbose

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

...

further argument for the load_cfg function

Value

a data.table with the following columns if the default melt=TRUE is used:

FREQThe frequency of the data (Annual, Semi-annual, Half-year, Quarterly, Monthly, Weekly, Daily)
dimension namesOne column for each dimension in the data
TIME_FORMATA column for the time format, if the source file SDMX-ML and the data was not loaded from a previously cached TSV download (this column is missing if the source file is TSV)
time/TIME_PERIODA column for the time dimension, where the name of the column depends on the source file (TSV/SDMX-ML)
values/OBS_VALUEA column for numerical values, where the name of the column depends on the source file (TSV/SDMX-ML)
flags/OBS_STATUSA column for flags if the keep_flags=TRUE otherwise this column is not included in the data table, and the name of the column depends on the source file (TSV/SDMX-ML)

The data does not include all missing values. The missing values are dropped if the value and flags are missing on a particular time.

In case melt=FALSE the results is a data.table where the first column contains the comma separated values of the various dimensions, and the columns contains the observations for each time dimension.

Details

Data sets are downloaded from the Eurostat bulk download facility in CSV, TSV or SDMX format.

The id, should be 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. By default all datasets downloaded in TSV format and 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. If the id is checked in TOC then the data will saved in the cache with the date from the "lastUpdate" column from the TOC, otherwise it is saved with the current date.

Examples

# \dontshow{
if (parallel::detectCores()<=2){
   options(restatapi_cores=1)
}else{
   options(restatapi_cores=2)
}    
# }
# \donttest{
if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2)
head(get_eurostat_raw("agr_r_milkpr",keep_flags=TRUE))
#>      freq milkitem dairyprod    geo   time values  flags
#>    <char>   <char>    <char> <char> <char> <char> <char>
#> 1:      A      PRO    D1110A     CY   1995 139.00       
#> 2:      A      PRO    D1110A    CY0   1995 139.00       
#> 3:      A      PRO    D1110A   CY00   1995 139.00       
#> 4:      A      PRO    D1110A     EE   1995 706.60       
#> 5:      A      PRO    D1110A    EE0   1995 706.60       
#> 6:      A      PRO    D1110A   EE00   1995 706.60       
head(get_eurostat_raw("avia_par_ee",mode="xml",check_toc=TRUE,update_cache=TRUE,verbose=TRUE))
#> 
#> get_eurostat_raw - API version:2
#> 
#> get_eurostat_toc - API version:2 - number of cores:2
#> get_eurostat_toc - Downloading https://ec.europa.eu/eurostat/api/dissemination/catalogue/toc/xml
#> get_eurostat_toc - class(xml_leafs): xml_nodeset
#> get_eurostat_toc - number of nodes: 9148
#> get_eurostat_toc - number of cores: 2
#> get_eurostat_toc - The TOC was cached in the file /tmp/Rtmp2iECG6/restatapi/toc.xml.en.rds.
#> get_eurostat_raw - raws of TOC: 7063
#> get_eurostat_raw - txt bulk url from TOC:https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/AVIA_PAR_EE?format=tsv&compressed=true
#> get_eurostat_raw - txt bulk url from cfg:https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/avia_par_ee?format=sdmx_2.1_structured&compressed=true
#> get_eurostat_raw - data rowcount in TOC: 91158
#> get_eurostat_raw - file format: gz
#> 
#> get_compressed_sdmx - url:https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/avia_par_ee?format=sdmx_2.1_structured&compressed=true
#> get_compressed_sdmx - format:gz
#> get_compressed_sdmx - xml NULL:FALSE
#> get_eurostat_raw - class(xml_leafs): xml_nodeset
#> get_eurostat_raw - number of nodes: 2208
#> get_eurostat_raw - number of cores: 2
#> get_eurostat_raw - caching in raw: FALSE
#> get_eurostat_raw - local filter: FALSE
#> get_eurostat_raw - called from: get_eurostat_rawavia_par_eexmlTRUETRUETRUE
#> get_eurostat_raw - get_eurostat_raw in sys.call(): FALSE
#>      unit tra_meas   freq         airp_pr TIME_PERIOD OBS_VALUE
#>    <char>   <char> <char>          <char>      <char>    <char>
#> 1: FLIGHT  CAF_PAS      A EE_EETN_AT_LOWW        2001       540
#> 2: FLIGHT  CAF_PAS      A EE_EETN_AT_LOWW        2002       726
#> 3: FLIGHT  CAF_PAS      A EE_EETN_AT_LOWW        2008       330
#> 4: FLIGHT  CAF_PAS      A EE_EETN_AT_LOWW        2012       476
#> 5: FLIGHT  CAF_PAS      A EE_EETN_AT_LOWW        2015       407
#> 6: FLIGHT  CAF_PAS      A EE_EETN_AT_LOWW        2016       535
options(restatapi_update=FALSE)
head(get_eurostat_raw("avia_par_me",mode="txt",melt=FALSE))
#>    freq,unit,tra_meas,airp_pr\\TIME_PERIOD   2016 2016-01 2016-02 2016-03
#>                                     <char> <char>  <char>  <char>  <char>
#> 1:        A,FLIGHT,CAF_PAS,ME_LYPG_AT_LOWW   1069       :       :       :
#> 2:        A,FLIGHT,CAF_PAS,ME_LYPG_BE_EBCI    208       :       :       :
#> 3:        A,FLIGHT,CAF_PAS,ME_LYPG_CH_LSZH    399       :       :       :
#> 4:        A,FLIGHT,CAF_PAS,ME_LYPG_DE_EDDB      :       :       :       :
#> 5:        A,FLIGHT,CAF_PAS,ME_LYPG_DE_EDDF    341       :       :       :
#> 6:        A,FLIGHT,CAF_PAS,ME_LYPG_DE_EDDS      :       :       :       :
#>    2016-04 2016-05 2016-06 2016-07 2016-08 2016-09 2016-10 2016-11 2016-12
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>    2016-Q1 2016-Q2 2016-Q3 2016-Q4   2017 2017-01 2017-02 2017-03 2017-04
#>     <char>  <char>  <char>  <char> <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :   1011       :       :       :       :
#> 2:       :       :       :       :    210       :       :       :       :
#> 3:       :       :       :       :    402       :       :       :       :
#> 4:       :       :       :       :    211       :       :       :       :
#> 5:       :       :       :       :    339       :       :       :       :
#> 6:       :       :       :       :      :       :       :       :       :
#>    2017-05 2017-06 2017-07 2017-08 2017-09 2017-10 2017-11 2017-12 2017-Q1
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>    2017-Q2 2017-Q3 2017-Q4   2018 2018-01 2018-02 2018-03 2018-04 2018-05
#>     <char>  <char>  <char> <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :   1008       :       :       :       :       :
#> 2:       :       :       :    214       :       :       :       :       :
#> 3:       :       :       :    423       :       :       :       :       :
#> 4:       :       :       :    208       :       :       :       :       :
#> 5:       :       :       :    338       :       :       :       :       :
#> 6:       :       :       :      :       :       :       :       :       :
#>    2018-06 2018-07 2018-08 2018-09 2018-10 2018-11 2018-12 2018-Q1 2018-Q2
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>    2018-Q3 2018-Q4   2019 2019-01 2019-02 2019-03 2019-04 2019-05 2019-06
#>     <char>  <char> <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :   1034       :       :       :       :       :       :
#> 2:       :       :    208       :       :       :       :       :       :
#> 3:       :       :    408       :       :       :       :       :       :
#> 4:       :       :    210       :       :       :       :       :       :
#> 5:       :       :    343       :       :       :       :       :       :
#> 6:       :       :    158       :       :       :       :       :       :
#>    2019-07 2019-08 2019-09 2019-10 2019-11 2019-12 2019-Q1 2019-Q2 2019-Q3
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>    2019-Q4   2020 2020-01 2020-02 2020-03 2020-04 2020-05 2020-06 2020-07
#>     <char> <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :    424       :       :       :       :       :       :       :
#> 2:       :      :       :       :       :       :       :       :       :
#> 3:       :      :       :       :       :       :       :       :       :
#> 4:       :      :       :       :       :       :       :       :       :
#> 5:       :      :       :       :       :       :       :       :       :
#> 6:       :      :       :       :       :       :       :       :       :
#>    2020-08 2020-09 2020-10 2020-11 2020-12 2020-Q1 2020-Q2 2020-Q3 2020-Q4
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>      2021 2021-01 2021-02 2021-03 2021-04 2021-05 2021-06 2021-07 2021-08
#>    <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:    836       :       :       :       :       :       :       :       :
#> 2:      :       :       :       :       :       :       :       :       :
#> 3:      :       :       :       :       :       :       :       :       :
#> 4:      :       :       :       :       :       :       :       :       :
#> 5:      :       :       :       :       :       :       :       :       :
#> 6:      :       :       :       :       :       :       :       :       :
#>    2021-09 2021-10 2021-11 2021-12 2021-Q1 2021-Q2 2021-Q3 2021-Q4   2022
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char> <char>
#> 1:       :       :       :       :       :       :       :       :   1293
#> 2:       :       :       :       :       :       :       :       :    198
#> 3:       :       :       :       :       :       :       :       :      :
#> 4:       :       :       :       :       :       :       :       :    159
#> 5:       :       :       :       :       :       :       :       :      :
#> 6:       :       :       :       :       :       :       :       :      :
#>    2022-01 2022-02 2022-03 2022-04 2022-05 2022-06 2022-07 2022-08 2022-09
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>    2022-10 2022-11 2022-12 2022-Q1 2022-Q2 2022-Q3 2022-Q4 2023-01 2023-02
#>     <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :       :       :       :
#>    2023-03 2023-04 2023-05 2023-06 2023-Q1 2023-Q2
#>     <char>  <char>  <char>  <char>  <char>  <char>
#> 1:       :       :       :       :       :       :
#> 2:       :       :       :       :       :       :
#> 3:       :       :       :       :       :       :
#> 4:       :       :       :       :       :       :
#> 5:       :       :       :       :       :       :
#> 6:       :       :       :       :       :       :
head(get_eurostat_raw("avia_par_me",
                      mode="txt",
                      cache_dir=tempdir(),
                      compress_file=FALSE,
                      verbose=TRUE))
#> 
#> get_eurostat_raw - API version:2
#> get_eurostat_raw - bulk url: https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/avia_par_me?format=TSV&compressed=true
#> get_eurostat_raw - class(raw): data.tabledata.frame
#> get_eurostat_raw - caching in raw: FALSE
#> get_eurostat_raw - local filter: FALSE
#> get_eurostat_raw - called from: get_eurostat_rawavia_par_metxttempdir()FALSETRUE
#> get_eurostat_raw - get_eurostat_raw in sys.call(): FALSE
#>      freq   unit tra_meas         airp_pr   time values
#>    <char> <char>   <char>          <char> <char> <char>
#> 1:      A FLIGHT  CAF_PAS ME_LYPG_AT_LOWW   2016   1069
#> 2:      A FLIGHT  CAF_PAS ME_LYPG_BE_EBCI   2016    208
#> 3:      A FLIGHT  CAF_PAS ME_LYPG_CH_LSZH   2016    399
#> 4:      A FLIGHT  CAF_PAS ME_LYPG_DE_EDDF   2016    341
#> 5:      A FLIGHT  CAF_PAS ME_LYPG_FR_LFPG   2016    473
#> 6:      A FLIGHT  CAF_PAS ME_LYPG_IT_LIRF   2016    702
options(timeout=60)
# }