Created
May 10, 2020 08:02
-
-
Save anirudhjayaraman/b7ffee2c15e390cb494f9c29c14444ed to your computer and use it in GitHub Desktop.
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
rm(list = ls()) | |
# Load relevant libraries ----------------------------------------------------- | |
library(stringr) | |
library(data.table) | |
# ============================================================================= | |
# COVID 19-India API: A volunteer-driven, crowdsourced database | |
# for COVID-19 stats & patient tracing in India | |
# ============================================================================= | |
url <- "https://api.covid19india.org/csv/" | |
# List out all CSV files to source -------------------------------------------- | |
html <- paste(readLines(url), collapse="\n") | |
pattern <- "https://api.covid19india.org/csv/latest/.*csv" | |
matched <- unlist(str_match_all(string = html, pattern = pattern)) | |
# Downloading the Data -------------------------------------------------------- | |
covid_datasets <- lapply(as.list(matched), fread) | |
# Naming the data objects appropriately --------------------------------------- | |
exclude_chars <- "https://api.covid19india.org/csv/latest/" | |
dataset_names <- substr(x = matched, | |
start = 1 + nchar(exclude_chars), | |
stop = nchar(matched)- nchar(".csv")) | |
# assigning variable names | |
for(i in seq_along(dataset_names)){ | |
assign(dataset_names[i], covid_datasets[[i]]) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment