# NOT RUN {
if (requireNamespace("sf", quietly = TRUE)) {
library(sf)
plot(urban_agglomerations)
}
# Code used to download the data:
# }
# NOT RUN {
f = "WUP2018-F11b-30_Largest_Cities_in_2018_by_time.xls"
download.file(
destfile = f,
url = paste0("https://population.un.org/wup/Download/Files/", f)
)
library(dplyr)
library(sf)
urban_agglomerations = readxl::read_excel(f, skip = 16) %>%
st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326)
names(urban_agglomerations)
names(urban_agglomerations) <- gsub(" |\\n", "_", tolower(names(urban_agglomerations)) ) %>%
gsub("\\(|\\)", "", .)
names(urban_agglomerations)
urban_agglomerations
usethis::use_data(urban_agglomerations, overwrite = TRUE)
file.remove("WUP2018-F11b-30_Largest_Cities_in_2018_by_time.xls")
# }
Run the code above in your browser using DataLab