Last active
March 22, 2021 18:36
-
-
Save novica/4f4706d5423964078789cec29231a368 to your computer and use it in GitHub Desktop.
R script to create a clean csv from the municipal income budget pdf
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
box::use( | |
tabulizer[locate_areas, extract_tables], | |
purrr[reduce], | |
dplyr[mutate, across, select, bind_rows, if_else, glimpse, `%>%`], | |
stringr[str_remove, str_remove_all], | |
readr[write_csv] | |
) | |
# bilans na prihodi | |
# this is for aerodrom municipality but it should work for all assuming they have the same format pdf | |
# locate the table in the pdf | |
#bp <- locate_areas("http://aerodrom.gov.mk/Upload/Editor_Upload/januari%202021/(01)%20Bilans%20na%20Prih_B2021%20Stavka%2030_12_2020.pdf") | |
# or use this coordinates if it looks the same as the aerodrom one | |
bp <- list(c(top = 159.88176, | |
left = 20.08177, | |
bottom = 340.57072, | |
right = 824.89750)) | |
bp_table <- extract_tables("http://aerodrom.gov.mk/Upload/Editor_Upload/januari%202021/(01)%20Bilans%20na%20Prih_B2021%20Stavka%2030_12_2020.pdf", | |
output = "data.frame", | |
area = bp, | |
guess = FALSE | |
) | |
bp_table_clean <- reduce(bp_table, bind_rows) | |
bp_table_clean <- rbind(names(bp_table_clean), bp_table_clean) | |
prihodi_names = c("kategorija", "stavka", "opis", "prethoden_budget", "budget", | |
"prihodi_od_samofinansirani_aktivnosti", "prihodi_od dotacii", | |
"prihodi_od_donacii", "prihodi_od_krediti", "vkupno_prihodi") | |
bp_table_complete <- bp_table_clean %>% | |
mutate(across(.cols = everything(), .fns = ~str_remove(., "X"))) %>% | |
mutate(across(.cols = everything(), .fns = ~str_remove(., "\\.\\d$"))) %>% | |
mutate(across(.cols = 3:9, .fns = ~str_remove_all(., "\\."))) %>% | |
mutate(across(.cols = 3:9, .fns = ~str_remove_all(., "\\,"))) %>% | |
mutate(X71_new = if_else(nchar(X71) == 3, X71, NA_character_)) %>% | |
mutate(X71 = if_else(nchar(X71) == 2, X71, str_extract(X71, "\\d\\d"))) %>% | |
select(X71, X71_new, everything()) | |
colnames(bp_table_complete) <- prihodi_names | |
opis <- c("Даночни приходи", "Данок од доход, од добивка и од капитални добивки", | |
"Даноци на имот", "Даноци на специфични услуги", | |
"Такси на користење или дозволи за вршење дејност", | |
"Неданочни приходи", "Глоби, судски и административни такси", | |
"Такси и надоместоци", "Други неданочни приходи", | |
"Капитални приходи", "Продажба на земјиште и нематеријални вложувања", | |
"Трансфери и донации", "Трансфери од други нивоа на власт", | |
"Донации од странство") | |
bp_table_complete$opis <- opis | |
glimpse(bp_table_complete) | |
write_csv(bp_table_complete, "aerodrom_bilans_na_prihodi_2021.csv") |
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
kategorija | stavka | opis | prethoden_budget | budget | prihodi_od_samofinansirani_aktivnosti | prihodi_od dotacii | prihodi_od_donacii | prihodi_od_krediti | vkupno_prihodi | |
---|---|---|---|---|---|---|---|---|---|---|
71 | NA | Даночни приходи | 436349000 | 441030000 | 0 | 0 | 0 | 0 | 441030000 | |
71 | 711 | Данок од доход, од добивка и од капитални добивки | 15560000 | 15560000 | 0 | 0 | 0 | 0 | 15560000 | |
71 | 713 | Даноци на имот | 89010000 | 88810000 | 0 | 0 | 0 | 0 | 88810000 | |
71 | 717 | Даноци на специфични услуги | 331579000 | 336460000 | 0 | 0 | 0 | 0 | 336460000 | |
71 | 718 | Такси на користење или дозволи за вршење дејност | 200000 | 200000 | 0 | 0 | 0 | 0 | 200000 | |
72 | NA | Неданочни приходи | 93096000 | 4000000 | 83833000 | 0 | 0 | 0 | 87833000 | |
72 | 722 | Глоби, судски и административни такси | 600000 | 600000 | 0 | 0 | 0 | 0 | 600000 | |
72 | 723 | Такси и надоместоци | 90496000 | 1400000 | 83833000 | 0 | 0 | 0 | 85233000 | |
72 | 725 | Други неданочни приходи | 2000000 | 2000000 | 0 | 0 | 0 | 0 | 2000000 | |
73 | NA | Капитални приходи | 4600000 | 38160000 | 0 | 0 | 0 | 0 | 38160000 | |
73 | 733 | Продажба на земјиште и нематеријални вложувања | 4600000 | 38160000 | 0 | 0 | 0 | 0 | 38160000 | |
74 | NA | Трансфери и донации | 851157000 | 349167000 | 0 | 421129000 | 20286000 | 0 | 790582000 | |
74 | 741 | Трансфери од други нивоа на власт | 833916000 | 349167000 | 0 | 421129000 | 0 | 0 | 770296000 | |
74 | 742 | Донации од странство | 17241000 | 0 | 0 | 0 | 20286000 | 0 | 20286000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment