-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
on: | ||
schedule: | ||
- cron: '36 12 * * *' | ||
workflow_dispatch: | ||
|
||
name: Vietnam | ||
|
||
jobs: | ||
Vietnam: | ||
runs-on: macOS-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: r-lib/actions/setup-r@v1 | ||
|
||
- name: Query dependencies | ||
run: | | ||
install.packages('remotes') | ||
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | ||
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | ||
shell: Rscript {0} | ||
|
||
- name: Cache R packages | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ env.R_LIBS_USER }} | ||
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | ||
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- | ||
|
||
- name: Install dependencies | ||
run: | | ||
install.packages(c("remotes")) | ||
remotes::install_deps(dependencies = TRUE) | ||
install.packages("devtools") | ||
shell: Rscript {0} | ||
|
||
- name: Install package | ||
run: R CMD INSTALL . | ||
|
||
- name: Test dataset | ||
run: | | ||
options("testDownload" = TRUE) | ||
options("testSource" = "Vietnam") | ||
devtools::load_all() | ||
testthat::test_file("tests/testthat/test-regional-datasets.R", reporter = c("summary", "fail")) | ||
shell: Rscript {0} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#' Vietnam Class for downloading, cleaning and processing | ||
#' notification data | ||
#' | ||
#' @description Information for downloading, cleaning | ||
#' and processing covid-19 region data for Vietnam. | ||
#' | ||
# nolint start | ||
#' @source \url{https://github.com/biocyberman/covidregionaldata/} | ||
# nolint end | ||
#' @export | ||
#' @concept dataset | ||
#' @family subnational | ||
#' @examples | ||
#' \dontrun{ | ||
#' region <- Vietnam$new(verbose = TRUE, steps = TRUE, get = TRUE) | ||
#' region$return() | ||
#' } | ||
Vietnam <- R6::R6Class("Vietnam", | ||
inherit = DataClass, | ||
public = list( | ||
|
||
# Core Attributes (amend each paramater for country specific infomation) | ||
#' @field origin name of country to fetch data for | ||
origin = "Vietnam", | ||
#' @field supported_levels List of supported levels. | ||
supported_levels = list("1"), | ||
#' @field supported_region_names List of region names in order of level. | ||
supported_region_names = list("1" = "region"), | ||
#' @field supported_region_codes List of region codes in order of level. | ||
supported_region_codes = list("1" = "is_3166_2"), | ||
#' @field common_data_urls List of named links to raw data. | ||
# nolint start | ||
common_data_urls = list( | ||
"main" = "https://docs.google.com/spreadsheets/d/1_d7oK-SKj-7KrWAW7DbGYEad2JO4TyR7ApsUAuoiH5g/export?format=csv&gid=0" | ||
), | ||
# nolint end | ||
#' @field source_data_cols existing columns within the raw data | ||
source_data_cols = c( | ||
"cases_new" | ||
), | ||
#' @field source_text Plain text description of the source of the data | ||
source_text = "Public COVID-19 data curated by 5F team", | ||
#' @field source_url Website address for explanation/introduction of the | ||
#' data | ||
source_url = "https://datastudio.google.com/u/0/reporting/1cc8d45e-2c74-4084-af70-cbbe60f1660e/page/bLUVC", # nolint | ||
|
||
#' @description Set up a table of region codes for clean data | ||
#' @importFrom tibble tibble | ||
set_region_codes = function(){ | ||
self$codes_lookup$`1` <- covidregionaldata::vietnam_codes | ||
}, | ||
|
||
#' @description Provincial Level Data | ||
#' cleaning | ||
#' @param ... pass additional arguments | ||
#' | ||
#' @importFrom dplyr filter select mutate rename | ||
#' @importFrom tidyr replace_na | ||
#' @importFrom lubridate dmy | ||
clean_common = function() { | ||
self$data$clean <- self$data$raw[["main"]] %>% | ||
`colnames<-`(c('date', 'region', 'cases_new', 'case_group')) %>% | ||
select( | ||
date, | ||
region, | ||
cases_new | ||
) %>% | ||
rename(level_1_region = region) %>% | ||
mutate( | ||
date = dmy(date), | ||
cases_new = as.numeric(cases_new) | ||
)%>% | ||
mutate( | ||
level_1_region = stringi::stri_trans_general(level_1_region, "latin-ascii"), | ||
level_1_region = stringi::stri_trim_both(level_1_region), | ||
level_1_region = stringr::str_replace_all(level_1_region, '\\(.*\\)|-| ', ''), | ||
level_1_region = stringr::str_to_title(level_1_region) | ||
) %>% | ||
left_join( | ||
self$codes_lookup$`1`, | ||
by = c("level_1_region" = "level_1_region") | ||
) | ||
} | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Set vietnam region codes | ||
# | ||
# Level 1 codes: ISO-3166-2 | ||
# Source: https://en.wikipedia.org/wiki/ISO_3166-2:VN | ||
# | ||
library(rvest) | ||
library(stringi) | ||
library(stringr) | ||
library(dplyr) | ||
library(tibble) | ||
|
||
# Level 1 ----------------------------------------------------------------- | ||
# Get ISO codes | ||
vn_iso <- "https://en.wikipedia.org/wiki/ISO_3166-2:VN" | ||
|
||
level_1_region_df <- read_html(vn_iso) %>% | ||
html_element(css="table.wikitable:nth-child(11)") %>% | ||
html_table() | ||
|
||
vietnam_codes <- data.frame( | ||
level_1_region_code = level_1_region_df$Code, | ||
level_1_region = level_1_region_df$`Subdivision name (vi)`, | ||
stringsAsFactors = FALSE | ||
) %>% | ||
mutate( | ||
level_1_region = stringi::stri_trans_general(level_1_region, "latin-ascii"), | ||
level_1_region = stringi::stri_trim_both(level_1_region), | ||
level_1_region = stringr::str_replace_all(level_1_region, '\\(.*\\)|-| ', ''), | ||
level_1_region = stringr::str_to_title(level_1_region) | ||
) | ||
|
||
# update package region_codes | ||
usethis::use_data(vietnam_codes, overwrite = TRUE) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.