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

Add input validation #476

Merged
merged 59 commits into from
Nov 14, 2023
Merged

Add input validation #476

merged 59 commits into from
Nov 14, 2023

Conversation

jamesmbaazam
Copy link
Contributor

@jamesmbaazam jamesmbaazam commented Oct 12, 2023

This PR:

  • Adds input checking to 5 core functions: estimate_infections(), estimate_secondary(), estimate_truncation(), simulate_infections(), and epinow().

  • A function check_reports_valid() is added to validate the reports dataset passed to the functions. Tests are added to check its functionality.

  • The various *_opts() functions are assigned subclasses of the same name as the functions. These are tested against the assigned arguments to ensure the right *_opts() is passed to the right argument. For example, the obs argument in estimate_secondary() is expected to only receive arguments passed through obs_opts() and will error otherwise.

This PR closes #337.

@jamesmbaazam
Copy link
Contributor Author

jamesmbaazam commented Oct 12, 2023

@seabbs @sbfnk I've implemented a check for the input data to the various estimate_*() functions. It expects the non-date columns to be integer. Tests are currently failing locally because example_data.rds has a "numeric" confirm column. I would prefer to make that conversion at the source but can't find where the data is created. Could you point me to it?

@sbfnk
Copy link
Contributor

sbfnk commented Oct 13, 2023

I'm not sure we want this to be strictly integer as the method should work in principle with e.g. proportions.

The check to me looks good, only think missing I think is a corresponding test.

