-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from vincentarelbundock/update-world_bank_scr…
…aper update world_bank scraper
- Loading branch information
Showing
2 changed files
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
source(here::here('dictionary/utilities.R')) | ||
|
||
url <- 'http://databank.worldbank.org/data/download/site-content/CLASS.xls' | ||
url <- 'https://databankfiles.worldbank.org/public/ddpext_download/site-content/CLASS.xlsx' | ||
|
||
filename <- tempfile(fileext = '.xls') | ||
filename <- tempfile(fileext = '.xlsx') | ||
download.file(url, filename, quiet = TRUE) | ||
|
||
not_countries <- c("Arab World", "Caribbean small states", "Central Europe and the Baltics", "Early-demographic dividend", "East Asia & Pacific", "East Asia & Pacific (excluding high income)", "East Asia & Pacific (IDA & IBRD)", "Euro area", "Europe & Central Asia", "Europe & Central Asia (excluding high income)", "Europe & Central Asia (IDA & IBRD)", "European Union", "Fragile and conflict affected situations", "Heavily indebted poor countries (HIPC)", "High income", "IBRD only", "IDA & IBRD total", "IDA blend", "IDA only", "IDA total", "Late-demographic dividend", "Latin America & Caribbean", "Latin America & Caribbean (excluding high income)", "Latin America & Caribbean (IDA & IBRD)", "Least developed countries: UN classification", "Low & middle income", "Low income", "Lower middle income", "Middle East & North Africa", "Middle East & North Africa (excluding high income)", "Middle East & North Africa (IDA & IBRD)", "Middle income", "North America", "OECD members", "Other small states", "Pacific island small states", "Post-demographic dividend", "Pre-demographic dividend", "Small states", "South Asia", "South Asia (IDA & IBRD)", "Sub-Saharan Africa", "Sub-Saharan Africa (excluding high income)", "Sub-Saharan Africa (IDA & IBRD)", "Upper middle income", "World") | ||
|
||
# weird read_excel call to silence warnings | ||
wb <- read_excel(filename, skip = 6, col_names = letters[1:9]) %>% | ||
select(3:4) %>% | ||
wb <- read_excel(filename, sheet = "List of economies") %>% | ||
select(Economy, Code) %>% | ||
setNames(c('country', 'wb')) %>% | ||
filter(!country %in% not_countries, | ||
!is.na(wb)) | ||
filter( | ||
!country %in% not_countries, | ||
!is.na(wb) | ||
) %>% | ||
arrange(country) | ||
|
||
wb %>% write_csv('dictionary/data_world_bank.csv', na = "") |