Created
July 14, 2021 15:02
-
-
Save fernandobarbalho/c4d9ecd8663eec48686ff14987b74604 to your computer and use it in GitHub Desktop.
Extração de dados do cofog diretamente da base de dados abertos do Tesouro Transparente
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readxl) | |
library(ckanr) | |
library(purrr) | |
ckanr::package_search() | |
package<- ckanr::package_show(id= "22d13d17-bf69-4a1a-add2-25cc1e25f2d7", | |
url= "https://www.tesourotransparente.gov.br/ckan") #busca todos os dados do dataset que se refere aos dados de COFOG | |
df_base_cofog<-#percorre todos os recursos do dataset para montar um único dataframe com os dados anuais com maio nível de detalhe | |
map_dfr(1:length(package[["resources"]]), function(a_pos){ | |
print(a_pos) | |
if (substr(package[["resources"]][[a_pos]]$name,1,10)== "Base COFOG"){#testa se é uma tabela dos dados anuais completa | |
tmp = tempfile(fileext = ".xlsx") | |
URL_add<- package[["resources"]][[a_pos]]$url | |
df_cofog<-download.file(URL_add,mode = "wb", destfile = tmp, extra = "-R", method = "libcurl") | |
df_cofog <- readxl::read_xlsx(tmp) | |
df_cofog <- janitor::clean_names(df_cofog) | |
df_cofog$natureza_despesa_detalhada <- as.character(df_cofog$natureza_despesa_detalhada) | |
df_cofog | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment