From 3c6086c5b274d300106e3a97e63da4acd6273349 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 15:40:17 +0100 Subject: [PATCH 01/14] Update the R-CMD-check workflow I've renamed and re-written the R-CMD-check workflow to be more consistent. It is now based on the r-lib v2 action examples and runs against a collection of R versions to represent the PHS current and future potential setup --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 54 +++++++++++++++++++ .github/workflows/phsopendata.yml | 85 ------------------------------ README.Rmd | 2 +- README.md | 85 ++++++++++++++++-------------- 6 files changed, 102 insertions(+), 126 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml delete mode 100644 .github/workflows/phsopendata.yml diff --git a/.Rbuildignore b/.Rbuildignore index 588683b..c16d1c6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^phsopendata\.Rproj$ ^\.Rproj\.user$ ^README\.Rmd$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..60199e5 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,54 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/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 }}) + continue-on-error: ${{ matrix.config.must_pass }} + + strategy: + fail-fast: false + matrix: + config: + # Windows + - {os: windows-latest, r: 'release', must_pass: true} + # Use 3.6 to trigger usage of RTools35 + - {os: windows-latest, r: '3.6', must_pass: true} + # Linux + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', must_pass: false} + - {os: ubuntu-latest, r: 'release', must_pass: true} + - {os: ubuntu-latest, r: 'oldrel-1', must_pass: true} + - {os: ubuntu-latest, r: 'oldrel-2', must_pass: true} + - {os: ubuntu-latest, r: '3.6.1', must_pass: true} + + 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: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/phsopendata.yml b/.github/workflows/phsopendata.yml deleted file mode 100644 index cea7ca2..0000000 --- a/.github/workflows/phsopendata.yml +++ /dev/null @@ -1,85 +0,0 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions -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: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest", http-user-agent: "R/4.1.0 (ubuntu-20.04) R (4.1.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } - - 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: Restore R package cache - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check diff --git a/README.Rmd b/README.Rmd index d66733d..c796acc 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,7 +16,7 @@ knitr::opts_chunk$set( # phsopendata -[![R build status](https://github.com/Public-Health-Scotland/phsopendata/workflows/R-CMD-check/badge.svg)](https://github.com/Public-Health-Scotland/phsopendata/actions) +[![R-CMD-check](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml) `phsopendata` contains functions to interact with open data from the [Scottish Health and Social Care Open Data platform](https://www.opendata.nhs.scot/) via the CKAN API. diff --git a/README.md b/README.md index f8ea467..7f872cf 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,20 @@ + -phsopendata -=========== +# phsopendata -[![R build -status](https://github.com/Public-Health-Scotland/phsopendata/workflows/R-CMD-check/badge.svg)](https://github.com/Public-Health-Scotland/phsopendata/actions) +[![R-CMD-check](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml) `phsopendata` contains functions to interact with open data from the [Scottish Health and Social Care Open Data platform](https://www.opendata.nhs.scot/) via the CKAN API. -- `get-resource` extracts a single resource from an open dataset by + - `get-resource` extracts a single resource from an open dataset by resource id -- `get-dataset` extracts multiple resources from an open dataset by + - `get-dataset` extracts multiple resources from an open dataset by dataset name For extracting metadata and search functionality, we recommend using the @@ -26,60 +25,65 @@ For extracting metadata and search functionality, we recommend using the RStudio. However, depending on firewall settings, proxy use may need to be configured with `use_proxy()`. -Installation ------------- +## Installation You need to install `phsopendata` from GitHub, which requires a package like `remotes` or `devtools`. Using `remotes` you run this to install the package: - remotes::install_github("Public-Health-Scotland/phsopendata", - upgrade = "never" - ) +``` r +remotes::install_github("Public-Health-Scotland/phsopendata", + upgrade = "never" +) +``` -Examples --------- +## Examples ### Downloading a data table with `get_resource()` To extract a specific resource, you will need it’s unique identifier - resource id. This can be found in the dataset metadata, the URL of a -resource’s page on -https://www.opendata.nhs.scot/, -or extracted using `ckanr::package_show`. +resource’s page on , or extracted using +`ckanr::package_show`. - library(phsopendata) +``` r +library(phsopendata) - # define a resource ID - res_id <- "a794d603-95ab-4309-8c92-b48970478c14" +# define a resource ID +res_id <- "a794d603-95ab-4309-8c92-b48970478c14" - # download the data from the CKAN database - data <- get_resource(res_id = "a794d603-95ab-4309-8c92-b48970478c14") +# download the data from the CKAN database +data <- get_resource(res_id = "a794d603-95ab-4309-8c92-b48970478c14") +``` ### Querying/filtering data with `get_resource()` You can define a row limit with the `rows` argument to get the first *N* rows of a table. - # get first 100 rows - get_resource( - res_id = "a794d603-95ab-4309-8c92-b48970478c14", - rows = 100 - ) +``` r +# get first 100 rows +get_resource( + res_id = "a794d603-95ab-4309-8c92-b48970478c14", + rows = 100 +) +``` You can use `col_select` and `row_filters` to query the data server-side (i.e., the data is filtered before it is downloaded to your machine). - # get first 100 rows - get_resource( - res_id = "a794d603-95ab-4309-8c92-b48970478c14", - col_select = c("GPPracticeName", "TelephoneNumber"), - row_filters = list( - HB = "S08000017", - Dispensing = "Y" - ) - ) +``` r +# get first 100 rows +get_resource( + res_id = "a794d603-95ab-4309-8c92-b48970478c14", + col_select = c("GPPracticeName", "TelephoneNumber"), + row_filters = list( + HB = "S08000017", + Dispensing = "Y" + ) +) +``` ### Downloading multiple tables with `get_dataset()` @@ -93,12 +97,13 @@ from: [opendata.nhs.scot/dataset/*gp-practice-populations*](https://www.opendata.nhs.scot/dataset/gp-practice-populations), so the dataset name will be gp-practice-populations. - # if max_resources is not set, all resources will be returned by default. - # Here we pull 10 rows from the first 2 resources only - get_dataset("gp-practice-populations", max_resources = 2, rows = 10) +``` r +# if max_resources is not set, all resources will be returned by default. +# Here we pull 10 rows from the first 2 resources only +get_dataset("gp-practice-populations", max_resources = 2, rows = 10) +``` -Contributing to phsopendata ---------------------------- +## Contributing to phsopendata At present, this package is maintained by [David Aikman](https://github.com/daikman). From bda241bd50888e1e68bd3c9ba626311bb414b361 Mon Sep 17 00:00:00 2001 From: runner Date: Wed, 24 Aug 2022 14:43:49 +0000 Subject: [PATCH 02/14] Re-build README.Rmd --- README.md | 82 ++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 7f872cf..9310e07 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ - -# phsopendata +phsopendata +=========== @@ -12,9 +12,9 @@ [Scottish Health and Social Care Open Data platform](https://www.opendata.nhs.scot/) via the CKAN API. - - `get-resource` extracts a single resource from an open dataset by +- `get-resource` extracts a single resource from an open dataset by resource id - - `get-dataset` extracts multiple resources from an open dataset by +- `get-dataset` extracts multiple resources from an open dataset by dataset name For extracting metadata and search functionality, we recommend using the @@ -25,65 +25,60 @@ For extracting metadata and search functionality, we recommend using the RStudio. However, depending on firewall settings, proxy use may need to be configured with `use_proxy()`. -## Installation +Installation +------------ You need to install `phsopendata` from GitHub, which requires a package like `remotes` or `devtools`. Using `remotes` you run this to install the package: -``` r -remotes::install_github("Public-Health-Scotland/phsopendata", - upgrade = "never" -) -``` + remotes::install_github("Public-Health-Scotland/phsopendata", + upgrade = "never" + ) -## Examples +Examples +-------- ### Downloading a data table with `get_resource()` To extract a specific resource, you will need it’s unique identifier - resource id. This can be found in the dataset metadata, the URL of a -resource’s page on , or extracted using -`ckanr::package_show`. +resource’s page on +https://www.opendata.nhs.scot/, +or extracted using `ckanr::package_show`. -``` r -library(phsopendata) + library(phsopendata) -# define a resource ID -res_id <- "a794d603-95ab-4309-8c92-b48970478c14" + # define a resource ID + res_id <- "a794d603-95ab-4309-8c92-b48970478c14" -# download the data from the CKAN database -data <- get_resource(res_id = "a794d603-95ab-4309-8c92-b48970478c14") -``` + # download the data from the CKAN database + data <- get_resource(res_id = "a794d603-95ab-4309-8c92-b48970478c14") ### Querying/filtering data with `get_resource()` You can define a row limit with the `rows` argument to get the first *N* rows of a table. -``` r -# get first 100 rows -get_resource( - res_id = "a794d603-95ab-4309-8c92-b48970478c14", - rows = 100 -) -``` + # get first 100 rows + get_resource( + res_id = "a794d603-95ab-4309-8c92-b48970478c14", + rows = 100 + ) You can use `col_select` and `row_filters` to query the data server-side (i.e., the data is filtered before it is downloaded to your machine). -``` r -# get first 100 rows -get_resource( - res_id = "a794d603-95ab-4309-8c92-b48970478c14", - col_select = c("GPPracticeName", "TelephoneNumber"), - row_filters = list( - HB = "S08000017", - Dispensing = "Y" - ) -) -``` + # get first 100 rows + get_resource( + res_id = "a794d603-95ab-4309-8c92-b48970478c14", + col_select = c("GPPracticeName", "TelephoneNumber"), + row_filters = list( + HB = "S08000017", + Dispensing = "Y" + ) + ) ### Downloading multiple tables with `get_dataset()` @@ -97,13 +92,12 @@ from: [opendata.nhs.scot/dataset/*gp-practice-populations*](https://www.opendata.nhs.scot/dataset/gp-practice-populations), so the dataset name will be gp-practice-populations. -``` r -# if max_resources is not set, all resources will be returned by default. -# Here we pull 10 rows from the first 2 resources only -get_dataset("gp-practice-populations", max_resources = 2, rows = 10) -``` + # if max_resources is not set, all resources will be returned by default. + # Here we pull 10 rows from the first 2 resources only + get_dataset("gp-practice-populations", max_resources = 2, rows = 10) -## Contributing to phsopendata +Contributing to phsopendata +--------------------------- At present, this package is maintained by [David Aikman](https://github.com/daikman). From 4beaaaa159e9aec3848bc96883b1b6c2e7aaa597 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 15:45:08 +0100 Subject: [PATCH 03/14] Add test coverage workflow and infrastructure This workflow will check and report test coverage to codecov.io --- .Rbuildignore | 1 + .github/workflows/test-coverage.yaml | 31 ++++++++++++++++++++++++++++ DESCRIPTION | 1 + README.Rmd | 1 + README.md | 2 ++ codecov.yml | 14 +++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 codecov.yml diff --git a/.Rbuildignore b/.Rbuildignore index c16d1c6..04c793c 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,4 @@ ^\.Rproj\.user$ ^README\.Rmd$ ^\.github$ +^codecov\.yml$ diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..4b65418 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,31 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/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 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: covr::codecov(quiet = FALSE) + shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index 1b03080..82b66dd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,6 +20,7 @@ Imports: cli, xml2 Suggests: + covr, testthat (>= 3.0.0) Encoding: UTF-8 LazyData: true diff --git a/README.Rmd b/README.Rmd index c796acc..96b452e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,6 +17,7 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/Public-Health-Scotland/phsopendata/branch/master/graph/badge.svg)](https://app.codecov.io/gh/Public-Health-Scotland/phsopendata?branch=master) `phsopendata` contains functions to interact with open data from the [Scottish Health and Social Care Open Data platform](https://www.opendata.nhs.scot/) via the CKAN API. diff --git a/README.md b/README.md index 9310e07..059abaf 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ phsopendata [![R-CMD-check](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Public-Health-Scotland/phsopendata/actions/workflows/R-CMD-check.yaml) +[![Codecov test +coverage](https://codecov.io/gh/Public-Health-Scotland/phsopendata/branch/master/graph/badge.svg)](https://app.codecov.io/gh/Public-Health-Scotland/phsopendata?branch=master) `phsopendata` contains functions to interact with open data from the diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true From bf69d1970e8f2e7dd799e618225e2b4e7dd9447d Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 15:47:11 +0100 Subject: [PATCH 04/14] Add pkgdown workflow and infrastructure This will build the package documentation, Readme and vignettes into a website on a new branch `gh_pages` this can be deployed to GitHub pages with the right permissions. --- .Rbuildignore | 3 +++ .github/workflows/pkgdown.yaml | 46 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + DESCRIPTION | 2 ++ _pkgdown.yml | 4 +++ 5 files changed, 56 insertions(+) create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 _pkgdown.yml diff --git a/.Rbuildignore b/.Rbuildignore index 04c793c..e87d948 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,6 @@ ^README\.Rmd$ ^\.github$ ^codecov\.yml$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..0b26021 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,46 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/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] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@4.1.4 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 807ea25..c2f15ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .Rproj.user .Rhistory .RData +docs diff --git a/DESCRIPTION b/DESCRIPTION index 82b66dd..cc7c00e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,3 +27,5 @@ LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.1 Config/testthat/edition: 3 +URL: https://github.com/Public-Health-Scotland/phsopendata +BugReports: https://github.com/Public-Health-Scotland/phsopendata/issues diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..d71acfb --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: ~ +template: + bootstrap: 5 + From e73f5af0f8ee70334fb2e84e19f979c6bec5422a Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 15:49:06 +0100 Subject: [PATCH 05/14] Add an action to style the package This will run whenever a relevant filetype is modified and style the package with `styler` to the tidyverse style. All the changes will be only cosmetic but will ensure consistency. --- .github/workflows/style.yaml | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/style.yaml diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml new file mode 100644 index 0000000..f0bb30c --- /dev/null +++ b/.github/workflows/style.yaml @@ -0,0 +1,68 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + paths: ["**.[rR]", "**.[rR]md", "**.[rR]markdown", "**.[rR]nw"] + pull_request: + paths: ["**.[rR]", "**.[rR]md", "**.[rR]markdown", "**.[rR]nw"] + +name: Style + +jobs: + style: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup R + uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - name: Install dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::styler + needs: styler + + - name: Enable styler cache + run: styler::cache_activate() + shell: Rscript {0} + + - name: Determine cache location + id: styler-location + run: | + cat( + "##[set-output name=location;]", + styler::cache_info(format = "tabular")$location, + "\n", + sep = "" + ) + shell: Rscript {0} + + - name: Cache styler + uses: actions/cache@v2 + with: + path: ${{ steps.styler-location.outputs.location }} + key: ${{ runner.os }}-styler-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-styler- + ${{ runner.os }}- + + - name: Style + run: styler::style_pkg(filetype = c(".R", ".Rmd", ".Rmarkdown", ".Rnw")) + shell: Rscript {0} + + - name: Commit and push changes + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add R/\* + git commit -m "Style code" || echo "No changes to commit" + git pull --ff-only + git push origin From 12a7437e8723732c26bab295cf5e4fc95f9874d7 Mon Sep 17 00:00:00 2001 From: Moohan Date: Wed, 24 Aug 2022 14:52:02 +0000 Subject: [PATCH 06/14] Style code --- R/check_dataset_name.R | 7 ++++--- R/check_res_id.R | 10 ++++++---- R/dump_download.R | 4 ++-- R/error_check.R | 15 +++++++++------ R/parse_col_select.R | 5 ++--- R/parse_error.R | 2 -- R/parse_row_filters.R | 15 +++++++++------ R/phs_GET.R | 4 ++-- R/request_url.R | 7 ++++--- R/suggest_dataset_name.R | 5 ++--- R/use_dump_check.R | 7 ++++--- 11 files changed, 44 insertions(+), 37 deletions(-) diff --git a/R/check_dataset_name.R b/R/check_dataset_name.R index eb9ae91..0dc8648 100644 --- a/R/check_dataset_name.R +++ b/R/check_dataset_name.R @@ -11,15 +11,16 @@ check_dataset_name <- function(dataset_name) { # Has only lowercase alphanum or hyphens inbetween dataset_name_regex <- "^[a-z0-9][a-z0-9\\-]+?[a-z0-9]$" - if (!inherits(dataset_name, "character")) + if (!inherits(dataset_name, "character")) { cli::cli_abort(c( "The dataset name supplied {.var {dataset_name}} is invalid.", "x" = "dataset_name must be of type character.", "i" = "You supplied a {.cls {class(dataset_name)[0]}} value." )) + } - if (!grepl(dataset_name_regex, dataset_name)) + if (!grepl(dataset_name_regex, dataset_name)) { cli::cli_abort(c( "The dataset name supplied {.var {dataset_name}} is invalid", "x" = "dataset_name must be in dash-case @@ -27,5 +28,5 @@ check_dataset_name <- function(dataset_name) { "i" = "You can find dataset names in the URL of a dataset's page on {.url www.opendata.nhs.scot}." )) - + } } diff --git a/R/check_res_id.R b/R/check_res_id.R index c449fca..5692600 100644 --- a/R/check_res_id.R +++ b/R/check_res_id.R @@ -9,28 +9,30 @@ check_res_id <- function(res_id) { # check res_id is single value - if (length(res_id) > 1) + if (length(res_id) > 1) { cli::cli_abort(c( "Argument {.var res_id} must be of length 1.", i = "You supplied a res_id with a length of {length(res_id)}", x = "`get_resource` does not currently support requests for multiple resources simultaneously." )) + } # check res_id is character - if (!inherits(res_id, "character")) + if (!inherits(res_id, "character")) { cli::cli_abort(c( "Argument {.var res_id} must be of type character", i = "You supplied a {.var res_id} with type {.cls {class(res_id)[1]}}" )) + } # check regex pattern res_id_regex <- "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" - if (!grepl(res_id_regex, res_id)) + if (!grepl(res_id_regex, res_id)) { cli::cli_abort(c( "Argument {.var res_id} is in an invalid format.", i = "You can find a resource's ID in the URL of it's page on {.url www.opendata.nhs.scot}." )) - + } } diff --git a/R/dump_download.R b/R/dump_download.R index 4c9d7e3..8cf4270 100644 --- a/R/dump_download.R +++ b/R/dump_download.R @@ -11,12 +11,12 @@ dump_download <- function(res_id) { ) # if content is a web page - if ("xml_document" %in% class(content)) + if ("xml_document" %in% class(content)) { cli::cli_abort(c( "Can't find resource with ID {.var {res_id}} in datastore." )) + } # return data return(content[, -1]) - } diff --git a/R/error_check.R b/R/error_check.R index 6802376..f1dc6b0 100644 --- a/R/error_check.R +++ b/R/error_check.R @@ -6,17 +6,21 @@ error_check <- function(content) { # if content is not a list, # stop for content (a string describing an error) - if (!is.list(content)) cli::cli_abort(c( - "API error", - x = content - )) + if (!is.list(content)) { + cli::cli_abort(c( + "API error", + x = content + )) + } # if there is no error status/message in the content, # break out of the function is_error <- suppressWarnings( !is.null(content$error) ) - if (!is_error) return() + if (!is_error) { + return() + } # generate error message and stop error_text <- parse_error(content$error) @@ -24,5 +28,4 @@ error_check <- function(content) { "API error.", x = error_text )) - } diff --git a/R/parse_col_select.R b/R/parse_col_select.R index c0980dd..82232b2 100644 --- a/R/parse_col_select.R +++ b/R/parse_col_select.R @@ -4,12 +4,11 @@ #' @param col_select a character vector identifying the columns to select. #' @return a character string parse_col_select <- function(col_select) { - - if (is.null(col_select)) + if (is.null(col_select)) { return(NULL) + } return( paste0(col_select, collapse = ",") ) - } diff --git a/R/parse_error.R b/R/parse_error.R index 1cc9f07..353d91a 100644 --- a/R/parse_error.R +++ b/R/parse_error.R @@ -14,13 +14,11 @@ parse_error <- function(error) { # special case for validation errors if (error_type == "Validation Error") { - error_output <- paste0(names(error[1][1]), ": ", error[1][[1]]) # translate message for package users error_output <- sub("fields", "col_select", error_output) error_output <- sub("q", "row_filters", error_output) - } # special case for SQL validation errors diff --git a/R/parse_row_filters.R b/R/parse_row_filters.R index 1cc8ce4..756dca2 100644 --- a/R/parse_row_filters.R +++ b/R/parse_row_filters.R @@ -5,18 +5,20 @@ parse_row_filters <- function(row_filters) { # exit function if no filters - if (is.null(row_filters)) + if (is.null(row_filters)) { return(NULL) + } # check if any filters in list have length > 1 too_many <- sapply(row_filters, length) > 1 - if (any(too_many)) + if (any(too_many)) { cli::cli_abort(c( "Invalid input for {.var row_filters}", i = "{names(row_filters)[which(too_many)]} in {.var row_filters} has too many values. ", x = "The {.var row_filters} list must only contain vectors of length 1." )) + } # check if any items in the list/vector have the same name # find number of unique names @@ -26,19 +28,20 @@ parse_row_filters <- function(row_filters) { # if same, all names are unique unique_names <- n_u_row_filters == n_row_filters - if (!unique_names) + if (!unique_names) { cli::cli_abort(c( "Invalid input for {.var row_filters}", x = "One or more elements in {.var row_filters} have the same name.", i = "Only one filter per field is currently supported by `get_resource`." )) + } filter_body <- paste0( - '"', names(row_filters), '":"', row_filters, '"', collapse = "," + '"', names(row_filters), '":"', row_filters, '"', + collapse = "," ) return( - paste0('{', filter_body, '}') + paste0("{", filter_body, "}") ) - } diff --git a/R/phs_GET.R b/R/phs_GET.R index d7fd156..99a6fe1 100644 --- a/R/phs_GET.R +++ b/R/phs_GET.R @@ -19,11 +19,12 @@ phs_GET <- function(action, query, verbose = FALSE) { ) # Check for response from server - if (!inherits(response, "response")) + if (!inherits(response, "response")) { cli::cli_abort(c( "Can't connect to the CKAN server.", i = "Check your network/proxy settings." )) + } # extract content from HTTP response content <- httr::content( @@ -35,5 +36,4 @@ phs_GET <- function(action, query, verbose = FALSE) { if (verbose) cat("GET request successful.\n") return(content) - } diff --git a/R/request_url.R b/R/request_url.R index 7aa65b0..ba2e866 100644 --- a/R/request_url.R +++ b/R/request_url.R @@ -8,23 +8,24 @@ request_url <- function(action, query) { # check action is valid valid_actions <- c("datastore_search", "datastore_search_sql", "dump", "package_show", "package_list") - if (!(action %in% valid_actions)) + if (!(action %in% valid_actions)) { cli::cli_abort(c( "API call failed.", x = "Invalid {.var action} argument in request." )) + } # return dump URL - if (action == "dump") + if (action == "dump") { return(paste0( "https://www.opendata.nhs.scot/datastore/dump/", query, "?bom=true" )) + } # return standard API endpoint (i.e., not dump) return(paste0( "https://www.opendata.nhs.scot/api/3/action/", action, "?", query )) - } diff --git a/R/suggest_dataset_name.R b/R/suggest_dataset_name.R index f1dd34b..0a61cbe 100644 --- a/R/suggest_dataset_name.R +++ b/R/suggest_dataset_name.R @@ -4,7 +4,6 @@ #' @param dataset_name a string to be matched against valid dataset names #' suggest_dataset_name <- function(dataset_name) { - content <- phs_GET("package_list", "") dataset_names <- unlist(content$result) @@ -13,13 +12,14 @@ suggest_dataset_name <- function(dataset_name) { string_distances <- stringdist::stringdist(dataset_name, dataset_names) # if min distance is too big, abort - if (min(string_distances) > 10) + if (min(string_distances) > 10) { cli::cli_abort(c( "Can't find the dataset name {.var {dataset_name}}, or a close match.", i = "Find a dataset's name in the URL of it's page on {.url www.opendata.nhs.scot.}" )) + } # find closet match closest_match <- dataset_names[which.min(string_distances)] @@ -29,5 +29,4 @@ suggest_dataset_name <- function(dataset_name) { "Can't find the dataset name {.var {dataset_name}}.", "i" = "Did you mean '{closest_match}'?" )) - } diff --git a/R/use_dump_check.R b/R/use_dump_check.R index 632d96b..b6cf714 100644 --- a/R/use_dump_check.R +++ b/R/use_dump_check.R @@ -21,7 +21,7 @@ use_dump_check <- function(query, rows) { # if user queried the data queried <- !is.null(query$q) || !is.null(query$filter) || !is.null(query$fields) - if (queried && use_dump) + if (queried && use_dump) { cli::cli_warn(c( "Invalid combination of {.var rows}, {.var row_filters} and/or {.var col_select}.", @@ -29,12 +29,13 @@ use_dump_check <- function(query, rows) { AND query its rows/columns.", i = "ALL rows and columns of the resource will be downloaded." )) + } # warn users if they haven't queried # the data but have requested rows > 99999 if (is.null(rows)) rows <- 0 - if (!queried && rows > 99999) + if (!queried && rows > 99999) { cli::cli_warn(c( "Getting all rows of resource.", i = "All rows will be returned if you @@ -42,8 +43,8 @@ use_dump_check <- function(query, rows) { i = "You set {.var rows} to {format(rows, big.mark = ',', scientific = FALSE)}" )) + } return(use_dump) } - From dd3ccec46366dd9aff97b6d52b6ec62a4a13ebe9 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 15:50:30 +0100 Subject: [PATCH 07/14] Add an action to document the package Will run when any files in the `R` directory are modified and ensure the package documentation is up to date. --- .github/workflows/document.yaml | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/document.yaml diff --git a/.github/workflows/document.yaml b/.github/workflows/document.yaml new file mode 100644 index 0000000..9a772c0 --- /dev/null +++ b/.github/workflows/document.yaml @@ -0,0 +1,44 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + paths: ["R/**"] + pull_request: + paths: ["R/**"] + +name: Document + +jobs: + document: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup R + uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - name: Install dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::roxygen2 + needs: roxygen2 + + - name: Document + run: roxygen2::roxygenise() + shell: Rscript {0} + + - name: Commit and push changes + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add man/\* NAMESPACE + git commit -m "Update documentation" || echo "No changes to commit" + git pull --ff-only + git push origin From 856307776becfaff869b8d21df2665f1042ee9a8 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 15:51:09 +0100 Subject: [PATCH 08/14] Add an action to lint the package It will run on any push or pull and add annotiations to the commit / PR with suggestions from `lintr` which provides best practice. --- .github/workflows/lint.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..381410b --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,30 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/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: 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 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr, local::. + needs: lint + + - name: Lint + run: lintr::lint_package() + shell: Rscript {0} From 9fcdafb0b6b41312fbab5396965ff382e24a9eeb Mon Sep 17 00:00:00 2001 From: James McMahon Date: Wed, 24 Aug 2022 16:35:21 +0100 Subject: [PATCH 09/14] Setup infrastructure for pkgdown -> GitHub pages I realised that I did actually have permissions --- DESCRIPTION | 3 ++- _pkgdown.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cc7c00e..47c0117 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,5 +27,6 @@ LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.1 Config/testthat/edition: 3 -URL: https://github.com/Public-Health-Scotland/phsopendata +URL: https://github.com/Public-Health-Scotland/phsopendata, + https://public-health-scotland.github.io/phsopendata/ BugReports: https://github.com/Public-Health-Scotland/phsopendata/issues diff --git a/_pkgdown.yml b/_pkgdown.yml index d71acfb..0dcfc08 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,4 @@ -url: ~ +url: https://public-health-scotland.github.io/phsopendata/ template: bootstrap: 5 From 713f15ec05efcd10968e2a0c4f3fcd04c6169178 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 6 Oct 2022 16:18:14 +0100 Subject: [PATCH 10/14] use stefanzweifel action to commit --- .github/workflows/style.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml index f0bb30c..4419ac4 100644 --- a/.github/workflows/style.yaml +++ b/.github/workflows/style.yaml @@ -59,10 +59,6 @@ jobs: shell: Rscript {0} - name: Commit and push changes - run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - git add R/\* - git commit -m "Style code" || echo "No changes to commit" - git pull --ff-only - git push origin + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Style code" From 110e476baf41ebfecdef49ed0cb43767ec79db8d Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 6 Oct 2022 16:19:16 +0100 Subject: [PATCH 11/14] Use stefanzweifel to commit change --- .github/workflows/document.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/document.yaml b/.github/workflows/document.yaml index 9a772c0..4d00aff 100644 --- a/.github/workflows/document.yaml +++ b/.github/workflows/document.yaml @@ -35,10 +35,6 @@ jobs: shell: Rscript {0} - name: Commit and push changes - run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - git add man/\* NAMESPACE - git commit -m "Update documentation" || echo "No changes to commit" - git pull --ff-only - git push origin + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Update documentation" From 7484b8e5281cf3c98c87ec79af13d716586ef503 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Tue, 2 May 2023 16:03:50 +0100 Subject: [PATCH 12/14] Update actions to the latest examples from r-lib (https://github.com/r-lib/actions/blob/v2/examples/README.md)[] --- .github/workflows/R-CMD-check.yaml | 7 +++++-- .github/workflows/document.yaml | 14 +++++++------ .github/workflows/lint.yaml | 2 +- .github/workflows/pkgdown.yaml | 6 ++++-- .github/workflows/style.yaml | 31 ++++++++++++++++++---------- .github/workflows/test-coverage.yaml | 23 +++++++++++++++++++-- 6 files changed, 59 insertions(+), 24 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 60199e5..2ae07d5 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -26,7 +26,10 @@ jobs: - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', must_pass: false} - {os: ubuntu-latest, r: 'release', must_pass: true} - {os: ubuntu-latest, r: 'oldrel-1', must_pass: true} - - {os: ubuntu-latest, r: 'oldrel-2', must_pass: true} + - {os: ubuntu-latest, r: 'oldrel-2', must_pass: false} + # Vesions in use on PHS PWB + - {os: ubuntu-latest, r: '4.0.2', must_pass: true} + - {os: ubuntu-latest, r: '4.1.2', must_pass: true} - {os: ubuntu-latest, r: '3.6.1', must_pass: true} env: @@ -34,7 +37,7 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/document.yaml b/.github/workflows/document.yaml index 4d00aff..6c118dd 100644 --- a/.github/workflows/document.yaml +++ b/.github/workflows/document.yaml @@ -3,8 +3,6 @@ on: push: paths: ["R/**"] - pull_request: - paths: ["R/**"] name: Document @@ -15,7 +13,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 @@ -35,6 +33,10 @@ jobs: shell: Rscript {0} - name: Commit and push changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "Update documentation" + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add man/\* NAMESPACE DESCRIPTION + git commit -m "Update documentation" || echo "No changes to commit" + git pull --ff-only + git push origin diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 381410b..24d656d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -14,7 +14,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-r@v2 with: diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 0b26021..ed7650c 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -19,8 +19,10 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 @@ -39,7 +41,7 @@ jobs: - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@4.1.4 + uses: JamesIves/github-pages-deploy-action@v4.4.1 with: clean: false branch: gh-pages diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml index 4419ac4..37c986e 100644 --- a/.github/workflows/style.yaml +++ b/.github/workflows/style.yaml @@ -2,9 +2,7 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - paths: ["**.[rR]", "**.[rR]md", "**.[rR]markdown", "**.[rR]nw"] - pull_request: - paths: ["**.[rR]", "**.[rR]md", "**.[rR]markdown", "**.[rR]nw"] + paths: ["**.[rR]", "**.[qrR]md", "**.[rR]markdown", "**.[rR]nw", "**.[rR]profile"] name: Style @@ -15,7 +13,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 @@ -27,7 +25,7 @@ jobs: - name: Install dependencies uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::styler + extra-packages: any::styler, any::roxygen2 needs: styler - name: Enable styler cache @@ -38,15 +36,17 @@ jobs: id: styler-location run: | cat( - "##[set-output name=location;]", + "location=", styler::cache_info(format = "tabular")$location, "\n", + file = Sys.getenv("GITHUB_OUTPUT"), + append = TRUE, sep = "" ) shell: Rscript {0} - name: Cache styler - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ steps.styler-location.outputs.location }} key: ${{ runner.os }}-styler-${{ github.sha }} @@ -55,10 +55,19 @@ jobs: ${{ runner.os }}- - name: Style - run: styler::style_pkg(filetype = c(".R", ".Rmd", ".Rmarkdown", ".Rnw")) + run: styler::style_pkg() shell: Rscript {0} - name: Commit and push changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "Style code" + run: | + if FILES_TO_COMMIT=($(git diff-index --name-only ${{ github.sha }} \ + | egrep --ignore-case '\.(R|[qR]md|Rmarkdown|Rnw|Rprofile)$')) + then + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git commit ${FILES_TO_COMMIT[*]} -m "Style code" + git pull --ff-only + git push origin + else + echo "No changes to commit." + fi diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 4b65418..2c5bb50 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -15,7 +15,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-r@v2 with: @@ -27,5 +27,24 @@ jobs: needs: coverage - name: Test coverage - run: covr::codecov(quiet = FALSE) + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package From 6a0c9f1cc637fee8db8e1a62160ca1ad3b947c53 Mon Sep 17 00:00:00 2001 From: Moohan Date: Thu, 30 Nov 2023 12:29:00 +0000 Subject: [PATCH 13/14] Update documentation --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d4f2410..02cf416 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,7 +25,7 @@ Suggests: Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 Config/testthat/edition: 3 URL: https://github.com/Public-Health-Scotland/phsopendata, https://public-health-scotland.github.io/phsopendata/ From e5234f7e835adf81e6b9b7a762101f985a5a6647 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Thu, 30 Nov 2023 12:36:14 +0000 Subject: [PATCH 14/14] Update to use latest examples (again) Also simplify the R CMD check --- .github/workflows/R-CMD-check.yaml | 21 +++++++++++---------- .github/workflows/render-README.yml | 10 ++++++---- .github/workflows/style.yaml | 2 +- .github/workflows/test-coverage.yaml | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2ae07d5..138d69c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -11,26 +11,27 @@ name: R-CMD-check jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - continue-on-error: ${{ matrix.config.must_pass }} strategy: fail-fast: false matrix: config: # Windows - - {os: windows-latest, r: 'release', must_pass: true} + - {os: windows-latest, r: 'release'} # Use 3.6 to trigger usage of RTools35 - - {os: windows-latest, r: '3.6', must_pass: true} + - {os: windows-latest, r: '3.6'} # Linux - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', must_pass: false} - - {os: ubuntu-latest, r: 'release', must_pass: true} - - {os: ubuntu-latest, r: 'oldrel-1', must_pass: true} - - {os: ubuntu-latest, r: 'oldrel-2', must_pass: false} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + # Mac OS + - {os: macos-latest, r: 'release'} + # Vesions in use on PHS PWB - - {os: ubuntu-latest, r: '4.0.2', must_pass: true} - - {os: ubuntu-latest, r: '4.1.2', must_pass: true} - - {os: ubuntu-latest, r: '3.6.1', must_pass: true} + - {os: ubuntu-latest, r: '4.0.2'} + - {os: ubuntu-latest, r: '4.1.2'} + - {os: ubuntu-latest, r: '3.6.1'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/render-README.yml b/.github/workflows/render-README.yml index 49b2b1e..42a57c7 100644 --- a/.github/workflows/render-README.yml +++ b/.github/workflows/render-README.yml @@ -6,18 +6,20 @@ on: jobs: render: name: Render README - 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-pandoc@v1 + - uses: actions/checkout@v3 + - uses: r-lib/actions/setup-r@v2 + - uses: r-lib/actions/setup-pandoc@v2 - name: Install rmarkdown run: Rscript -e 'install.packages("rmarkdown")' - name: Render README run: Rscript -e 'rmarkdown::render("README.Rmd", output_format = "md_document")' - name: Commit results run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" git commit README.md -m 'Re-build README.Rmd' || echo "No changes to commit" git push origin || echo "No changes to commit" diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml index 37c986e..bee3e48 100644 --- a/.github/workflows/style.yaml +++ b/.github/workflows/style.yaml @@ -65,7 +65,7 @@ jobs: then git config --local user.name "$GITHUB_ACTOR" git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - git commit ${FILES_TO_COMMIT[*]} -m "Style code" + git commit ${FILES_TO_COMMIT[*]} -m "Style code (GHA)" git pull --ff-only git push origin else diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb50..27d4528 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -31,7 +31,7 @@ jobs: covr::codecov( quiet = FALSE, clean = FALSE, - install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") ) shell: Rscript {0}