Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting #378

Merged
merged 19 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/lint-only-changed-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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:
pull_request:
branches:
- main
workflow_dispatch:

name: lint-changed-files

jobs:
lint-changed-files:
runs-on: ubuntu-latest
if: "! contains(github.event.head_commit.message, '[ci skip]')"
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::gh
any::lintr
any::purrr
needs: check

- name: Add lintr options
run: |
cat('\noptions(lintr.linter_file = ".lintr")\n', file = "~/.Rprofile", append = TRUE)
shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .

- name: Extract and lint files changed by this PR
run: |
files <- gh::gh("GET https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files")
changed_files <- purrr::map_chr(files, "filename")
all_files <- list.files(recursive = TRUE)
exclusions_list <- as.list(setdiff(all_files, changed_files))
lintr::lint_package(exclusions = exclusions_list)
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
36 changes: 0 additions & 36 deletions .github/workflows/lint.yaml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/render-readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
workflow_dispatch:
push:
paths:
- 'README.Rmd'

jobs:
render-readme:
runs-on: ubuntu-latest
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::.

- name: Compile the readme
run: |
rmarkdown::render("README.Rmd")
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 man/figures/
git diff-index --quiet HEAD || git commit -m "Automatic readme update"
git push origin || echo "No changes to push"
42 changes: 13 additions & 29 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
linters: with_defaults(
line_length_linter = line_length_linter(120)
linters: linters_with_tags(
tags = NULL, # include all linters
implicit_integer_linter = NULL,
extraction_operator_linter = NULL,
undesirable_function_linter = NULL,
function_argument_linter = NULL,
indentation_linter = NULL,
object_name_linter = NULL,
cyclocomp_linter(25L)
)
exclusions: list(
"inst/dev/load-stan-functions.R",
"inst/dev/recover-synthetic.R",
"inst/dev/test-secondary.R",
"inst/pkg-structure/generate-pkgstructure-report.R",
"R/stanmodels.R",
"tests/spelling.R",
"tests/testthat.R",
"tests/testthat/test-calc_CrI.R",
"tests/testthat/test-calc_CrIs.R",
"tests/testthat/test-calc_summary_measures.R",
"tests/testthat/test-calc_summary_stats.R",
"tests/testthat/test-create_future-rt.R",
"tests/testthat/test-create_stan_args.R",
"tests/testthat/test-epinow.R",
"tests/testthat/test-estimate_infections.R",
"tests/testthat/test-extract_CrIs.R",
"tests/testthat/test-get_dist.R",
"tests/testthat/test-set_dt_single_thread.R",
"tests/testthat/test-match_output_arguments.R",
"tests/testthat/test-regional_epinow.R",
"tests/testthat/test-regional_runtimes.R",
"tests/testthat/test-setup_future.R",
"tests/testthat/test-simulate_infections.R",
"tests/testthat/test-stan-infections.R",
"tests/testthat/test-stan-rt.R",
"tests/testthat/test-stan-secondary.R"
exclusions: c(
list.files("tests", recursive = TRUE, full.names = TRUE),
list.files("inst", recursive = TRUE, full.names = TRUE),
"R/stanmodels.R"
)
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: EpiNow2
Title: Estimate Real-Time Case Counts and Time-Varying
Epidemiological Parameters
Version: 1.3.6.1000
Version: 1.3.6.2000
Authors@R:
c(person(given = "Sam",
family = "Abbott",
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# EpiNow2 1.3.6.1000
# EpiNow2 1.3.6.2000

This release is in development. For a stable release install 1.3.5 from CRAN.

## Package

* Model description has been expanded to include more detail.
* Moved to a GitHub Action to only lint changed files.
* Linted the package with a wider range of default linters.
* Added a GitHub Action to build the README when it is altered.

# EpiNow2 1.3.5

Expand Down
25 changes: 16 additions & 9 deletions R/adjust.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
#' @description `r lifecycle::badge("stable")`
#' Maps from cases by date of infection to date of report via date of
#' onset.
#' @param infections `data.table` containing a `date` variable and a numeric `cases` variable.
#' @param infections `data.table` containing a `date` variable and a numeric
#' `cases` variable.
#'
#' @param delay_defs A list of single row data.tables that each defines a delay distribution (model, parameters and maximum delay for each model).
#' @param delay_defs A list of single row data.tables that each defines a
#' delay distribution (model, parameters and maximum delay for each model).
#' See `lognorm_dist_def` for an example of the structure.
#'
#' @param reporting_effect A numeric vector of length 7 that allows the scaling of reported cases
#' by the day on which they report (1 = Monday, 7 = Sunday). By default no scaling occurs.
#' @param reporting_effect A numeric vector of length 7 that allows the scaling
#' of reported cases by the day on which they report (1 = Monday, 7 = Sunday).
#' By default no scaling occurs.
#'
#' @param reporting_model A function that takes a single numeric vector as an argument and returns a
#' single numeric vector. Can be used to apply stochastic reporting effects. See the examples for details.
#' @param reporting_model A function that takes a single numeric vector as an
#' argument and returns a single numeric vector. Can be used to apply stochastic
#' reporting effects. See the examples for details.
#'
#' @return A `data.table` containing a `date` variable (date of report) and a `cases` variable. If `return_onset = TRUE` there will be
#' a third variable `reference` which indicates what the date variable refers to.
#' @return A `data.table` containing a `date` variable (date of report) and a
#' `cases` variable. If `return_onset = TRUE` there will be a third variable
#' `reference` which indicates what the date variable refers to.
#' @export
#' @inheritParams sample_approx_dist
#' @importFrom data.table setorder data.table data.table
Expand All @@ -42,7 +47,9 @@
#' )
#'
#' # simple mapping
#' report <- adjust_infection_to_report(cases, delay_defs = list(incubation_def, delay_def))
#' report <- adjust_infection_to_report(
#' cases, delay_defs = list(incubation_def, delay_def)
#' )
#' print(report)
#'
#' # mapping with a weekly reporting effect
Expand Down
Loading