Skip to content

Commit

Permalink
Get tibble functions from dplyr
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Nov 30, 2021
1 parent a499cc0 commit 1c4ede0
Show file tree
Hide file tree
Showing 24 changed files with 21 additions and 36 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Expand Up @@ -100,7 +100,6 @@ Imports:
rlang,
stringi,
stringr,
tibble,
tidyr (>= 1.0.0),
tidyselect,
vroom,
Expand Down
11 changes: 5 additions & 6 deletions R/Belgium.R
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
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
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
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
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
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
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
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
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
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
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
1 change: 0 additions & 1 deletion R/Mexico.R
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
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
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
Expand Up @@ -69,7 +69,7 @@ Switzerland <- R6::R6Class("Switzerland",
source_url = "https://github.com/openZH/covid_19/",

#' @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
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
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
1 change: 0 additions & 1 deletion R/Vietnam.R
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 Down
1 change: 0 additions & 1 deletion R/get_available_datasets.R
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
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
7 changes: 2 additions & 5 deletions R/processing.R
Expand Up @@ -7,7 +7,7 @@
#' @return A tibble with relevant NA columns added
#' @family compulsory_processing
#' @concept compulsory_processing
#' @importFrom tibble tibble add_column
#' @importFrom dplyr mutate
#' @importFrom rlang !!!
add_extra_na_cols <- function(data) {
expected_col_names <- c(
Expand All @@ -17,7 +17,7 @@ add_extra_na_cols <- function(data) {

new_cols <- rep(list(NA_real_), length(expected_col_names))
names(new_cols) <- expected_col_names
data <- add_column(
data <- mutate(
data,
!!!new_cols[!(names(new_cols) %in% names(data))]
)
Expand Down Expand Up @@ -50,7 +50,6 @@ set_negative_values_to_zero <- function(data) {
#' @return A tibble with rows of NAs added.
#' @family compulsory_processing
#' @concept compulsory_processing
#' @importFrom tibble tibble
#' @importFrom tidyr complete full_seq nesting
#' @importFrom tidyselect starts_with
#' @importFrom rlang !!! syms
Expand Down Expand Up @@ -103,7 +102,6 @@ complete_cumulative_columns <- function(data) {
#' @importFrom purrr walk2
#' @importFrom tidyr replace_na
#' @importFrom tidyselect ends_with
#' @importFrom tibble tibble
#' @importFrom rlang !! :=
calculate_columns_from_existing_data <- function(data) {
possible_counts <- c("cases", "deaths", "hosp", "recovered", "tested")
Expand Down Expand Up @@ -150,7 +148,6 @@ calculate_columns_from_existing_data <- function(data) {
#' @param data A data table
#' @return A data table, totalled up
#' @importFrom dplyr left_join group_by summarise select arrange
#' @importFrom tibble tibble
#' @family optional_processing
#' @concept optional_processing
totalise_data <- function(data) {
Expand Down
2 changes: 1 addition & 1 deletion R/shared-methods.R
Expand Up @@ -505,7 +505,7 @@ DataClass <- R6::R6Class(

#' @description Create a table of summary information for the data set
#' being processed.
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
#' @return Returns a single row summary tibble containing the origin of the
#' data source, class, level 1 and 2 region names, the type of data,
#' the urls of the raw data and the columns present in the raw data.
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Expand Up @@ -16,7 +16,7 @@ rlang::`.data`
#' @return A data table
#' @importFrom memoise memoise cache_filesystem
#' @importFrom vroom vroom
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
#' @importFrom withr with_envvar
#' @concept utility
csv_reader <- function(file, verbose = FALSE, guess_max = 1000, ...) {
Expand Down Expand Up @@ -50,7 +50,7 @@ csv_reader <- function(file, verbose = FALSE, guess_max = 1000, ...) {
#' @param ... extra parameters to be passed to jsonlite::fromJSON
#' @inheritParams message_verbose
#' @return A data table
#' @importFrom tibble tibble
#' @importFrom dplyr tibble
#' @importFrom jsonlite fromJSON
#' @concept utility
json_reader <- function(file, verbose = FALSE, ...) {
Expand Down

0 comments on commit 1c4ede0

Please sign in to comment.