Skip to content

Commit

Permalink
Merge pull request epiforecasts#455 from epiforecasts/bug-454-country…
Browse files Browse the repository at this point in the history
…code

Bug 454 countrycode
  • Loading branch information
seabbs authored Feb 5, 2022
2 parents ab8c599 + a6e7fac commit 845b500
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
3 changes: 2 additions & 1 deletion R/shared-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@ CountryDataClass <- R6::R6Class("CountryDataClass",
if (!is.null(self$target_regions)) {
self$target_regions <- countryname(
self$target_regions,
destination = "country.name.en"
destination = "country.name.en",
warn = FALSE
)
if (all(is.na(self$target_regions))) {
stop("No countries found with target names")
Expand Down
75 changes: 43 additions & 32 deletions tests/testthat/test-regional-datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,51 @@ if (identical(Sys.getenv("NOT_CRAN"), "true")) {
download <- getOption("testDownload")
}

# get datasets for testing
sources <- get_available_datasets() %>%
dplyr::filter(.data$type %in%
c("national", "regional")) %>%
dplyr::select(
source = class,
level_1_region, level_2_region, level_3_region
) %>%
tidyr::pivot_longer(
cols = -source,
names_to = "level",
values_to = "regions"
) %>%
dplyr::mutate(
level = stringr::str_split(level, "_"),
level = purrr::map_chr(level, ~ .[2])
) %>%
tidyr::drop_na(regions)

# filter out target datasets
if (!is.null(source_of_interest)) {
sources <- sources %>%
dplyr::filter(source %in% source_of_interest)
test_regions <- TRUE
}else{
test_regions <- FALSE
}
if (!is.null(getOption("testRegions"))) {
test_regions <- getOption("testRegions")
}

# apply tests to each data source in turn
sources %>%
dplyr::rowwise() %>%
dplyr::group_split() %>%
purrr::walk(
~ test_regional_dataset(
source = .$source[[1]],
level = .$level[[1]],
download = download
if (test_regions) {
# get datasets for testing
sources <- get_available_datasets() %>%
dplyr::filter(.data$type %in%
c("national", "regional")) %>%
dplyr::select(
source = class,
level_1_region, level_2_region, level_3_region
) %>%
tidyr::pivot_longer(
cols = -source,
names_to = "level",
values_to = "regions"
) %>%
dplyr::mutate(
level = stringr::str_split(level, "_"),
level = purrr::map_chr(level, ~ .[2])
) %>%
tidyr::drop_na(regions)

# filter out target datasets
if (!is.null(source_of_interest)) {
sources <- sources %>%
dplyr::filter(source %in% source_of_interest)
}

# apply tests to each data source in turn
sources %>%
dplyr::rowwise() %>%
dplyr::group_split() %>%
purrr::walk(
~ test_regional_dataset(
source = .$source[[1]],
level = .$level[[1]],
download = download
)
)
)
}
}

0 comments on commit 845b500

Please sign in to comment.