diff --git a/.github/workflows/dependency-change.yaml b/.github/workflows/dependency-change.yaml new file mode 100644 index 0000000..0c51cdf --- /dev/null +++ b/.github/workflows/dependency-change.yaml @@ -0,0 +1,83 @@ +# 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 +# Adapted from Epiverse packages: https://github.com/epiverse-trace +on: + pull_request: + paths: + - 'DESCRIPTION' + +name: Analyze dependency changes + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + pull-requests: write + +jobs: + dependency-changes: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - 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: + packages: any::pak, glue, gh + + - name: Analyze dependency changes + shell: Rscript {0} + run: | + deps_base <- pak::pkg_deps("${{ github.repository }}@${{ github.base_ref }}", dependencies = TRUE) |> + subset(!directpkg) |> + subset(is.na(priority)) + # We install from PR number rather than branch to deal with the case + # of PR coming from forks + deps_head <- pak::pkg_deps("${{ github.repository }}#${{ github.event.number }}", dependencies = TRUE) |> + subset(!directpkg) |> + subset(is.na(priority)) + + deps_added <- deps_head |> + subset(!ref %in% deps_base$ref) + + deps_removed <- deps_base |> + subset(!ref %in% deps_head$ref) + + if (nrow(deps_added) + nrow(deps_removed) > 0) { + + message("Dependencies have changed! Analyzing...") + + if (nrow(deps_added) > 0) { + nudge <- "Reach out on slack (`#code-review` or `#help` channels) to double check if there are base R alternatives to the new dependencies.\n" + } else { + nudge <- "" + } + + msg <- glue::glue( + .sep = "\n", + "This pull request:", + "- Adds {nrow(deps_added)} new dependencies (direct and indirect)", + "- Adds {length(unique(deps_added$sysreqs))} new system dependencies", + "- Removes {nrow(deps_removed)} existing dependencies (direct and indirect)", + "- Removes {length(unique(deps_removed$sysreqs))} existing system dependencies", + "", + nudge, + "(Note that results may be inaccurate if you branched from an outdated version of the target branch.)" + ) + + message("Posting results as a pull request comment.") + + gh::gh( + "POST /repos/{repo}/issues/{issue_number}/comments", + repo = "${{ github.repository }}", + issue_number = "${{ github.event.number }}", + body = msg + ) + + } diff --git a/.github/workflows/render-readme.yaml b/.github/workflows/render-readme.yaml new file mode 100644 index 0000000..f305a40 --- /dev/null +++ b/.github/workflows/render-readme.yaml @@ -0,0 +1,97 @@ +# Adapted from Epiverse packages: https://github.com/epiverse-trace +# Reproduce locally by running: +# ```r +# pak::pak(c("any::rmarkdown", "any::usethis", ".")) +# writeLines( +# knitr::knit_expand( +# "README.Rmd", +# packagename = read.dcf("DESCRIPTION", "Package"), +# gh_repo = usethis:::github_remote_list()$repo_spec +# ), +# "README_expanded.Rmd" +# ) +# rmarkdown::render( +# "README_expanded.Rmd", +# output_file = "README.md", +# output_dir = "." +# ) +# unlink("README_expanded.Rmd") +# ``` +name: render-readme + +# Controls when the action will run. Triggers include: +# +# - button trigger from github action page +# - on changes to readme.Rmd + +on: + workflow_dispatch: + push: + branches: + # This may seem like a no-op but it prevents triggering on tags + # We use '**' rather '*' to accomodate names like 'dev/branch-1' + - '**' + paths: + - 'README.Rmd' + - '.github/workflows/render_readme.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + render-readme: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout repos + uses: actions/checkout@v4 + + - name: Setup R + uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - name: Setup pandoc + uses: r-lib/actions/setup-pandoc@v2 + + - name: Install dependencies + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rmarkdown, local::. + + - name: Compile the readme + run: | + writeLines( + knitr::knit_expand( + "README.Rmd", + packagename = read.dcf("DESCRIPTION", "Package"), + gh_repo = Sys.getenv("GITHUB_REPOSITORY") + ), + "README_expanded.Rmd" + ) + rmarkdown::render( + "README_expanded.Rmd", + output_file = "README.md", + output_dir = "." + ) + shell: Rscript {0} + + - name: Commit files + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add README.md + # Also add README figures if they exist + if [ -d man/figures ] + then + git add man/figures/ + fi + git diff-index --quiet HEAD || git commit -m "Automatic readme update" + git pull --rebase origin ${{ github.ref.name }} + git push origin || echo "No changes to push" diff --git a/.github/workflows/update-copyright-year.yaml b/.github/workflows/update-copyright-year.yaml new file mode 100644 index 0000000..156291c --- /dev/null +++ b/.github/workflows/update-copyright-year.yaml @@ -0,0 +1,38 @@ +# Adapted from Epiverse packages: https://github.com/epiverse-trace +name: Update copyright year(s) in license file + +on: + workflow_dispatch: + schedule: + - cron: '0 3 1 1 *' + +permissions: + contents: write + pull-requests: write + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: FantasticFiasco/action-update-license-year@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + path: | + LICENSE.md + prBody: > + This PR updates the copyright license for this new year! If you're reading this while you're celebrating, enjoy! Don't worry about this one :blush: + + ![Happy new year!](https://media.giphy.com/media/HyDfNCZlTn5iU/giphy.gif?cid=ecf05e4777yl7dbo1xfha6bx1z5lrl13uq7biv6rs9dqsyoh&ep=v1_gifs_search&rid=giphy.gif&ct=g) + - uses: FantasticFiasco/action-update-license-year@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + path: | + LICENSE + prBody: > + This PR updates the copyright license for this new year! If you're reading this while you're celebrating, enjoy! Don't worry about this one :blush: + + ![Happy new year!](https://media.giphy.com/media/HyDfNCZlTn5iU/giphy.gif?cid=ecf05e4777yl7dbo1xfha6bx1z5lrl13uq7biv6rs9dqsyoh&ep=v1_gifs_search&rid=giphy.gif&ct=g) + transform: (?<=YEAR:\s)(?\d{4})?-?(\d{4})? diff --git a/.lintr b/.lintr index 66a6688..e26a154 100644 --- a/.lintr +++ b/.lintr @@ -1,6 +1,5 @@ linters: all_linters( indentation_linter = NULL, # unstable as of lintr 3.1.0 - extraction_operator_linter = NULL, # lints auto-generated vignette setup chunks implicit_integer_linter = NULL, # turn off due to multiple integerish values used duplicate_argument_linter = NULL, # due to cli_bullets object_name_linter = NULL, # due to S3 methods @@ -20,8 +19,5 @@ exclusions: list( ), "vignettes" = list( undesirable_function_linter = Inf - ), - # do no attempt to lint auto-generated files - "R/RcppExports.R", - "R/cpp11.R" + ) ) diff --git a/DESCRIPTION b/DESCRIPTION index bf2a6c8..e237a6f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,6 +10,9 @@ Description: Your package description. It must end with a period (".") and include relevant bibliographical references if applicable, using the following format: Author et al. (2023) . License: MIT + file LICENSE +URL: https://github.com/vimc/vimc.rpkg.template, + https://vimc.github.io/vimc.rpkg.template/ +BugReports: https://github.com/vimc/vimc.rpkg.template/issues Suggests: knitr, rmarkdown, diff --git a/README.Rmd b/README.Rmd index e00c56a..86f57d4 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,6 +1,8 @@ --- output: github_document -# add bibliography here +# NOTE: place references if any as a JSON in `vignettes/resources` +# NOTE: references file can have any name, and there can be separate references per vignette +bibliography: vignettes/resources/references.json link-citations: true --- @@ -33,9 +35,7 @@ Replace all instances of `"vimc.rpkg.template"` with your package name. Make sur 2. Edit the files in `R/`, `tests/`, and `vignettes/` to suit your package; -3. Add spell check by running `usethis::use_spell_check(lang = "en-GB")`; - -4. Remove these instructions from `README.Rmd`, and re-render the `.md` file using `devtools::render_readme()`. +3. Remove these instructions from `README.Rmd`. Then, either let the automated GitHub Actions workflow update `README.md` once the change is pushed to GitHub, or disable the workflow by removing the file `.github/workflows/render-readme.yaml`, and manually re-render the `.md` file using `devtools::render_readme()`. ## Installation @@ -71,6 +71,8 @@ If preparatory or plotting steps are needed, prefer to hide them to keep focus o Add information and links to related projects, such as research papers or packages, here. +An example citation would be @echeverria-londono2021. + ## References -Space for references: REMOVE this text. +**Space for references: REMOVE this sub-section if there are no references. References, if any, should appear below this text. Remove this text in packages.** diff --git a/README.md b/README.md index 896e83e..0ba994d 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ VIMC GitHub organisation. Replace all instances of 2. Edit the files in `R/`, `tests/`, and `vignettes/` to suit your package; -3. Add spell check by running - `usethis::use_spell_check(lang = "en-GB")`; - -4. Remove these instructions from `README.Rmd`, and re-render the `.md` - file using `devtools::render_readme()`. +3. Remove these instructions from `README.Rmd`. Then, either let the + automated GitHub Actions workflow update `README.md` once the change + is pushed to GitHub, or disable the workflow by removing the file + `.github/workflows/render-readme.yaml`, and manually re-render the + `.md` file using `devtools::render_readme()`. ## Installation @@ -75,6 +75,26 @@ prefer to hide them to keep focus on the package functionality. Add information and links to related projects, such as research papers or packages, here. +An example citation would be Echeverria-Londono et al. +([2021](#ref-echeverria-londono2021)). + ## References -Space for references: REMOVE this text. +**Space for references: REMOVE this sub-section if there are no +references. References, if any, should appear below this text. Remove +this text in packages.** + +
+ +
+ +Echeverria-Londono, Susy, Xiang Li, Jaspreet Toor, Margaret J. De +Villiers, Shevanthi Nayagam, Timothy B. Hallett, Kaja Abbas, et al. +2021. “How Can the Public Health Impact of Vaccination Be Estimated?” +*BMC Public Health* 21 (1): 2049. +. + +
+ +
diff --git a/inst/WORDLIST b/inst/WORDLIST index 5d6e36f..8363407 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,7 +1,18 @@ +BMC Codecov +Echeverria +Hallett +Jaspreet +Kaja +Londono +Nayagam ORCID +Shevanthi +Susy TAGLINE +Toor VIMC +Xiang doi pkgdown rpkg diff --git a/man/vimc.rpkg.template-package.Rd b/man/vimc.rpkg.template-package.Rd index 4fa3a28..f332fff 100644 --- a/man/vimc.rpkg.template-package.Rd +++ b/man/vimc.rpkg.template-package.Rd @@ -7,6 +7,15 @@ \title{vimc.rpkg.template: Your Package Title in Title Case} \description{ Your package description. It must end with a period (".") and include relevant bibliographical references if applicable, using the following format: Author et al. (2023) \doi{10.5281/zenodo.6619350}. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/vimc/vimc.rpkg.template} + \item \url{https://vimc.github.io/vimc.rpkg.template/} + \item Report bugs at \url{https://github.com/vimc/vimc.rpkg.template/issues} +} + } \author{ \strong{Maintainer}: Pratik Gupte \email{p.gupte24@imperial.ac.uk} (\href{https://orcid.org/0000-0001-5294-7819}{ORCID}) diff --git a/tests/spelling.R b/tests/spelling.R index d60e024..a8cf85b 100644 --- a/tests/spelling.R +++ b/tests/spelling.R @@ -1,7 +1,6 @@ -if (requireNamespace("spelling", quietly = TRUE)) { +if (requireNamespace('spelling', quietly = TRUE)) spelling::spell_check_test( vignettes = TRUE, error = FALSE, skip_on_cran = TRUE ) -} diff --git a/tests/testthat/helper-state.R b/tests/testthat/helper-state.R index afb0459..1b2fb85 100644 --- a/tests/testthat/helper-state.R +++ b/tests/testthat/helper-state.R @@ -5,15 +5,6 @@ # function, or more conveniently with the `withr` package. # We add a test on R >= 4.0.0 because some functions such as # `globalCallingHandlers()` did not exist before. -get_pars_toreset <- function() { - pars <- par(no.readonly = TRUE) - # The following params are set and modified automatically by plot(), as - # documented in ?plot.window() and we: - # 1. have no control over them - # 2. do not care about resetting them - pars <- pars[!names(pars) %in% c("usr", "xaxp", "yaxp")] -} - if (getRversion() >= "4.0.0") { testthat::set_state_inspector(function() { list( diff --git a/vignettes/resources/references.json b/vignettes/resources/references.json new file mode 100644 index 0000000..3a691c0 --- /dev/null +++ b/vignettes/resources/references.json @@ -0,0 +1,3 @@ +[ + {"id":"echeverria-londono2021","abstract":"Abstract\n \n Background\n Deaths due to vaccine preventable diseases cause a notable proportion of mortality worldwide. To quantify the importance of vaccination, it is necessary to estimate the burden averted through vaccination. The Vaccine Impact Modelling Consortium (VIMC) was established to estimate the health impact of vaccination.\n \n \n Methods\n We describe the methods implemented by the VIMC to estimate impact by calendar year, birth year and year of vaccination (YoV). The calendar and birth year methods estimate impact in a particular year and over the lifetime of a particular birth cohort, respectively. The YoV method estimates the impact of a particular year’s vaccination activities through the use of impact ratios which have no stratification and stratification by activity type and/or birth cohort. Furthermore, we detail an impact extrapolation (IE) method for use between coverage scenarios. We compare the methods, focusing on YoV for hepatitis B, measles and yellow fever.\n \n \n Results\n We find that the YoV methods estimate similar impact with routine vaccinations but have greater yearly variation when campaigns occur with the birth cohort stratification. The IE performs well for the YoV methods, providing a time-efficient mechanism for updates to impact estimates.\n \n \n Conclusions\n These methods provide a robust set of approaches to quantify vaccination impact; however it is vital that the area of impact estimation continues to develop in order to capture the full effect of immunisation.","accessed":{"date-parts":[["2025",12,9]]},"author":[{"family":"Echeverria-Londono","given":"Susy"},{"family":"Li","given":"Xiang"},{"family":"Toor","given":"Jaspreet"},{"family":"De Villiers","given":"Margaret J."},{"family":"Nayagam","given":"Shevanthi"},{"family":"Hallett","given":"Timothy B."},{"family":"Abbas","given":"Kaja"},{"family":"Jit","given":"Mark"},{"family":"Klepac","given":"Petra"},{"family":"Jean","given":"Kévin"},{"family":"Garske","given":"Tini"},{"family":"Ferguson","given":"Neil M."},{"family":"Gaythorpe","given":"Katy A. M."}],"citation-key":"echeverria-londono2021","container-title":"BMC Public Health","container-title-short":"BMC Public Health","DOI":"10.1186/s12889-021-12040-9","ISSN":"1471-2458","issue":"1","issued":{"date-parts":[["2021",12]]},"language":"en","page":"2049","source":"DOI.org (Crossref)","title":"How can the public health impact of vaccination be estimated?","type":"article-journal","URL":"https://bmcpublichealth.biomedcentral.com/articles/10.1186/s12889-021-12040-9","volume":"21"} +] diff --git a/vignettes/vimc-rpkg-template.Rmd b/vignettes/vimc-rpkg-template.Rmd index 2d33504..ce83315 100644 --- a/vignettes/vimc-rpkg-template.Rmd +++ b/vignettes/vimc-rpkg-template.Rmd @@ -1,6 +1,9 @@ --- title: "vimc-rpkg-template" output: rmarkdown::html_vignette +# NOTE: make references if any available as a JSON at a location, see e.g. below +# NOTE: uncomment the line below, and update the references path as needed +# bibliography: resources/references.json vignette: > %\VignetteIndexEntry{vimc-rpkg-template} %\VignetteEngine{knitr::rmarkdown}