-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_dim_info.R
58 lines (53 loc) · 1.94 KB
/
get_dim_info.R
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#' Get information about the dimensions of a given indicator
#'
#' @description
#' `r lifecycle::badge('experimental')` \cr
#' Get information about the dimensions of a given indicator
#'
#'
#' @details
#' If the indicator is not valid, returns "(PT) O codigo do indicador nao existe. / (EN) The indicator code does not exist." \cr
#' Calling `is_indicator_valid()` before using this function is recommended.
#'
#' @param indicator INE indicator ID as a 7 character string. Example: "0010003".
#' @param lang One of "PT" or "EN". Default is "PT".
#' @return A data frame with dim_num (dimension number), abrv (dimension description) and versao (dimension version) for the selected indicator.
#' A fourth column 'nota_dsg' is present for some indicators, with additional notes about the dimensions.
#' @importFrom magrittr %>%
#' @export
#'
#' @examples
#' get_dim_info("0011823", lang = "EN")
get_dim_info <- function(indicator, lang="PT") {
value <- NULL
valid_ind <- is_indicator_valid(indicator)
if (is.null(valid_ind)) {
return(invisible(NULL))
}
if (valid_ind) {
metadata <- get_metadata_raw(indicator = indicator, lang = lang)
if (is.null(metadata)) {
return(invisible(NULL))
}
metadata %>%
magrittr::extract2("Dimensoes") %>%
magrittr::extract2("Descricao_Dim") %>%
tibble::as_tibble_col() %>%
tidyr::unnest_wider(col = value)
} else {
#message("(PT) O código do indicador não existe. / (EN) The indicator code does not exist.")
message("(PT) O c\u00F3digo do indicador n\u00E3o existe. / (EN) The indicator code does not exist.")
return(invisible(NULL))
# metadata <- get_metadata_raw(indicator = indicator, lang = lang)
#
# if (is.null(metadata)) {
# return(invisible(NULL))
# }
#
# metadata %>%
# magrittr::extract2("Sucesso") %>%
# magrittr::use_series("Falso") %>%
# magrittr::extract2(1) %>%
# magrittr::use_series("Msg")
}
}