Skip to content

Commit

Permalink
Merge pull request epiforecasts#437 from epiforecasts/fewer-deps
Browse files Browse the repository at this point in the history
Reduce the number of `Imports`
  • Loading branch information
seabbs authored Dec 3, 2021
2 parents f6c9759 + 007b535 commit b93e19d
Show file tree
Hide file tree
Showing 31 changed files with 70 additions and 136 deletions.
5 changes: 0 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,14 @@ Imports:
jsonlite,
lifecycle,
lubridate,
magrittr,
memoise,
purrr,
R6,
readxl,
rlang,
stringi,
stringr,
tibble,
tidyr (>= 1.0.0),
tidyselect,
vroom,
withr,
xml2
Suggests:
ggplot2,
Expand Down
18 changes: 5 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ importFrom(countrycode,countrycode)
importFrom(countrycode,countryname)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,arrange)
importFrom(dplyr,as_tibble)
importFrom(dplyr,bind_rows)
importFrom(dplyr,count)
importFrom(dplyr,distinct)
importFrom(dplyr,do)
importFrom(dplyr,ends_with)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
Expand All @@ -78,6 +80,7 @@ importFrom(dplyr,summarise)
importFrom(dplyr,tally)
importFrom(dplyr,tibble)
importFrom(dplyr,transmute)
importFrom(dplyr,tribble)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(httr,GET)
Expand All @@ -95,7 +98,6 @@ importFrom(lubridate,month)
importFrom(lubridate,year)
importFrom(lubridate,ymd)
importFrom(lubridate,ymd_hms)
importFrom(magrittr,"%>%")
importFrom(memoise,cache_filesystem)
importFrom(memoise,memoise)
importFrom(purrr,compact)
Expand All @@ -114,17 +116,12 @@ importFrom(rlang,"!!")
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,syms)
importFrom(stringi,stri_replace_all)
importFrom(stringi,stri_trans_general)
importFrom(stringi,stri_trim_both)
importFrom(stringr,str_conv)
importFrom(stringr,str_detect)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_to_sentence)
importFrom(stringr,str_to_title)
importFrom(tibble,add_column)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tibble,tribble)
importFrom(stringr,str_trim)
importFrom(tidyr,complete)
importFrom(tidyr,drop_na)
importFrom(tidyr,fill)
Expand All @@ -134,13 +131,8 @@ importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,replace_na)
importFrom(tidyr,separate)
importFrom(tidyselect,all_of)
importFrom(tidyselect,ends_with)
importFrom(tidyselect,starts_with)
importFrom(tidyselect,vars_select_helpers)
importFrom(utils,download.file)
importFrom(utils,untar)
importFrom(vroom,vroom)
importFrom(withr,with_envvar)
importFrom(xml2,xml_find_first)
importFrom(xml2,xml_text)
11 changes: 5 additions & 6 deletions R/Belgium.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ Belgium <- R6::R6Class("Belgium",
source_url = "https://epistat.wiv-isp.be/covid/",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble tribble
#' @importFrom dplyr tibble tribble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble::tibble(
self$codes_lookup$`1` <- tibble(
level_1_region_code = c("BE-BRU", "BE-VLG", "BE-WAL"),
level_1_region = c("Brussels", "Flanders", "Wallonia")
)
self$codes_lookup$`2` <- tibble::tribble(
self$codes_lookup$`2` <- tribble(
~level_2_region_code, ~level_2_region, ~level_1_region_code,
"BE-VAN", "Antwerpen", "BE-VLG",
"BE-WBR", "BrabantWallon", "BE-WAL",
Expand All @@ -82,8 +82,7 @@ Belgium <- R6::R6Class("Belgium",

#' @description Downloads data from source and (for Belgium)
#' applies an initial data patch.
#' @importFrom dplyr select mutate filter bind_rows
#' @importFrom tibble tribble
#' @importFrom dplyr select mutate filter bind_rows tribble
download = function() {
# do the actual downloading using the parent download method
super$download()
Expand All @@ -92,7 +91,7 @@ Belgium <- R6::R6Class("Belgium",
# For now, we filter out the broken lines and replace them
# with the following data shim

fixed_lines <- tibble::tribble(
fixed_lines <- tribble(
~DATE, ~PROVINCE, ~REGION, ~AGEGROUP, ~SEX, ~CASES,
"2020-04-22", "Limburg", "Flanders", "50-59", "F", 10,
"2021-02-17", "VlaamsBrabant", "Flanders", "10-19", "M", 12
Expand Down
2 changes: 1 addition & 1 deletion R/Brazil.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Brazil <- R6::R6Class("Brazil",
source_url = "https://github.com/wcota/covid19br/blob/master/README.en.md",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tribble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup <- tibble(
state_name = c(
Expand Down
2 changes: 1 addition & 1 deletion R/Canada.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Canada <- R6::R6Class("Canada",
source_url = "https://open.canada.ca/data/en/dataset/261c32ab-4cfd-4f81-9dea-7b64065690dc", # nolint

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
canada_codes <- tibble(
code = c(
Expand Down
1 change: 0 additions & 1 deletion R/Colombia.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Colombia <- R6::R6Class("Colombia",
source_url = "https://github.com/danielcs88/colombia_covid-19/",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr mutate
set_region_codes = function() {
self$codes_lookup$`1` <- covidregionaldata::colombia_codes
Expand Down
2 changes: 1 addition & 1 deletion R/Cuba.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Cuba <- R6::R6Class("Cuba",


#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c(
Expand Down
2 changes: 1 addition & 1 deletion R/Estonia.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Estonia <- R6::R6Class("Estonia",


#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c("EE-37",
Expand Down
1 change: 0 additions & 1 deletion R/France.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ France <- R6::R6Class("France",


#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr select
set_region_codes = function() {
self$codes_lookup$`1` <- france_codes %>%
Expand Down
3 changes: 1 addition & 2 deletions R/Germany.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Germany <- R6::R6Class("Germany",


#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr mutate
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c(
Expand Down
2 changes: 1 addition & 1 deletion R/India.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ India <- R6::R6Class("India",
source_url = "https://www.covid19india.org",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c(
Expand Down
2 changes: 1 addition & 1 deletion R/Italy.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Italy <- R6::R6Class("Italy",
source_url = "https://github.com/pcm-dpc/COVID-19/blob/master/README_EN.md",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c(
Expand Down
1 change: 0 additions & 1 deletion R/JHU.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ JHU <- R6::R6Class("JHU", # rename to country name
source_url = "https://github.com/CSSEGISandData/COVID-19/",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
set_region_codes = function() {
self$codes_lookup$`1` <- JHU_codes
},
Expand Down
8 changes: 3 additions & 5 deletions R/Lithuania.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ Lithuania <- R6::R6Class("Lithuania",
#' @description Common data cleaning for both levels
#'
# nolint start
#' @importFrom dplyr mutate group_by summarise if_else filter select bind_rows rename left_join everything across lead
#' @importFrom tidyselect all_of
#' @importFrom dplyr mutate group_by summarise if_else filter select bind_rows rename left_join everything across lead all_of
#' @importFrom lubridate as_date
# nolint end
clean_common = function() {
Expand Down Expand Up @@ -244,7 +243,7 @@ Lithuania <- R6::R6Class("Lithuania",
# or qualitative)
sum_cols <- names(select(
self$data$raw$main,
"population":tidyselect::last_col()
"population":dplyr::last_col()
))
sum_cols <- sum_cols[!grepl("prc|map_colors", sum_cols)]

Expand Down Expand Up @@ -345,7 +344,6 @@ Lithuania <- R6::R6Class("Lithuania",
#' provided by the source at the level 2 (municipality) regional level.
#'
#' @importFrom dplyr group_by summarise ungroup full_join across if_else
#' @importFrom tidyselect vars_select_helpers
clean_level_1 = function() {
self$data$clean <- self$data$clean %>%
group_by(
Expand All @@ -354,7 +352,7 @@ Lithuania <- R6::R6Class("Lithuania",
) %>%
summarise(
across(
tidyselect::vars_select_helpers$where(is.numeric),
where(is.numeric),
sum
)
) %>%
Expand Down
1 change: 0 additions & 1 deletion R/Mexico.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Mexico <- R6::R6Class("Mexico",
source_url = "https://datos.covid-19.conacyt.mx",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr select
set_region_codes = function() {
self$codes_lookup$`1` <- covidregionaldata::mexico_codes %>%
Expand Down
1 change: 0 additions & 1 deletion R/Netherlands.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Netherlands <- R6::R6Class("Netherlands",
source_url = "https://data.rivm.nl/covid-19/",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
set_region_codes = function() {

},
Expand Down
2 changes: 1 addition & 1 deletion R/SouthAfrica.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SouthAfrica <- R6::R6Class("SouthAfrica",
source_url = "https://github.com/dsfsi/covid19za",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c(
Expand Down
2 changes: 1 addition & 1 deletion R/Switzerland.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Switzerland <- R6::R6Class("Switzerland",
source_url = "https://www.covid19.admin.ch/en/overview",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup$`1` <- tibble(
code = c(
Expand Down
3 changes: 1 addition & 2 deletions R/UK.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ UK <- R6::R6Class("UK",
#' Section 2, "2. Estimated new hospital cases"
#' @importFrom lubridate year month
#' @importFrom readxl read_excel cell_limits
#' @importFrom tibble as_tibble
#' @importFrom dplyr mutate select %>% group_by summarise left_join
#' @importFrom dplyr mutate select %>% group_by summarise left_join as_tibble
#' @importFrom tidyr pivot_longer
#' @param clean_data Cleaned UK covid-19 data
#' @param nhs_data NHS region data
Expand Down
2 changes: 1 addition & 1 deletion R/USA.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ USA <- R6::R6Class("USA",
source_url = "https://github.com/nytimes/covid-19-data",

#' @description Set up a table of region codes for clean data
#' @importFrom tibble tribble
#' @importFrom dplyr tibble
set_region_codes = function() {
self$codes_lookup <- usa_codes <- tibble(
level_1_region_code = c(
Expand Down
8 changes: 3 additions & 5 deletions R/Vietnam.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Vietnam <- R6::R6Class("Vietnam",
source_url = "https://covid19.ncsc.gov.vn",

#' @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
},
Expand All @@ -65,8 +64,7 @@ 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 stringi stri_trans_general stri_trim_both stri_replace_all
#' @importFrom stringr str_to_title str_replace_all
#' @importFrom stringr str_conv str_trim str_to_title str_replace_all
#' @importFrom lubridate dmy
clean_common = function() {
# The first three elements of self$data$raw are the data
Expand Down Expand Up @@ -121,8 +119,8 @@ Vietnam <- R6::R6Class("Vietnam",
#
#tidyr::drop_na(date, region_name) %>%
mutate(
level_1_region = stri_trans_general(level_1_region, "latin-ascii"),
level_1_region = stri_trim_both(level_1_region),
level_1_region = str_conv(level_1_region, "ASCII"),
level_1_region = str_trim(level_1_region, side = "both"),
level_1_region = str_replace_all(level_1_region,
"\\(.*\\)|-| ", ""),
level_1_region = str_to_title(level_1_region),
Expand Down
1 change: 0 additions & 1 deletion R/get_available_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' @family interface
#' @importFrom rlang .data
#' @importFrom dplyr select bind_rows filter
#' @importFrom tibble as_tibble
#' @export
#' @examples
#' # see all available datasets
Expand Down
1 change: 0 additions & 1 deletion R/get_linelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#' @importFrom lifecycle deprecate_warn
#' @importFrom dplyr if_else select mutate filter
#' @importFrom lubridate dmy
#' @importFrom tibble as_tibble
#' @importFrom utils download.file untar
#' @examples
#' \dontrun{
Expand Down
Loading

0 comments on commit b93e19d

Please sign in to comment.