Skip to content

Commit

Permalink
Vietnam fix added
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardMN committed Feb 4, 2022
1 parent 190ab71 commit b607e1f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ Imports:
R6,
readxl,
rlang,
stringi,
stringr,
tidyr (>= 1.0.0),
tidyselect,
vroom,
xml2
Suggests:
Expand Down
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ importFrom(rlang,"!!")
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,syms)
importFrom(stringr,str_conv)
importFrom(stringi,stri_trans_general)
importFrom(stringi,stri_trim_both)
importFrom(stringr,str_detect)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_to_sentence)
importFrom(stringr,str_to_title)
importFrom(stringr,str_trim)
importFrom(tidyr,complete)
importFrom(tidyr,drop_na)
importFrom(tidyr,fill)
Expand All @@ -133,6 +133,7 @@ importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,replace_na)
importFrom(tidyr,separate)
importFrom(tidyselect,vars_select_helpers)
importFrom(utils,download.file)
importFrom(utils,untar)
importFrom(vroom,vroom)
Expand Down
43 changes: 25 additions & 18 deletions R/Vietnam.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Vietnam <- R6::R6Class("Vietnam",
#' @importFrom dplyr filter select mutate rename tibble as_tibble full_join
#' @importFrom tidyr replace_na drop_na separate
#' @importFrom purrr map
#' @importFrom stringr str_conv str_trim str_to_title str_replace_all
#' @importFrom stringr str_to_title str_replace_all
#' @importFrom stringi stri_trans_general stri_trim_both
#' @importFrom lubridate dmy
clean_common = function() {
# The first three elements of self$data$raw are the data
Expand All @@ -80,28 +81,34 @@ Vietnam <- R6::R6Class("Vietnam",
y %>% separate(date, sep = "[.]+", into = c(NA, "province", "date"))
}
)
self$data$clean <- full_join(
full_join(
flat_all$case_by_time, flat_all$death_by_time,
by = c("province", "date"),
suffix = c(".cases", ".deaths"),
copy = TRUE
),
flat_all$recovered_by_time,
by = c("province", "date"),
suffix = c("", ".recovered"),
copy = TRUE
) %>%
index_cols <- bind_rows(
flat_all$case_by_time %>% select("date", "province"),
flat_all$death_by_time %>% select("date", "province"),
flat_all$recovered_by_time %>% select("date", "province")) %>%
unique()

self$data$clean <-
left_join(index_cols, flat_all$case_by_time %>% rename(cases_total =value),
by = c("province", "date") ) %>%
left_join(flat_all$death_by_time %>% rename(deaths_total =value),
by = c("province", "date") ) %>%
left_join(flat_all$recovered_by_time %>% rename(recovered_total =value),
by = c("province", "date") ) %>%
# The api uses integer codes for provinces which do not
# line up with ISO 3166-2 (some of which are not numbers)
# so we use this as a temporary code to line names up
# with data.
select(
ncsc_region_code = province,
date,
cases_total = value.cases,
deaths_total = value.deaths,
recovered_total = value) %>%
cases_total,
deaths_total,
recovered_total
# ,
# cases_total = value.cases,
# deaths_total = value.deaths,
# recovered_total = value
) %>%
mutate(ncsc_region_code = as.numeric(ncsc_region_code)) %>%
left_join(
self$data$raw$provinces %>%
Expand All @@ -119,8 +126,8 @@ Vietnam <- R6::R6Class("Vietnam",
#
#tidyr::drop_na(date, region_name) %>%
mutate(
level_1_region = str_conv(level_1_region, "ASCII"),
level_1_region = str_trim(level_1_region, side = "both"),
level_1_region = stri_trans_general(level_1_region, "ASCII"),
level_1_region = stri_trim_both(level_1_region),
level_1_region = str_replace_all(level_1_region,
"\\(.*\\)|-| ", ""),
level_1_region = str_to_title(level_1_region),
Expand Down
Binary file modified data/all_country_data.rda
Binary file not shown.

0 comments on commit b607e1f

Please sign in to comment.