In the rest of the package we have mostly (although I don't think strictly) taken the approach of importing functions with @importFrom and then not qualifying them with e.g. checkmate:: in the code except when it might be ambiuous.

@jamesmbaazam
Copy link
Contributor Author

jamesmbaazam commented Oct 13, 2023

I'm not sure we want this to be strictly integer as the method should work in principle with e.g. proportions.

Alright. I'll change it to check for numerics instead of integer.

The check to me looks good, only think missing I think is a corresponding test.

Thanks. It's still a work in progress, hence the PR is a draft.

In the rest of the package we have mostly (although I don't think strictly) taken the approach of importing functions with @importFrom and then not qualifying them with e.g. checkmate:: in the code except when it might be ambiguous.

Noted. I'll make the change.

@jamesmbaazam jamesmbaazam force-pushed the input-val branch 2 times, most recently from 102d8ee to 4fe82c7 Compare October 26, 2023 15:16
@jamesmbaazam jamesmbaazam marked this pull request as ready for review October 27, 2023 11:45
@jamesmbaazam jamesmbaazam self-assigned this Oct 27, 2023
@jamesmbaazam jamesmbaazam requested review from seabbs and sbfnk October 27, 2023 16:18
@sbfnk
Copy link
Contributor

sbfnk commented Oct 30, 2023

Noting that the test coverage PR was cancelled after 6 hours (didn't fail) - might be worth re-running to see if it's a transient GHA issue.

Copy link
Contributor

@sbfnk sbfnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Please add yourself as an author to any function where you've made substantial additions.

R/checks.R Outdated Show resolved Hide resolved
R/checks.R Outdated Show resolved Hide resolved
R/checks.R Outdated Show resolved Hide resolved
R/checks.R Outdated Show resolved Hide resolved
R/checks.R Outdated Show resolved Hide resolved
R/checks.R Outdated Show resolved Hide resolved
R/estimate_infections.R Outdated Show resolved Hide resolved
R/estimate_infections.R Outdated Show resolved Hide resolved
R/estimate_secondary.R Outdated Show resolved Hide resolved
R/estimate_secondary.R Show resolved Hide resolved
@seabbs
Copy link
Contributor

seabbs commented Oct 31, 2023

Please add yourself as an author to any function where you've made substantial additions.

If this is EpiNow2 dev policy we should update the contributing guide.

@jamesmbaazam
Copy link
Contributor Author

I'm not sure this test-coverage failure is related to the PR content.

@jamesmbaazam
Copy link
Contributor Author

Please add yourself as an author to any function where you've made substantial additions.
If this is EpiNow2 dev policy we should update the contributing guide.

Sure. We can have a section on giving credit. We recently did similar for Epiverse here. I'm actually not sure what constitutes a substantial addition. I guess I would define it as a change without which the function would not do as promised? I would imagine that I would qualify as a co-author of these functions when I work on the S3 class structure for each of them. In that case, the return value of the function is the class with certain attributes, which I implemented, so I can consider myself a co-author.

Copy link
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks really nice. Looking forward to having this merged. Just a few comments about line breaks (exciting times) and we need a news update for this.

R/checks.R Outdated Show resolved Hide resolved
R/checks.R Outdated Show resolved Hide resolved
R/estimate_secondary.R Outdated Show resolved Hide resolved
R/opts.R Show resolved Hide resolved
@sbfnk
Copy link
Contributor

sbfnk commented Nov 1, 2023

I'm not sure this test-coverage failure is related to the PR content.

I think it's related but I'm not sure how - the corresponding action hasn't been failing on other PRs, e.g.
#467

That said I could not reproduce the timeouts running covr::codecov locally and tests are not timing out within the R CMD check so I'm not sure what's going on.

@jamesmbaazam
Copy link
Contributor Author

That said I could not reproduce the timeouts running covr::codecov locally and tests are not timing out within the R CMD check so I'm not sure what's going on.

Same. It passes locally but with a warning and 3 notes.

checking top-level files ... WARNING
  A complete check needs the 'checkbashisms' script.
  See sectionConfigure and cleanupin theWriting R Extensionsmanual.checking installed package size ... NOTE
    installed size is 12.3Mb
    sub-directories of 1Mb or more:
      doc       1.1Mb
      extdata   2.1Mb
      help      2.1Mb
      libs      6.1Mbchecking for GNU extensions in Makefiles ... NOTE
  GNU make is a SystemRequirements.checking files invignettes... NOTE
  The following directory looks like a leftover from 'knitr':figurePlease remove from your package.

0 errors| 1 warning| 3 notes

@sbfnk
Copy link
Contributor

sbfnk commented Nov 3, 2023

Could you try temporarily removing test-checks.r and see if that fixes it?

@sbfnk
Copy link
Contributor

sbfnk commented Nov 3, 2023

Could you try temporarily removing test-checks.r and see if that fixes it?

Turns out this didn't do the trick. Next steps could be:

  • roll back more changes (can always reset to 157b5c4 and force push to revert to original state later) if that's even possible (and I realise it might not be)
  • address Update outdated actions #492 (complete stab in the dark but who knows) not an issue as the everything is up to date in the test-coverage action
  • ignore (but then we lose the codecov action which would be a bit of a shame)

@jamesmbaazam
Copy link
Contributor Author

I'll create a backup branch and try the fixes there. Whichever works will then be applied here.

@seabbs
Copy link
Contributor

seabbs commented Nov 7, 2023

Could this be a problem with the cache for this action? I just had this issue in epinowcast (but for another action) and resolved it by removing the related cache using gh cache

@jamesmbaazam
Copy link
Contributor Author

I've removed them and re-run the action. Let's see if it fixes it. 🤞🏾

@sbfnk
Copy link
Contributor

sbfnk commented Nov 9, 2023

Maybe temporarily changing the action here to run covr::codecov with quiet = FALSE will help identify the issue?

@jamesmbaazam
Copy link
Contributor Author

jamesmbaazam commented Nov 13, 2023

This test-coverage failure issue has persisted after several attempts so I'm going to split this PR into smaller parts and see if that helps:

  • One to add the function that checks the reports argument.
  • Separate PR's with input checks for each functions.

@sbfnk
Copy link
Contributor

sbfnk commented Nov 13, 2023

I've been able to reproduce the issue using https://github.com/nektos/act (which is a great little tool for investigating GHA issues locally).

Just looking at some runs I started before the weekend it looks like all the tests in test-estimate_infections.R were slowed down to snail's pace, apparently because of an issue in the interaction between codecov and stan_opts objects being passed to do.call() calls. Changing the code so that only pure lists are passed to do.call has resolved the issue. This is implemented in db0bfce which is based off the last commit of the original PR before we started investigating this issue.

To apply this fix in this PR you can:

  1. git reset --hard to 5410759
  2. git merge the fix-codecov branch
  3. force push

@jamesmbaazam
Copy link
Contributor Author

Amazing! Thanks for taking a look @sbfnk. The stan_opts change is my fault. I made that change in ba00fc1.

@sbfnk
Copy link
Contributor

sbfnk commented Nov 13, 2023

It's still a really strange issue that didn't occur when either of us ran codecov::covr. Fingers crossed this fixes it.🤞

@jamesmbaazam
Copy link
Contributor Author

🥳

@jamesmbaazam jamesmbaazam requested review from sbfnk and seabbs November 13, 2023 22:25
@jamesmbaazam
Copy link
Contributor Author

This should be ready for merge now.

Copy link
Contributor

@sbfnk sbfnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing stuff! Nearly there.

R/estimate_infections.R Outdated Show resolved Hide resolved
@jamesmbaazam jamesmbaazam requested a review from sbfnk November 14, 2023 12:57
@sbfnk sbfnk merged commit 65e6c5a into main Nov 14, 2023
9 checks passed
@sbfnk sbfnk deleted the input-val branch November 14, 2023 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add input validation
4 participants