```
Now we have the data we can create plots, for example the time-series of
@@ -212,7 +200,7 @@ uk_nots %>%
See `get_available_datasets()` for supported regions and subregional
-levels. To view what datasets we currently have subnationaldata for,
+levels. To view what datasets we currently have subnational data for,
along with their current status, check the [supported
countries](https://epiforecasts.io/covidregionaldata/articles/supported-countries.html)
page or build the [supported countries
@@ -233,9 +221,8 @@ using the following,
#>
#> To cite covidregionaldata in publications use:
#>
- #> Joseph Palmer, Katharine Sherratt, Richard Martin-Nielsen, Jonnie
- #> Bevan, Hamish Gibbs, Sebastian Funk and Sam Abbott (2021).
- #> covidregionaldata: Subnational data for COVID-19 epidemiology, DOI:
+ #> Joseph Palmer, Katharine Sherratt, Richard Martin-Nielsen, Jonnie Bevan, Hamish Gibbs, Sebastian
+ #> Funk and Sam Abbott (2021). covidregionaldata: Subnational data for COVID-19 epidemiology, DOI:
#> 10.21105/joss.03290
#>
#> A BibTeX entry for LaTeX users is
diff --git a/_pkgdown.yml b/_pkgdown.yml
index da51ab70..9076ed31 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -1,8 +1,9 @@
url: https://epiforecasts.io/covidregionaldata/
template:
bootstrap: 5
+ package: preferably
params:
- bootswatch: lumen
+ toggle: manual
docsearch:
api_key: 721a43acf6af66699c04bd8b2af75ff1
index_name: epiforecasts
diff --git a/cran-comments.md b/cran-comments.md
index dbf1a0cb..c13c381e 100644
--- a/cran-comments.md
+++ b/cran-comments.md
@@ -1,9 +1,8 @@
## Test environments
-* local R installation, R 4.1.0
-* ubuntu 16.04 (on travis-ci), R 4.1.0
+* local R installation, R 4.1.2
+* ubuntu 16.04 (on travis-ci), R 4.1.2
* win-builder (devel)
## R CMD check results
0 errors | 0 warnings | 0 note
-
diff --git a/data-raw/colombia_codes.R b/data-raw/colombia_codes.R
index 8cb8792b..8c6202a5 100644
--- a/data-raw/colombia_codes.R
+++ b/data-raw/colombia_codes.R
@@ -22,7 +22,7 @@ level_1_region <- read_html(co_iso) %>%
html_text()
level_1_region <- level_1_region[1:33]
-colombia_codes <- data.frame(
+colombia_departments <- data.frame(
level_1_region_code,
level_1_region,
stringsAsFactors = FALSE
@@ -37,7 +37,7 @@ colombia_codes <- data.frame(
replacements <- list(
"Distrito Capital De Bogota" = "Bogota"
)
-colombia_codes <- colombia_codes %>%
+colombia_departments <- colombia_departments %>%
mutate(
level_1_region = ifelse(level_1_region %in% names(replacements),
replacements[level_1_region],
@@ -46,5 +46,47 @@ colombia_codes <- colombia_codes %>%
level_1_region = as.character(level_1_region)
)
+# Download list of municipalities and codes
+#
+
+colombia_municipalities_sheet <- download_excel(
+ "https://www.dane.gov.co/files/censo2005/provincias/subregiones.xls",
+ "colombia_municipalities.xls",
+ verbose = TRUE,
+ transpose = FALSE,
+ sheet = "Hoja1"
+)
+ colombia_municipalities <- colombia_municipalities_sheet %>%
+ select(level_2_region = NOM_MPIO,
+ level_2_region_code = DPTOC_MPIO,
+ level_1_region = NOM_DEPTO) %>%
+ mutate(
+ level_1_region = stri_trans_general(level_1_region, "latin-ascii"),
+ level_1_region = stri_trim_both(level_1_region),
+ level_1_region = stringr::str_to_title(level_1_region),
+ level_1_region =
+ str_replace_all(.data$level_1_region,
+ c(" D.c." = "",
+ "Archipielago De San Andres"
+ = "San Andres, Providencia Y Santa Catalina",
+ "Norte Santander" = "Norte De Santander"
+ )
+ ),
+ level_2_region = stri_trans_general(level_2_region, "latin-ascii"),
+ level_2_region = stri_trim_both(level_2_region),
+ level_2_region =
+ str_replace_all(.data$level_2_region,
+ c(" D.C." = ""
+ )
+ ),
+ level_2_region = stringr::str_to_title(level_2_region),
+ )
+
+
+# anti_join(colombia_municipalities, colombia_departments, by=c("level_1_region"))
+colombia_codes <- left_join(colombia_municipalities,
+ colombia_departments,
+ by=c("level_1_region"))
+
# update package region_codes
usethis::use_data(colombia_codes, overwrite = TRUE)
diff --git a/data-raw/vietnam_codes.R b/data-raw/vietnam_codes.R
index bdba31fc..baec3f9f 100644
--- a/data-raw/vietnam_codes.R
+++ b/data-raw/vietnam_codes.R
@@ -14,7 +14,7 @@ library(tibble)
vn_iso <- "https://en.wikipedia.org/wiki/ISO_3166-2:VN"
level_1_region_df <- read_html(vn_iso) %>%
- html_element(css="table.wikitable:nth-child(11)") %>%
+ html_element(css = "table.wikitable:nth-child(11)") %>%
html_table()
vietnam_codes <- data.frame(
@@ -25,7 +25,7 @@ vietnam_codes <- data.frame(
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_replace_all(level_1_region, '\\(.*\\)|-| ', ''),
+ level_1_region = str_replace_all(level_1_region, "\\(.*\\)|-| ", ""),
level_1_region = str_to_title(level_1_region)
)
diff --git a/data/colombia_codes.rda b/data/colombia_codes.rda
index efc435d6..81666ce6 100644
Binary files a/data/colombia_codes.rda and b/data/colombia_codes.rda differ
diff --git a/inst/WORDLIST b/inst/WORDLIST
index abf97ef6..1ea85c64 100644
--- a/inst/WORDLIST
+++ b/inst/WORDLIST
@@ -29,6 +29,7 @@ COVID
covidregionaldata
cre
CSSE
+csv
ctb
DataClass
datahub
@@ -128,6 +129,7 @@ rlang
rmarkdown
Roxygen
RoxygenNote
+RSocrata
rvest
RVIM
rworldmap
@@ -140,6 +142,7 @@ seperate
shapefiles
sherratt
Sherratt
+Socrata
sophie
SouthAfrica
spi
diff --git a/inst/github_workflow_template.yaml b/inst/github_workflow_template.yaml
index c1bb734f..f2c17a5e 100644
--- a/inst/github_workflow_template.yaml
+++ b/inst/github_workflow_template.yaml
@@ -7,34 +7,18 @@ name: _SOURCE_
jobs:
_SOURCE_:
- runs-on: macOS-latest
+ runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+ steps:
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}
+ - uses: r-lib/actions/setup-r@v2
- - name: Cache R packages
- uses: actions/cache@v2
+ - uses: r-lib/actions/setup-r-dependencies@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)
- install.packages("devtools")
- shell: Rscript {0}
+ extra-packages: devtools
- name: Install package
run: R CMD INSTALL .
diff --git a/man/Colombia.Rd b/man/Colombia.Rd
index d1f88abb..f8228ff5 100644
--- a/man/Colombia.Rd
+++ b/man/Colombia.Rd
@@ -4,7 +4,7 @@
\alias{Colombia}
\title{Colombia Class for downloading, cleaning and processing notification data}
\source{
-\url{https://github.com/danielcs88/colombia_covid-19/}
+\url{https://www.datos.gov.co/Salud-y-Protecci-n-Social/Casos-positivos-de-COVID-19-en-Colombia/gt2j-8ykr}
}
\description{
Information for downloading, cleaning
@@ -70,7 +70,9 @@ data}
\subsection{Public methods}{
\itemize{
\item \href{#method-set_region_codes}{\code{Colombia$set_region_codes()}}
+\item \href{#method-download}{\code{Colombia$download()}}
\item \href{#method-clean_common}{\code{Colombia$clean_common()}}
+\item \href{#method-clean_level_1}{\code{Colombia$clean_level_1()}}
\item \href{#method-clone}{\code{Colombia$clone()}}
}
}
@@ -79,7 +81,6 @@ data}
\itemize{
\item \out{}\href{../../covidregionaldata/html/DataClass.html#method-available_regions}{\code{covidregionaldata::DataClass$available_regions()}}\out{}
\item \out{}\href{../../covidregionaldata/html/DataClass.html#method-clean}{\code{covidregionaldata::DataClass$clean()}}\out{}
-\item \out{}\href{../../covidregionaldata/html/DataClass.html#method-download}{\code{covidregionaldata::DataClass$download()}}\out{}
\item \out{}\href{../../covidregionaldata/html/DataClass.html#method-download_JSON}{\code{covidregionaldata::DataClass$download_JSON()}}\out{}
\item \out{}\href{../../covidregionaldata/html/DataClass.html#method-filter}{\code{covidregionaldata::DataClass$filter()}}\out{}
\item \out{}\href{../../covidregionaldata/html/DataClass.html#method-get}{\code{covidregionaldata::DataClass$get()}}\out{}
@@ -100,16 +101,41 @@ Set up a table of region codes for clean data
\if{html}{\out{}}\preformatted{Colombia$set_region_codes()}\if{html}{\out{
}}
}
+}
+\if{html}{\out{
}}
+\if{html}{\out{}}
+\if{latex}{\out{\hypertarget{method-download}{}}}
+\subsection{Method \code{download()}}{
+Colombia specific download using Socrata API
+This uses the \code{RSocrata} package if it is installed or downloads
+a much larger csv file if that package is not available.
+\subsection{Usage}{
+\if{html}{\out{}}\preformatted{Colombia$download()}\if{html}{\out{
}}
+}
+
}
\if{html}{\out{
}}
\if{html}{\out{}}
\if{latex}{\out{\hypertarget{method-clean_common}{}}}
\subsection{Method \code{clean_common()}}{
-Colombia specific state level data cleaning
+Colombia specific data cleaning
\subsection{Usage}{
\if{html}{\out{}}\preformatted{Colombia$clean_common()}\if{html}{\out{
}}
}
+}
+\if{html}{\out{
}}
+\if{html}{\out{}}
+\if{latex}{\out{\hypertarget{method-clean_level_1}{}}}
+\subsection{Method \code{clean_level_1()}}{
+Colombia Specific Department Level Data Cleaning
+
+Aggregates data to the level 1 (department) regional level. Data is
+provided by the source at the level 2 (municipality) regional level.
+\subsection{Usage}{
+\if{html}{\out{}}\preformatted{Colombia$clean_level_1()}\if{html}{\out{
}}
+}
+
}
\if{html}{\out{
}}
\if{html}{\out{}}
diff --git a/man/Estonia.Rd b/man/Estonia.Rd
index b7a5f9c1..a9a5607e 100644
--- a/man/Estonia.Rd
+++ b/man/Estonia.Rd
@@ -36,8 +36,7 @@ Subnational data sources
\code{\link{SouthAfrica}},
\code{\link{Switzerland}},
\code{\link{UK}},
-\code{\link{USA}},
-\code{\link{Vietnam}}
+\code{\link{USA}}
}
\concept{dataset}
\concept{subnational}
diff --git a/man/all_country_data.Rd b/man/all_country_data.Rd
index b81bf36f..052c4727 100644
--- a/man/all_country_data.Rd
+++ b/man/all_country_data.Rd
@@ -6,7 +6,7 @@
\title{Table of available datasets along with level and other information.
Rendered from the individual R6 class objects included in this package.}
\format{
-An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 24 rows and 10 columns.
+An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 23 rows and 10 columns.
}
\usage{
all_country_data
diff --git a/man/colombia_codes.Rd b/man/colombia_codes.Rd
index 2292ad7a..40ff0e81 100644
--- a/man/colombia_codes.Rd
+++ b/man/colombia_codes.Rd
@@ -5,7 +5,7 @@
\alias{colombia_codes}
\title{Region Codes for Colombia Dataset.}
\format{
-An object of class \code{data.frame} with 33 rows and 2 columns.
+An object of class \code{data.frame} with 1119 rows and 4 columns.
}
\usage{
colombia_codes
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/Colombia_level_1.rds b/tests/testthat/custom_data/Colombia_level_1.rds
index 7f131bb8..07aee3a3 100644
Binary files a/tests/testthat/custom_data/Colombia_level_1.rds and b/tests/testthat/custom_data/Colombia_level_1.rds differ
diff --git a/tests/testthat/custom_data/Colombia_level_2.rds b/tests/testthat/custom_data/Colombia_level_2.rds
new file mode 100644
index 00000000..07aee3a3
Binary files /dev/null and b/tests/testthat/custom_data/Colombia_level_2.rds differ
diff --git a/tests/testthat/custom_data/Netherlands_level_1.rds b/tests/testthat/custom_data/Netherlands_level_1.rds
index ceff2ca3..26b1c9cb 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..26b1c9cb 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/ecdc.rds b/tests/testthat/custom_data/ecdc.rds
index 9e6c2294..6edff880 100644
Binary files a/tests/testthat/custom_data/ecdc.rds and b/tests/testthat/custom_data/ecdc.rds differ
diff --git a/tests/testthat/custom_data/mexico_level_1_snap.rds b/tests/testthat/custom_data/mexico_level_1_snap.rds
index cc89f66d..71abefd0 100644
Binary files a/tests/testthat/custom_data/mexico_level_1_snap.rds and b/tests/testthat/custom_data/mexico_level_1_snap.rds differ
diff --git a/tests/testthat/custom_data/mexico_level_2_snap.rds b/tests/testthat/custom_data/mexico_level_2_snap.rds
index b6dfc25b..8b021b02 100644
Binary files a/tests/testthat/custom_data/mexico_level_2_snap.rds and b/tests/testthat/custom_data/mexico_level_2_snap.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/custom_data/who.rds b/tests/testthat/custom_data/who.rds
index 14b102ee..6f004077 100644
Binary files a/tests/testthat/custom_data/who.rds and b/tests/testthat/custom_data/who.rds differ
diff --git a/tests/testthat/custom_tests/mock_data.R b/tests/testthat/custom_tests/mock_data.R
index 4b09b694..006cffdf 100644
--- a/tests/testthat/custom_tests/mock_data.R
+++ b/tests/testthat/custom_tests/mock_data.R
@@ -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, date, level_1_region, level_1_region_code, everything()
+ )
return(dplyr::tibble(expected_data))
}
@@ -234,10 +238,16 @@ get_expected_data_for_complete_cumulative_columns_test <- function() {
partial_data <- expected_data[-c(6:9), ]
# manually add cumulative cases to get expected data
- full_data_with_cum_cases_filled <- covidregionaldata:::fill_empty_dates_with_na(partial_data)
- full_data_with_cum_cases_filled <- dplyr::arrange(full_data_with_cum_cases_filled, level_1_region, date)
- full_data_with_cum_cases_filled <- cbind(full_data_with_cum_cases_filled, as.integer(c(1, 5, 5, 15, 2, 7, 7, 18, 3, 3, 3, 15)))
+ full_data_with_cum_cases_filled <- partial_data %>%
+ 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 <-
+ cbind(
+ full_data_with_cum_cases_filled,
+ as.integer(c(1, 5, 5, 15, 2, 7, 7, 18, 3, 3, 3, 15))
+ )
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)
}
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..c6c45d73
--- /dev/null
+++ b/tests/testthat/test-json_reader.R
@@ -0,0 +1,36 @@
+test_path <- "custom_data/mtcars.json"
+target <- dplyr::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))
+})
diff --git a/tests/testthat/test-processing.R b/tests/testthat/test-processing.R
index 10fdcc3c..e13ce6ad 100644
--- a/tests/testthat/test-processing.R
+++ b/tests/testthat/test-processing.R
@@ -80,26 +80,35 @@ 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
+
partial_data <- expected_data[-c(6:9), ]
- expect_equal(fill_empty_dates_with_na(partial_data), expected_data)
+ expect_equal(
+ fill_empty_dates_with_na(partial_data),
+ expected_data
+ )
expected_data <- dplyr::mutate(
expected_data,
level_2_region = level_1_region,
level_2_region_code = level_1_region_code
) %>%
+ group_by(level_2_region, level_2_region_code) %>%
select(
- date, level_2_region, level_2_region_code,
- level_1_region, level_1_region_code, cases
+ date, level_1_region, level_1_region_code,
+ level_2_region, level_2_region_code, cases
)
partial_data <- expected_data[-c(6:9), ]
- expect_equal(fill_empty_dates_with_na(partial_data), expected_data)
+ expect_equal(
+ fill_empty_dates_with_na(partial_data),
+ expected_data
+ )
})
test_that("complete_cumulative_columns works", {
input_data <- get_input_data_for_complete_cumulative_columns_test()
expected_data <- get_expected_data_for_complete_cumulative_columns_test()
actual_data <- complete_cumulative_columns(input_data)
- expect_equal(colnames(actual_data), colnames(expected_data))
+ expect_equal(sort(colnames(actual_data)), sort(colnames(expected_data)))
expect_true(!any(is.na(actual_data$cases_total)))
})
diff --git a/tests/testthat/test-regional-datasets.R b/tests/testthat/test-regional-datasets.R
index 4a6061ca..fea1af79 100644
--- a/tests/testthat/test-regional-datasets.R
+++ b/tests/testthat/test-regional-datasets.R
@@ -1,7 +1,7 @@
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
# load testing function and tools.
# set up custom tests using:
- # custom_tests/regional-dataset-specific.R
+ # custom_tests/regional-dataset-specific.R # nolint
source("custom_tests/test-regional-dataset.R")
# should a single dataset be tested vs all datasets
@@ -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
+ )
)
- )
+ }
}
diff --git a/vignettes/supported-countries.Rmd b/vignettes/supported-countries.Rmd
index 53d1018f..b9dde943 100644
--- a/vignettes/supported-countries.Rmd
+++ b/vignettes/supported-countries.Rmd
@@ -72,8 +72,7 @@ datasets <- get_available_datasets() %>%
Method, "/badge.svg)]",
"(https://github.com/epiforecasts/covidregionaldata/actions/workflows/", # nolint
Method, ".yaml)"
- ),
- `CRAN status` = "*working*"
+ )
)
kable(datasets)
```