api_call.R 3.15 KB
Newer Older
1
2
3
#' Get a codelist based on an identifier
#'
#' @param identifier  the codelist's identifier
4
5
6
#' @param language string for language(s) to return.
#' Available are 'all', 'fr', 'de', 'it', 'en'.
#' If 'all' (default), all languages are returned.
7
8
9
10
11
12
13
14
#' @param export_format the export's format
#' Available are CSV, XLSX, SDMX-ML or JSON.
#' @param version_format the export format's version
#' (2.0 or 2.1 when format is SDMX-ML).
#' @param annotations flag to include annotations
#'
#' @return response based on the export format
#' @export
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
15
get_codelist <- function(identifier,
16
                         language = "all",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
17
18
19
                         export_format = "SDMX-ML",
                         version_format = 2.1,
                         annotations = FALSE) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
20
21
  api <- api_class(
    api_type = "codelist",
22
23
    id = identifier,
    language = language,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
24
    export_format = export_format,
25
    parameters = glue::glue("annotations={tolower(annotations)}")
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
26
  )
27
  api$get_response()
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
28
29
30
}


31
32
33
34
35
36
37
38
39
40
41
42
#' Get one level of a nomenclature
#'
#' @param identifier nomenclature's identifier
#' @param filters additionnal filters
#' @param level_number level to export
#' @param language  the language of the response data
#' Available are 'fr', 'de', 'it', 'en'.
#' @param annotations flag to include annotations
#'
#' @return dataframe with 3 columns
#' (Code, Parent and Name in the selected language)
#' @export
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
43
get_nomenclature_one_level <- function(identifier,
44
                                       filters = list(),
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
45
                                       level_number = 1,
46
                                       language = "all",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
47
                                       annotations = FALSE) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
48
  parameters <- glue::glue(
49
    "level={level_number}",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
50
    "&annotations={tolower(annotations)}",
51
    "&{list_to_string(filters)}"
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
52
  )
53
54
  api <- api_class(
    api_type = "nomenclature_one_level",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
55
    id = identifier,
56
    language = language,
57
    parameters = parameters,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
58
    export_format = "CSV"
59
60
61
  )
  api$get_response()
}
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
62
63


64
65
66
67
68
69
70
71
72
73
74
75
76
#' Get multiple levels of a nomenclature (from `level_from` to `level_to`)
#'
#' @param identifier nomenclature's identifier
#' @param filters additionnal filters
#' @param level_from the 1st level to include
#' @param level_to the last level to include
#' @param language  the language of the response data
#' Available are 'fr', 'de', 'it', 'en'.
#' @param annotations flag to include annotations
#'
#' @return dataframe columns
#' from `level_from` to `level_to` codes
#' @export
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
77
get_nomenclature_multiple_levels <- function(identifier,
78
                                             filters = list(),
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
79
80
                                             level_from = 1,
                                             level_to = 2,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
81
                                             language = "fr",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
82
                                             annotations = FALSE) {
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
83
84
85
86
87
  parameters <- glue::glue(
    "language={language}",
    "&levelFrom={level_from}",
    "&levelTo={level_to}",
    "&annotations={tolower(annotations)}",
88
    "&{list_to_string(filters)}"
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
89
  )
90
91
  api <- api_class(
    api_type = "nomenclature_multiple_levels",
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
92
    id = identifier,
93
    parameters = parameters,
Pauline Maury Laribière's avatar
Pauline Maury Laribière committed
94
    export_format = "CSV"
95
  )
96
  res <- api$get_response()
97
}