Skip to contents

Get the data of the last millesime of all the datafiles found in data. All columns are returned as chr (see below).

For private life reason, data returned by DiDo can be secretize (the value is replaced by the string "secret") so readr can't determine data type. You can use convert() to convert number and integer.

get_data cache data before loading it. By default it saves the files in tempdir(). If you downloaded the same data again, il will first try to find it in the cache argument. If you want to cache data between session, don't keep the default but use your own directory.

Usage

get_data(
  data,
  query = list(),
  col_types = cols(.default = "c"),
  concat = TRUE,
  cache = tempdir()
)

Arguments

data

a tibble issued from datafiles() or a dataframe with two columns ridandmillesime`.

query

a query to pass to the API to select columns and filter on values.

col_types

how to convert columns, the default is to use char for all columns cols(.default = "c")

concat

TRUE if TRUE, returns a tibble with all data concatenated in one tibble, else returns a list of tibbles.

cache

the directory to cache/save downloaded files. Default is tempdir()

Value

If concat is TRUE (default), return a tibble with all data concatenated in one tibble. If concat is FALSE, return a list of tibbles.

get_data() returns only chr columns. Use convert to convert columns to good types.

Details

For caching, get_data() will use a reproductible name compose of the datafile identifier (rid) and the stringification of the query passed to get_data() of a query is passed.

Examples

# get all columns
datafiles() %>%
  dido_search("drom") %>%
  get_data()
#>  reading data from cache : /tmp/RtmpF5CYw6/6c79805c-def9-4695-9d9f-7d86599c4d8a-2022-10.csv
#> # A tibble: 55 × 10
#>    DEPARTEMENT_CODE DEPARTEMENT_LIBELLE REGION_CODE REGION_LIBELLE ANNEE
#>    <chr>            <chr>               <chr>       <chr>          <chr>
#>  1 971              Guadeloupe          01          Guadeloupe     2021 
#>  2 972              Martinique          02          Martinique     2021 
#>  3 973              Guyane              03          Guyane         2021 
#>  4 974              La Réunion          04          La Réunion     2021 
#>  5 976              Mayotte             06          Mayotte        2021 
#>  6 971              Guadeloupe          01          Guadeloupe     2020 
#>  7 972              Martinique          02          Martinique     2020 
#>  8 973              Guyane              03          Guyane         2020 
#>  9 974              La Réunion          04          La Réunion     2020 
#> 10 976              Mayotte             06          Mayotte        2020 
#> # ℹ 45 more rows
#> # ℹ 5 more variables: ESSENCE_M3 <chr>, GAZOLE_M3 <chr>, FIOUL_M3 <chr>,
#> #   GPL_M3 <chr>, CARBUREACTEUR_M3 <chr>
# get only DEPARTEMENT_CODE and ESSENCE_M3 columns
datafiles() %>%
  dido_search("drom") %>%
  get_data(query = c(columns = "DEPARTEMENT_CODE,ESSENCE_M3"))
#>  downloading data and caching to : /tmp/RtmpF5CYw6/6c79805c-def9-4695-9d9f-7d86599c4d8a-2022-10-columns=DEPARTEMENT_CODE,ESSENCE_M3.csv
#> 
Downloading: 280 B     
Downloading: 280 B     
Downloading: 280 B     
Downloading: 280 B     
#> # A tibble: 55 × 2
#>    DEPARTEMENT_CODE ESSENCE_M3
#>    <chr>            <chr>     
#>  1 971              118664    
#>  2 972              125134    
#>  3 973              39528     
#>  4 974              151834    
#>  5 976              22575     
#>  6 971              112378    
#>  7 972              115415    
#>  8 973              26717     
#>  9 974              129677    
#> 10 976              19592     
#> # ℹ 45 more rows
# get only rows where `DEPARTEMENT_CODE == 971
datafiles() %>%
  dido_search("drom") %>%
  get_data(query = c(DEPARTEMENT_CODE = "eq:971"))
#>  downloading data and caching to : /tmp/RtmpF5CYw6/6c79805c-def9-4695-9d9f-7d86599c4d8a-2022-10-DEPARTEMENT_CODE=eq971.csv
#> 
Downloading: 380 B     
Downloading: 380 B     
Downloading: 380 B     
Downloading: 380 B     
Downloading: 380 B     
Downloading: 380 B     
#> # A tibble: 11 × 10
#>    DEPARTEMENT_CODE DEPARTEMENT_LIBELLE REGION_CODE REGION_LIBELLE ANNEE
#>    <chr>            <chr>               <chr>       <chr>          <chr>
#>  1 971              Guadeloupe          01          Guadeloupe     2021 
#>  2 971              Guadeloupe          01          Guadeloupe     2020 
#>  3 971              Guadeloupe          01          Guadeloupe     2019 
#>  4 971              Guadeloupe          01          Guadeloupe     2018 
#>  5 971              Guadeloupe          01          Guadeloupe     2017 
#>  6 971              Guadeloupe          01          Guadeloupe     2016 
#>  7 971              Guadeloupe          01          Guadeloupe     2015 
#>  8 971              Guadeloupe          01          Guadeloupe     2014 
#>  9 971              Guadeloupe          01          Guadeloupe     2013 
#> 10 971              Guadeloupe          01          Guadeloupe     2012 
#> 11 971              Guadeloupe          01          Guadeloupe     2011 
#> # ℹ 5 more variables: ESSENCE_M3 <chr>, GAZOLE_M3 <chr>, FIOUL_M3 <chr>,
#> #   GPL_M3 <chr>, CARBUREACTEUR_M3 <chr>
datafiles() %>%
  dido_search("drom") %>%
  get_data(query = c(DEPARTEMENT_CODE = "eq:971"), cache = tempdir())
#>  reading data from cache : /tmp/RtmpF5CYw6/6c79805c-def9-4695-9d9f-7d86599c4d8a-2022-10-DEPARTEMENT_CODE=eq971.csv
#> # A tibble: 11 × 10
#>    DEPARTEMENT_CODE DEPARTEMENT_LIBELLE REGION_CODE REGION_LIBELLE ANNEE
#>    <chr>            <chr>               <chr>       <chr>          <chr>
#>  1 971              Guadeloupe          01          Guadeloupe     2021 
#>  2 971              Guadeloupe          01          Guadeloupe     2020 
#>  3 971              Guadeloupe          01          Guadeloupe     2019 
#>  4 971              Guadeloupe          01          Guadeloupe     2018 
#>  5 971              Guadeloupe          01          Guadeloupe     2017 
#>  6 971              Guadeloupe          01          Guadeloupe     2016 
#>  7 971              Guadeloupe          01          Guadeloupe     2015 
#>  8 971              Guadeloupe          01          Guadeloupe     2014 
#>  9 971              Guadeloupe          01          Guadeloupe     2013 
#> 10 971              Guadeloupe          01          Guadeloupe     2012 
#> 11 971              Guadeloupe          01          Guadeloupe     2011 
#> # ℹ 5 more variables: ESSENCE_M3 <chr>, GAZOLE_M3 <chr>, FIOUL_M3 <chr>,
#> #   GPL_M3 <chr>, CARBUREACTEUR_M3 <chr>