Skip to content

Commit

Permalink
make sure any changes to variable order doesn't impact output
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Feb 4, 2022
1 parent b9887be commit 2e98e5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions R/processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ process_internal <- function(clean_data, level, group_vars,
group_vars_standard, "cases_total", "deaths_total", "recovered_total",
"hosp_total", "tested_total"
)
))
)) %>%
ungroup()
} else {
dat <- dat %>%
drop_na(.data$date) %>%
Expand All @@ -258,9 +259,9 @@ process_internal <- function(clean_data, level, group_vars,
)),
everything()
) %>%
ungroup() %>%
arrange(.data$date, all_of(group_vars_standard[1]))
}
dat <- ungroup(dat)

if (localise) {
old <- names(group_vars)
Expand Down
12 changes: 7 additions & 5 deletions tests/testthat/custom_tests/mock_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,16 @@ get_expected_data_for_fill_empty_dates_with_na_test <- function() {
# full data is data with all dates/regions + some NAs in the cases column
expected_data <- data.frame(expand.grid(dates, regions))
colnames(expected_data) <- c("date", "level_1_region")

expected_data$date <- as.Date(expected_data$date)
expected_data$level_1_region <- as.character(expected_data$level_1_region)
expected_data <- expected_data %>%
dplyr::arrange(date, level_1_region) %>%
dplyr::left_join(region_codes, by = c("level_1_region" = "region"))
expected_data$cases <- c(1:5, rep(NA, 4), 10:12)
expected_data <- dplyr::select(
expected_data, level_1_region, level_1_region_code, date, everything()
)
return(dplyr::tibble(expected_data))
}

Expand All @@ -235,10 +239,8 @@ get_expected_data_for_complete_cumulative_columns_test <- function() {

# manually add cumulative cases to get expected data
full_data_with_cum_cases_filled <- partial_data %>%
dplyr::group_by(level_1_region) %>%
covidregionaldata:::fill_empty_dates_with_na() %>%
dplyr::ungroup()

dplyr::group_by(level_1_region, level_1_region_code) %>%
covidregionaldata:::fill_empty_dates_with_na()
full_data_with_cum_cases_filled <-
dplyr::arrange(full_data_with_cum_cases_filled, level_1_region, date)
full_data_with_cum_cases_filled <-
Expand All @@ -248,5 +250,5 @@ get_expected_data_for_complete_cumulative_columns_test <- function() {
)
colnames(full_data_with_cum_cases_filled)[5] <- "cases_total"

return(dplyr::tibble(full_data_with_cum_cases_filled))
return(full_data_with_cum_cases_filled)
}
3 changes: 3 additions & 0 deletions tests/testthat/test-processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ test_that("fill_empty_dates_with_na fills empty dates with NA", {
expected_data <- get_expected_data_for_fill_empty_dates_with_na_test()
# partial data deletes some rows (i.e. gets rid of some dates - all the ones
# with NA in cases)
expected_data <- expected_data %>%
dplyr::group_by(, level_1_region, level_1_region_code)

partial_data <- expected_data[-c(6:9), ]
expect_equal(fill_empty_dates_with_na(partial_data), expected_data)
expected_data <- dplyr::mutate(
Expand Down

0 comments on commit 2e98e5e

Please sign in to comment.