tests/sgstbcb.R

#' SGSTBCB - Sistema Gerenciador de Séries Temporais do Banco Central do Brasil
#'
#' This function get data from \url{https://www3.bcb.gov.br/sgspub/}
#' through api.
#'
#' @param cod is provide from the \url{https://www3.bcb.gov.br/sgspub/}.
#'
#' @example
#' sgstbcb(cod = 253)
#' 
#' @export
sgstbcb <- function(cod = NULL) {
    url <- "http://api.bcb.gov.br/dados/serie/bcdata.sgs.%s/dados?formato=json&dataInicial=01/01/2001"
    link <- sprintf(url, cod)
    x <- try(jsonlite::fromJSON(link), silent = TRUE)
    if (class(x) == "try-error") return(NULL) else return(x)
}
Andryas/WEBDATA documentation built on Jan. 2, 2020, 1:31 p.m.