diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 00000000..271d466e --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,46 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macOS-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-pandoc@v1 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v1 + with: + extra-packages: rcmdcheck + + - uses: r-lib/actions/check-r-package@v1 diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml deleted file mode 100644 index 5e099a4c..00000000 --- a/.github/workflows/check-full.yaml +++ /dev/null @@ -1,272 +0,0 @@ ---- -# Github Actions workflow to check covidregionaldata -name: R-CMD-check - -'on': - push: - branches: - - master - schedule: - - cron: '0 0 * * 1' - pull_request: - branches: - - '*' - workflow_dispatch: - -jobs: - R-CMD-check: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: true - matrix: - config: - - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release'} - - {os: ubuntu-20.04, r: 'oldrel'} - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - with: - r-version: ${{ matrix.config.r }} - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - env: - RHUB_PLATFORM: linux-x86_64-ubuntu-gcc - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - sudo apt-get -y install libudunits2-dev libgdal-dev libqpdf-dev libcurl4-openssl-dev - shell: bash - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Session info - run: | - options(width = 100) - pkgs <- installed.packages()[, "Package"] - sessioninfo::session_info(pkgs, include_base = TRUE) - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_: false - _R_CHECK_DONTTEST_EXAMPLES_: false - _R_CHECK_FORCE_SUGGESTS_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Show testthat output - if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@v2 - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check - - Lint: - runs-on: ubuntu-20.04 - - needs: [R-CMD-check] - - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - env: - RHUB_PLATFORM: linux-x86_64-ubuntu-gcc - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - sudo apt-get -y install libudunits2-dev libgdal-dev libqpdf-dev libcurl4-openssl-dev - shell: bash - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("lintr") - remotes::install_cran("sessioninfo") - remotes::install_local(".") - shell: Rscript {0} - - - name: Session info - run: | - options(width = 100) - pkgs <- installed.packages()[, "Package"] - sessioninfo::session_info(pkgs, include_base = TRUE) - shell: Rscript {0} - - - name: Lint - run: lintr::lint_package() - shell: Rscript {0} - - - test-coverage: - if: github.repository == 'epiforecasts/covidregionaldata' - runs-on: ubuntu-20.04 - - needs: [R-CMD-check] - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - env: - RHUB_PLATFORM: linux-x86_64-ubuntu-gcc - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - sudo apt-get -y install libudunits2-dev libgdal-dev libqpdf-dev libcurl4-openssl-dev - shell: bash - - - name: Install dependencies - run: | - install.packages(c("remotes","sessioninfo")) - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("covr") - shell: Rscript {0} - - - name: Session info - run: | - options(width = 100) - pkgs <- installed.packages()[, "Package"] - sessioninfo::session_info(pkgs, include_base = TRUE) - shell: Rscript {0} - - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} - - - pkgdown: - if: github.ref == 'refs/heads/master' && github.repository == 'epiforecasts/covidregionaldata' - runs-on: macOS-latest - - needs: [R-CMD-check, Lint, test-coverage] - - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - shell: Rscript {0} - - - name: Cache R packages - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: macOS-r-4.0-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: macOS-r-4.0-1- - - - name: Install dependencies - run: | - install.packages(c("remotes", "pkgbuild")) - remotes::install_deps(dependencies = TRUE) - remotes::install_dev("pkgdown") - shell: Rscript {0} - - - name: Install package - run: R CMD INSTALL . - - - name: Deploy package - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - Rscript -e "pkgdown::deploy_to_branch(new_process = FALSE, clean = TRUE)" - shell: bash diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..041ee3c8 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,49 @@ +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +name: lint + +jobs: + lint: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore R package cache + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + install.packages(c("remotes")) + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("lintr") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Lint + run: lintr::lint_package() + shell: Rscript {0} \ No newline at end of file diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 00000000..19db0001 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,59 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + NOT_CRAN: true + steps: + - name: cmdstan env vars + run: | + echo "CMDSTAN_PATH=${HOME}/.cmdstan" >> $GITHUB_ENV + shell: bash + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore R package cache + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + install.packages(c("remotes")) + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("covr") + install.packages("curl") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Test coverage + run: | + options(testRegions = TRUE) + covr::codecov() + shell: Rscript {0} \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index f629aa2a..de3a4b03 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,6 +41,7 @@ export(start_using_memoise) export(stop_using_memoise) export(test_cleaning) export(test_download) +export(test_download_JSON) export(test_processing) export(test_return) importFrom(R6,R6Class) @@ -76,6 +77,7 @@ importFrom(dplyr,pull) importFrom(dplyr,recode) importFrom(dplyr,rename) importFrom(dplyr,select) +importFrom(dplyr,slice_head) importFrom(dplyr,slice_tail) importFrom(dplyr,starts_with) importFrom(dplyr,summarise) @@ -90,9 +92,7 @@ importFrom(httr,POST) importFrom(httr,content) importFrom(httr,status_code) importFrom(jsonlite,fromJSON) -importFrom(lifecycle,deprecate_warn) -importFrom(lifecycle,deprecated) -importFrom(lifecycle,is_present) +importFrom(lifecycle,deprecate_stop) importFrom(lubridate,as_date) importFrom(lubridate,dmy) importFrom(lubridate,dmy_hms) diff --git a/NEWS.md b/NEWS.md index 8062c9c0..942c164e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,11 +12,21 @@ This release is currently under development * Change the data source for Switzerland to draw data from the Swiss Federal Office of Public Health (FOPH) * Updated the package logo to include the newly supported data sets. * Reduced the number of package dependencies (@bisaloo and @RichardMN) +* Added tests for JSON download code (@RichardMN). ## Bug fixes - Fixed a bug in `fill_empty_dates_with_na()` caused by changes made in version `1.2.0` of `tidyr`. - Fixed a bug in the data sourced from Germany so that instead of treating it as a line list of individuals it is treated as a relatively finely resolved count data which needs to be summed up (by @sbfnk). +- Fixed a bug in the Vietnam class due to `stringr` ([#448](https://github.com/epiforecasts/covidregionaldata/pull/448) by @RichardMN). +- Fixed a bug with the Netherlands class were the lack of Hospitalisation data in the source was causing the class to fail ([#446](https://github.com/epiforecasts/covidregionaldata/pull/446) by @RichardMN). + +## Depreciations + +- `get_interventions_data()` has been depreciated and removed. +- `get_info_covidregionaldata()` has been depreciated and removed. +- The `country` argument to `get_national_data()` has been depreciated and removed. It's functionality can be replicated using the `countries` argument. +- `get_linelist()` has been updated to fail on use vs warn on use and will be removed from future versions of the package. # covidregionaldata 0.9.2 diff --git a/R/Netherlands.R b/R/Netherlands.R index a4afdf05..5d9f4f10 100644 --- a/R/Netherlands.R +++ b/R/Netherlands.R @@ -38,7 +38,7 @@ Netherlands <- R6::R6Class("Netherlands", ), # nolint end #' @field source_data_cols existing columns within the raw data - source_data_cols = c("cases_new", "deaths_new", "hosp_new"), + source_data_cols = c("cases_new", "deaths_new"), #' @field source_text Plain text description of the source of the data source_text = "National Institute for Public Health and the Environment (RIVM), Netherlands", # nolint #' @field source_url Website address for explanation/introduction of the @@ -60,7 +60,6 @@ Netherlands <- R6::R6Class("Netherlands", mutate( Date_of_publication = ymd(.data$Date_of_publication), Total_reported = as.double(.data$Total_reported), - Hospital_admission = as.double(.data$Hospital_admission), Deceased = as.double(.data$Deceased), level_1_region_code = sub("[a-z].*-", "", .data$Province), level_1_region_code = paste0( @@ -74,8 +73,8 @@ Netherlands <- R6::R6Class("Netherlands", level_2_region = .data$Municipality_name, level_2_region_code = .data$Municipality_code, cases_new = .data$Total_reported, - deaths_new = .data$Deceased, - hosp_new = .data$Hospital_admission + deaths_new = .data$Deceased #, + #hosp_new = .data$Hospital_admission ) }, diff --git a/R/get_info_covidregionaldata.R b/R/get_info_covidregionaldata.R deleted file mode 100644 index 632d77c1..00000000 --- a/R/get_info_covidregionaldata.R +++ /dev/null @@ -1,18 +0,0 @@ -#' Get available datasets -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function is deprecated. Please use `get_available_datasets()` instead. -#' -#' @keywords internal -#' @importFrom lifecycle deprecate_warn -get_info_covidregionaldata <- function() { - deprecate_warn( - when = "0.9.0", - what = "covidregionaldata::get_info_covidregionaldata()", - with = "covidregionaldata::get_available_datasets()" - ) - data <- get_available_datasets() - return(data) -} diff --git a/R/get_interventions_data.R b/R/get_interventions_data.R deleted file mode 100644 index 37dfa4cc..00000000 --- a/R/get_interventions_data.R +++ /dev/null @@ -1,58 +0,0 @@ -#' Get ACAPS Government Interventions dataset -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' Downloads the ACAPS Government Interventions dataset. -#' This function is deprecated: data are no longer updated as of December 2020. -#' -#' Over 100 alternative datasets are available, covering government -#' interventions worldwide. Several include subnational level policy. -#' See: https://supertracker.spi.ox.ac.uk/policy-trackers/ -#' -#' @return a dataframe of government interventions up to Dec 2020 from ACAPS -#' @source \url{https://www.acaps.org/covid-19-government-measures-dataset} -#' @author Paul Campbell @paulcampbell91 -#' -#' @keywords internal -#' -#' @importFrom readxl read_excel -#' @importFrom dplyr mutate -#' @importFrom utils download.file -#' @importFrom lifecycle deprecate_warn -#' -get_interventions_data <- function() { - deprecate_warn( - when = "0.9.0", - what = "covidregionaldata::get_interventions_data()", - details = c( - "The ACAPS data source stopped updating in December 2020.", - "Over 100 alternative data sets are available at:", - "https://supertracker.spi.ox.ac.uk/policy-trackers/" - ) - ) - - base_url <- "https://www.acaps.org/sites/acaps/files/resources/files/acaps_covid19_government_measures_dataset_0.xlsx" # nolint - temp <- tempdir() - filename <- "interventions.xlsx" - download.file(base_url, - destfile = file.path(temp, filename), - mode = "wb", quiet = TRUE - ) - # Read in data and correct excel dates - data <- suppressWarnings(read_excel(file.path(temp, filename), - sheet = "Dataset", - col_types = "text" - )) %>% - mutate( - ENTRY_DATE = as.Date((as.numeric(.data$ENTRY_DATE) - 2), - origin = as.Date("1900-01-01") - ), - DATE_IMPLEMENTED = as.Date((as.numeric(.data$DATE_IMPLEMENTED) - 2), - origin = as.Date("1900-01-01") - ) - ) - names(data) <- tolower(names(data)) - - return(data) -} diff --git a/R/get_linelist.R b/R/get_linelist.R index 6b5f48ca..2f2d11f8 100644 --- a/R/get_linelist.R +++ b/R/get_linelist.R @@ -21,7 +21,7 @@ #' #' @keywords internal #' -#' @importFrom lifecycle deprecate_warn +#' @importFrom lifecycle deprecate_stop #' @importFrom dplyr if_else select mutate filter #' @importFrom lubridate dmy #' @importFrom utils download.file untar @@ -35,7 +35,7 @@ #' } #' get_linelist <- function(clean = TRUE, report_delay_only = FALSE) { - deprecate_warn( + deprecate_stop( when = "0.9.0", what = "covidregionaldata::get_linelist()", details = c( diff --git a/R/get_national_data.R b/R/get_national_data.R index 00cde97f..0645435c 100644 --- a/R/get_national_data.R +++ b/R/get_national_data.R @@ -12,15 +12,12 @@ #' #' @param countries A character vector specifying country names of interest. #' Used to filter the data. -#' @param country `r lifecycle::badge("deprecated")` A character string -#' specifying a country to filter for. #' @param source A character string specifying the data source (not case #' dependent). Defaults to WHO (the World Health Organisation). See #' `get_available_datasets("national")` for all options. #' @return A tibble with data related to cases, deaths, hospitalisations, #' recoveries and testing. #' @inheritParams get_regional_data -#' @importFrom lifecycle deprecated is_present deprecate_warn #' @family interface #' @seealso [WHO()], [ECDC()], [JHU()], [Google()] #' @export @@ -54,16 +51,7 @@ #' } get_national_data <- function(countries, source = "who", level = "1", totals = FALSE, steps = FALSE, class = FALSE, verbose = TRUE, - country = deprecated(), ...) { - if (is_present(country)) { - deprecate_warn( - "0.9.0", - "covidregionaldata::get_national_data(country = )", - "covidregionaldata::get_national_data(countries = )" - ) - countries <- country - } # check data availability and initiate country class if available nation_class <- initialise_dataclass( diff --git a/R/get_regional_data.R b/R/get_regional_data.R index bf533566..34ae99a0 100644 --- a/R/get_regional_data.R +++ b/R/get_regional_data.R @@ -13,16 +13,10 @@ #' @param country A character string specifying the country to get data from. #' Not case dependent. Name should be the English name. For a list of #' options use `get_available_datasets()`. -#' @param include_level_2_regions `r lifecycle::badge("deprecated")` Boolean. If TRUE, returns data stratified by -#' level 2 regions. If FALSE, stratified by Level 1. Note that Level 2 region -#' data is not always available. In these cases the user will get a warning -#' and the Level 1 data will be returned. -#' @param localise_regions `r lifecycle::badge("deprecated")` Logical, defaults to TRUE. Should region names be localised. #' @inheritParams return_data #' @inheritParams initialise_dataclass #' @return A tibble with data related to cases, deaths, hospitalisations, #' recoveries and testing stratified by regions within the given country. -#' @importFrom lifecycle deprecated is_present deprecate_warn #' @family interface #' @seealso [Italy()], [UK()] #' @export @@ -47,28 +41,7 @@ get_regional_data <- function(country, level = "1", totals = FALSE, localise = TRUE, steps = FALSE, class = FALSE, verbose = TRUE, regions, - include_level_2_regions = deprecated(), - localise_regions = deprecated(), ...) { - if (is_present(include_level_2_regions)) { - deprecate_warn( - "0.9.0", - "covidregionaldata::get_regional_data(include_level_2_regions = )", "covidregionaldata::get_regional_data(level = )" - ) - if (include_level_2_regions) { - level <- "1" - } else { - level <- "2" - } - } - - if (is_present(localise_regions)) { - deprecate_warn( - "0.9.0", - "covidregionaldata::get_regional_data(localise_regions = )", "covidregionaldata::get_regional_data(localise = )" - ) - localise <- localise_regions - } # check data availability and initiate country class if available region_class <- initialise_dataclass( diff --git a/R/shared-methods.R b/R/shared-methods.R index 0433831e..8974d8ac 100644 --- a/R/shared-methods.R +++ b/R/shared-methods.R @@ -638,10 +638,12 @@ CountryDataClass <- R6::R6Class("CountryDataClass", } if (!is.null(self$target_regions)) { - self$target_regions <- countryname( - self$target_regions, - destination = "country.name.en", - warn = FALSE + self$target_regions <- suppressWarnings( + countryname( + self$target_regions, + destination = "country.name.en", + warn = FALSE + ) ) if (all(is.na(self$target_regions))) { stop("No countries found with target names") diff --git a/R/test-DataClass.R b/R/test-DataClass.R index 3f4c3695..280eb3ae 100644 --- a/R/test-DataClass.R +++ b/R/test-DataClass.R @@ -121,6 +121,47 @@ test_download <- function(DataClass_obj, download, snapshot_path) { } } + +#' Test download method for JSON files works correctly +#' @description Test data can be downloaded if `download = TRUE`, or a requested +#' snapshot file is not found, and store a snap shot in the `snapshot_dir`. If +#' an existing snapshot file is found then load this data to use in future tests +#' @param DataClass_obj The R6Class object to perform checks on. +#' Must be a `DataClass` or `DataClass` child object. +#' @param download Logical check to download or use a snapshot of the data +#' @param snapshot_path character_array the path to save the downloaded +#' snapshot to. +#' @importFrom purrr map walk +#' @importFrom dplyr slice_head +#' @family tests +#' @concept tests +#' @export +test_download_JSON <- function(DataClass_obj, download, snapshot_path) { + if (!file.exists(snapshot_path)) { + download <- TRUE + } + if (download) { + testthat::test_that( + paste0(DataClass_obj$data_name, " downloads sucessfully"), + { + DataClass_obj$download_JSON() + walk(DataClass_obj$data$raw, function(data) { + testthat::expect_true(length(data) > 0) + testthat::expect_false(is.null(data)) + }) + } + ) + DataClass_obj$data$raw <- map(DataClass_obj$data$raw, + slice_head, + n = 2 + ) + + saveRDS(DataClass_obj$data$raw, snapshot_path) + } else { + DataClass_obj$data$raw <- readRDS(snapshot_path) + } +} + #' Test clean method works correctly #' @description Test data can be cleaned properly. The clean method is invoked #' to generate clean data. This data is checked to ensure it is a data.frame, diff --git a/README.Rmd b/README.Rmd index a42bda15..04b68018 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,7 +13,7 @@ knitr::opts_chunk$set( # Subnational data for the COVID-19 outbreak -[![R-CMD-check](https://github.com/epiforecasts/covidregionaldata/workflows/R-CMD-check/badge.svg)](https://github.com/epiforecasts/covidregionaldata/actions) [![Codecov test coverage](https://codecov.io/gh/epiforecasts/covidregionaldata/branch/master/graph/badge.svg)](https://codecov.io/gh/epiforecasts/covidregionaldata?branch=master) [![Data status](https://img.shields.io/badge/Data-status-lightblue.svg?style=flat)](https://epiforecasts.io/covidregionaldata/articles/supported-countries.html) [![metacran downloads](http://cranlogs.r-pkg.org/badges/grand-total/covidregionaldata?color=ff69b4)](https://cran.r-project.org/package=covidregionaldata) + [![R-CMD-check](https://github.com/epiforecasts/covidregionaldata/workflows/R-CMD-check/badge.svg)](https://github.com/epiforecasts/covidregionaldata/actions) [![Codecov test coverage](https://codecov.io/gh/epiforecasts/covidregionaldata/branch/master/graph/badge.svg)](https://codecov.io/gh/epiforecasts/covidregionaldata?branch=master) [![Data status](https://img.shields.io/badge/Data-status-lightblue.svg?style=flat)](https://epiforecasts.io/covidregionaldata/articles/supported-countries.html) [![metacran downloads](http://cranlogs.r-pkg.org/badges/grand-total/covidregionaldata?color=ff69b4)](https://cran.r-project.org/package=covidregionaldata) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/epiforecasts/covidregionaldata/blob/master/LICENSE.md/) [![GitHub contributors](https://img.shields.io/github/contributors/epiforecasts/covidregionaldata)](https://github.com/epiforecasts/covidregionaldata/graphs/contributors) [![Discord](https://img.shields.io/discord/864828485981306890?logo=Discord)](https://discord.gg/9YPDDADVt3) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-yellow.svg)](https://makeapullrequest.com/) [![GitHub commits](https://img.shields.io/github/commits-since/epiforecasts/covidregionaldata/0.9.2.svg?color=orange)](https://github.com/epiforecasts/covidregionaldata/commit/master/) diff --git a/data/all_country_data.rda b/data/all_country_data.rda index f305e8ba..961dfecf 100644 Binary files a/data/all_country_data.rda and b/data/all_country_data.rda differ diff --git a/man/expect_clean_cols.Rd b/man/expect_clean_cols.Rd index 4cbfc03e..c5165fef 100644 --- a/man/expect_clean_cols.Rd +++ b/man/expect_clean_cols.Rd @@ -20,6 +20,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_columns_contain_data}()}, \code{\link{expect_processed_cols}()}, \code{\link{test_cleaning}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_download}()}, \code{\link{test_processing}()}, \code{\link{test_return}()} diff --git a/man/expect_columns_contain_data.Rd b/man/expect_columns_contain_data.Rd index 75439ae5..3c97b657 100644 --- a/man/expect_columns_contain_data.Rd +++ b/man/expect_columns_contain_data.Rd @@ -19,6 +19,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_clean_cols}()}, \code{\link{expect_processed_cols}()}, \code{\link{test_cleaning}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_download}()}, \code{\link{test_processing}()}, \code{\link{test_return}()} diff --git a/man/expect_processed_cols.Rd b/man/expect_processed_cols.Rd index ad96cf9e..ae79949d 100644 --- a/man/expect_processed_cols.Rd +++ b/man/expect_processed_cols.Rd @@ -23,6 +23,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_clean_cols}()}, \code{\link{expect_columns_contain_data}()}, \code{\link{test_cleaning}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_download}()}, \code{\link{test_processing}()}, \code{\link{test_return}()} diff --git a/man/get_info_covidregionaldata.Rd b/man/get_info_covidregionaldata.Rd deleted file mode 100644 index f656ae0c..00000000 --- a/man/get_info_covidregionaldata.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_info_covidregionaldata.R -\name{get_info_covidregionaldata} -\alias{get_info_covidregionaldata} -\title{Get available datasets} -\usage{ -get_info_covidregionaldata() -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function is deprecated. Please use \code{get_available_datasets()} instead. -} -\keyword{internal} diff --git a/man/get_interventions_data.Rd b/man/get_interventions_data.Rd deleted file mode 100644 index f8e8c870..00000000 --- a/man/get_interventions_data.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_interventions_data.R -\name{get_interventions_data} -\alias{get_interventions_data} -\title{Get ACAPS Government Interventions dataset} -\source{ -\url{https://www.acaps.org/covid-19-government-measures-dataset} -} -\usage{ -get_interventions_data() -} -\value{ -a dataframe of government interventions up to Dec 2020 from ACAPS -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -Downloads the ACAPS Government Interventions dataset. -This function is deprecated: data are no longer updated as of December 2020. - -Over 100 alternative datasets are available, covering government -interventions worldwide. Several include subnational level policy. -See: https://supertracker.spi.ox.ac.uk/policy-trackers/ -} -\author{ -Paul Campbell @paulcampbell91 -} -\keyword{internal} diff --git a/man/get_national_data.Rd b/man/get_national_data.Rd index 098ca65b..9b19b25a 100644 --- a/man/get_national_data.Rd +++ b/man/get_national_data.Rd @@ -12,7 +12,6 @@ get_national_data( steps = FALSE, class = FALSE, verbose = TRUE, - country = deprecated(), ... ) } @@ -43,9 +42,6 @@ Overrides \code{steps}.} \item{verbose}{Logical, defaults to \code{TRUE}. Should verbose processing messages and warnings be returned.} -\item{country}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} A character string -specifying a country to filter for.} - \item{...}{Additional arguments to pass to class specific functionality.} } \value{ diff --git a/man/get_regional_data.Rd b/man/get_regional_data.Rd index de52bb4f..e825493b 100644 --- a/man/get_regional_data.Rd +++ b/man/get_regional_data.Rd @@ -13,8 +13,6 @@ get_regional_data( class = FALSE, verbose = TRUE, regions, - include_level_2_regions = deprecated(), - localise_regions = deprecated(), ... ) } @@ -47,13 +45,6 @@ messages and warnings be returned.} \item{regions}{A character vector of target regions to be assigned to the \code{target_regions} field and used to filter the returned data.} -\item{include_level_2_regions}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Boolean. If TRUE, returns data stratified by -level 2 regions. If FALSE, stratified by Level 1. Note that Level 2 region -data is not always available. In these cases the user will get a warning -and the Level 1 data will be returned.} - -\item{localise_regions}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Logical, defaults to TRUE. Should region names be localised.} - \item{...}{Additional arguments to pass to class specific functionality.} } \value{ diff --git a/man/test_cleaning.Rd b/man/test_cleaning.Rd index c7f7414d..4194c5a0 100644 --- a/man/test_cleaning.Rd +++ b/man/test_cleaning.Rd @@ -22,6 +22,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_clean_cols}()}, \code{\link{expect_columns_contain_data}()}, \code{\link{expect_processed_cols}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_download}()}, \code{\link{test_processing}()}, \code{\link{test_return}()} diff --git a/man/test_download.Rd b/man/test_download.Rd index fb9c32ea..1cd01985 100644 --- a/man/test_download.Rd +++ b/man/test_download.Rd @@ -26,6 +26,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_columns_contain_data}()}, \code{\link{expect_processed_cols}()}, \code{\link{test_cleaning}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_processing}()}, \code{\link{test_return}()} } diff --git a/man/test_download_JSON.Rd b/man/test_download_JSON.Rd new file mode 100644 index 00000000..8d05564f --- /dev/null +++ b/man/test_download_JSON.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/test-DataClass.R +\name{test_download_JSON} +\alias{test_download_JSON} +\title{Test download method for JSON files works correctly} +\usage{ +test_download_JSON(DataClass_obj, download, snapshot_path) +} +\arguments{ +\item{DataClass_obj}{The R6Class object to perform checks on. +Must be a \code{DataClass} or \code{DataClass} child object.} + +\item{download}{Logical check to download or use a snapshot of the data} + +\item{snapshot_path}{character_array the path to save the downloaded +snapshot to.} +} +\description{ +Test data can be downloaded if \code{download = TRUE}, or a requested +snapshot file is not found, and store a snap shot in the \code{snapshot_dir}. If +an existing snapshot file is found then load this data to use in future tests +} +\seealso{ +Functions used for testing data is cleaned and processed correctly +\code{\link{expect_clean_cols}()}, +\code{\link{expect_columns_contain_data}()}, +\code{\link{expect_processed_cols}()}, +\code{\link{test_cleaning}()}, +\code{\link{test_download}()}, +\code{\link{test_processing}()}, +\code{\link{test_return}()} +} +\concept{tests} diff --git a/man/test_processing.Rd b/man/test_processing.Rd index 6b7ebb31..3b698d3c 100644 --- a/man/test_processing.Rd +++ b/man/test_processing.Rd @@ -25,6 +25,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_columns_contain_data}()}, \code{\link{expect_processed_cols}()}, \code{\link{test_cleaning}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_download}()}, \code{\link{test_return}()} } diff --git a/man/test_return.Rd b/man/test_return.Rd index 69715cf9..02f66f34 100644 --- a/man/test_return.Rd +++ b/man/test_return.Rd @@ -22,6 +22,7 @@ Functions used for testing data is cleaned and processed correctly \code{\link{expect_columns_contain_data}()}, \code{\link{expect_processed_cols}()}, \code{\link{test_cleaning}()}, +\code{\link{test_download_JSON}()}, \code{\link{test_download}()}, \code{\link{test_processing}()} } diff --git a/tests/testthat/custom_data/Netherlands_level_1.rds b/tests/testthat/custom_data/Netherlands_level_1.rds index ceff2ca3..262a43e3 100644 Binary files a/tests/testthat/custom_data/Netherlands_level_1.rds and b/tests/testthat/custom_data/Netherlands_level_1.rds differ diff --git a/tests/testthat/custom_data/Netherlands_level_2.rds b/tests/testthat/custom_data/Netherlands_level_2.rds index ceff2ca3..262a43e3 100644 Binary files a/tests/testthat/custom_data/Netherlands_level_2.rds and b/tests/testthat/custom_data/Netherlands_level_2.rds differ diff --git a/tests/testthat/custom_data/mtcars.json b/tests/testthat/custom_data/mtcars.json new file mode 100644 index 00000000..bd79a009 --- /dev/null +++ b/tests/testthat/custom_data/mtcars.json @@ -0,0 +1 @@ +[{"mpg":21,"cyl":6,"disp":160,"hp":110,"drat":3.9,"wt":2.62,"qsec":16.46,"vs":0,"am":1,"gear":4,"carb":4},{"mpg":21,"cyl":6,"disp":160,"hp":110,"drat":3.9,"wt":2.875,"qsec":17.02,"vs":0,"am":1,"gear":4,"carb":4},{"mpg":22.8,"cyl":4,"disp":108,"hp":93,"drat":3.85,"wt":2.32,"qsec":18.61,"vs":1,"am":1,"gear":4,"carb":1},{"mpg":21.4,"cyl":6,"disp":258,"hp":110,"drat":3.08,"wt":3.215,"qsec":19.44,"vs":1,"am":0,"gear":3,"carb":1},{"mpg":18.7,"cyl":8,"disp":360,"hp":175,"drat":3.15,"wt":3.44,"qsec":17.02,"vs":0,"am":0,"gear":3,"carb":2},{"mpg":18.1,"cyl":6,"disp":225,"hp":105,"drat":2.76,"wt":3.46,"qsec":20.22,"vs":1,"am":0,"gear":3,"carb":1}] diff --git a/tests/testthat/test-get_info_covidregionaldata.R b/tests/testthat/test-get_info_covidregionaldata.R deleted file mode 100644 index 1ef53bcd..00000000 --- a/tests/testthat/test-get_info_covidregionaldata.R +++ /dev/null @@ -1,6 +0,0 @@ -test_that("get_info_covidregionaldata works as expected", { - expect_warning(get_info_covidregionaldata()) - expect_s3_class( - suppressWarnings(get_info_covidregionaldata()), "data.frame" - ) -}) diff --git a/tests/testthat/test-get_national_data.R b/tests/testthat/test-get_national_data.R index 4caed1a2..de83e30e 100644 --- a/tests/testthat/test-get_national_data.R +++ b/tests/testthat/test-get_national_data.R @@ -26,10 +26,6 @@ test_get_national_data <- function(source) { countries = "rwfwf", source = source, verbose = FALSE )) - expect_warning(get_national_data( - country = "Zimbabwe", source = source, - verbose = FALSE - )) expect_equal( true_steps, get_national_data(source = source, steps = TRUE, verbose = FALSE) diff --git a/tests/testthat/test-get_regional_data.R b/tests/testthat/test-get_regional_data.R index ec826ad6..1cc59b90 100644 --- a/tests/testthat/test-get_regional_data.R +++ b/tests/testthat/test-get_regional_data.R @@ -46,19 +46,6 @@ test_get_regional_data <- function(level) { verbose = FALSE ) ) - # test depreciated args - if (level == "2") { - expect_warning(get_regional_data("mexico", - level = level, - include_level_2_regions = TRUE, verbose = FALSE - )) - expect_warning( - get_regional_data("mexico", - localise_regions = TRUE, - verbose = FALSE - ) - ) - } }) } diff --git a/tests/testthat/test-json_reader.R b/tests/testthat/test-json_reader.R new file mode 100644 index 00000000..84b46284 --- /dev/null +++ b/tests/testthat/test-json_reader.R @@ -0,0 +1,36 @@ +test_path <- "custom_data/mtcars.json" +target <- tibble::as_tibble(head(mtcars)) + +test_that("json_reader can read in a simple dataset", { + test <- json_reader(test_path) + expect_s3_class(test, "tbl_df") + expect_equal( + colnames(test), + colnames(target) + ) + attributes(test)$spec <- NULL + attributes(test)$problems <- NULL + expect_equal( + test, + target + ) +}) + +test_that("json_reader verbosity is controlled as expected", { + expect_gte( + length(capture.output(tmp <- json_reader(test_path, verbose = TRUE), + type = "message" + )), + 1 + ) + expect_equal( + length(capture.output(tmp <- json_reader(test_path, verbose = FALSE), + type = "message" + )), + 0 + ) +}) + +test_that("json_reader fails as expected when given a file that doesn't exist", { + expect_error(json_reader("nonsense.json", verbose = FALSE)) +})