Skip to content

Commit

Permalink
adding testing data from OWID reading fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mponce0 committed Feb 2, 2021
1 parent 0033105 commit 6210cae
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Jan 2021: More data sources added _ ver 2.1
- Vaccination data, from OWID
- Testing data, from OWID
- pandemics data, from Visual Capitalist infographics
- report.Tor fn, to report overview analysis of Toronto data

Expand Down
68 changes: 52 additions & 16 deletions R/covid19_vaccination_testing.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
# functions to obtain covid19 vaccination data
# SRC: Our World In Data
# functions to obtain covid19 Vaccination & Testing data
# SRC: "Our World In Data" (OWID)
#
# M.Ponce - covid19.analytics


OWID.repos <- function(tgt) {
#' function to define the OWID repos URLs
#'
#' @param tgt target case: 'global','us','country','locations'
#' @param tgt target case: 'VAC.global','VAC.us','VAC.country','VAC.locations', 'testing'
#'
#' @return URL
#'

# OWID gtihub repo
owid.repo <- "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/"
vacc.locns <- paste0(owid.repo,"locations.csv")
#owid.repo <- "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/"
owid.repo <- "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/"
vacc.repo <- paste0(owid.repo,"vaccinations/")
vacc.locns <- paste0(vacc.repo,"locations.csv")
testing.repo <- paste0(owid.repo,"testing/")
testing.data <- paste0(testing.repo, "covid-testing-all-observations.csv")
testing.data.details <- paste0(testing.repo,"covid-testing-latest-data-source-details.csv")

# United States vaccination data
#
# State-by-state data on United States COVID-19 vaccinations. We rely on the data updated daily by the United States Centers for Disease Control and Prevention. Stored in us_state_vaccinations.csv.
vacc.us <- paste0(owid.repo,"us_state_vaccinations.csv")
vacc.us <- paste0(vacc.repo,"us_state_vaccinations.csv")

# Vaccination data
#
# Country-by-country data on global COVID-19 vaccinations. We only rely on figures that are verifiable based on public official sources. Stored in vaccinations.csv.
vacc.global <- paste0(owid.repo,"vaccinations.csv")
vacc.global <- paste0(vacc.repo,"vaccinations.csv")

# specific per country -- it will be one file per country
vacc.country <- paste0(owid.repo,"country_data/")
vacc.country <- paste0(vacc.repo,"country_data/")

if (tgt == 'locations') {
# VACINATION REPOS
if (tgt == 'VAC.locations') {
repo <- vacc.locns
} else if (tgt == 'us') {
} else if (tgt == 'VAC.us') {
repo <- vacc.us
} else if (tgt == 'global') {
} else if (tgt == 'VAC.global') {
repo <- vacc.global
} else if (tgt == 'country') {
} else if (tgt == 'VAC.country') {
repo <- vacc.country
# TESTING REPOS
} else if (tgt == 'testing') {
repo <- testing.data
# UNRECOGNIZED option
} else {
stop("Error : unrecognized target! -- ",tgt)
}
Expand All @@ -45,11 +55,14 @@ OWID.repos <- function(tgt) {
}


c19.vaccination <- function(repo, disclaimer=TRUE){
#' function to read data from OWID repo
c19.OWID.data <- function(repo, disclaimer=TRUE){
#' function to read data from OWID repos
#'
#' @param repo URL for reading the data
#' @param disclaimer indicate whether the information about the source of the data is disclosed
#'
#' @return datafram object
#'

vacc.data <- read.csv(repo)

Expand All @@ -68,14 +81,17 @@ covid19.vaccination <- function(tgt="global", data.fmt='orig', disclaimer=TRUE){
#' @param tgt selects data type: 'global','us','country','locations'
#' @param data.fmt selects the format of the data, options are: 'orig' (original as reported by the OWID repo)
#' @param disclaimer indicates whether the information about the source of the data is disclosed
#'
#' @export
#'

# select repo depending on target
tgt <- paste0("VAC.",tgt)
repo <- OWID.repos(tgt)

# distinguish between 'country' and everything else
if (tgt != 'country') {
return(c19.vaccination(repo,disclaimer))
return(c19.OWID.data(repo,disclaimer))
} else {
skip <- c("European Union","World")
# obtain list of countries
Expand All @@ -88,8 +104,28 @@ covid19.vaccination <- function(tgt="global", data.fmt='orig', disclaimer=TRUE){
for (cty in ctries) {
# convert names into URL notation, ie. spaces -> %20
cty <- gsub("[[:space:]]", "%20", cty)
vacc.countries[[cty]] <- c19.vaccination(paste0(repo,"/",cty,'.csv'))
vacc.countries[[cty]] <- c19.OWID.data(paste0(repo,"/",cty,'.csv'))
}
return(vacc.countries)
}
}



covid19.testing.data <- function(disclaimer=TRUE){
#' function to read data related to covid19 Testing from OWID repo
#'
#' @param disclaimer indicates whether the information about the source of the data is disclosed
#'
#' @return dataframe containing list of countries (Entity) and testing data
#'
#' @export
#'

tgt <- "testing"
repo <- OWID.repos("testing")

tst.data <- c19.OWID.data(repo,disclaimer)

return(tst.data)
}

0 comments on commit 6210cae

Please sign in to comment.