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
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
de54916
Add function to check validity of reports input
jamesmbaazam Oct 12, 2023
242c4f4
Adopt reports checking function
jamesmbaazam Oct 12, 2023
73d4817
Import checkmate
jamesmbaazam Oct 12, 2023
6293fa7
Linting: remove whitespace
jamesmbaazam Oct 12, 2023
c486b10
Remove explicit namespacing
jamesmbaazam Oct 13, 2023
83f28db
Import checkmate functions
jamesmbaazam Oct 13, 2023
5559a55
Revise function description
jamesmbaazam Oct 13, 2023
de2b6e5
Make _opts functions return their own class
jamesmbaazam Oct 13, 2023
650271b
Import functions for use
jamesmbaazam Oct 13, 2023
04f8ff3
Add input checking to the estimation functions
jamesmbaazam Oct 13, 2023
4af70cc
Return an object of class secondary_opts
jamesmbaazam Oct 13, 2023
b954ac2
Allow for NULL inputs
jamesmbaazam Oct 19, 2023
0544e8f
Change burn_in check from integer to numeric
jamesmbaazam Oct 19, 2023
d47606b
Update returned objects
jamesmbaazam Oct 19, 2023
d10e236
Allow NULL args
jamesmbaazam Oct 19, 2023
2e50956
Make lower bound of horizon 0
jamesmbaazam Oct 19, 2023
d291b12
Don't import assert_integer
jamesmbaazam Oct 19, 2023
c4064c3
Pass delays to delay_opts
jamesmbaazam Oct 23, 2023
ee247d9
Don't return a class
jamesmbaazam Oct 23, 2023
30c6deb
Catch the dot-dot-dot and modify iter if present
jamesmbaazam Oct 23, 2023
ba00fc1
Convert argument to stan_opts objects
jamesmbaazam Oct 23, 2023
7cd4bc4
Revise wording of return type
jamesmbaazam Oct 23, 2023
b50c450
Remove import of assert_integer
jamesmbaazam Oct 23, 2023
8af25bb
Linting: Remove trailing whitespace
jamesmbaazam Oct 23, 2023
0987274
Linting: trim white space
jamesmbaazam Oct 24, 2023
65f31d3
Add tests for check_reports_valid function
jamesmbaazam Oct 26, 2023
e234eec
Automatic readme update
actions-user Oct 26, 2023
6187da7
Check inputs of simulate_infection()
jamesmbaazam Oct 26, 2023
164a4e3
Check inputs of epinow function
jamesmbaazam Oct 26, 2023
30befbd
Check that target_date is a string, not a date
jamesmbaazam Oct 27, 2023
9f70cfd
Check that target_folder is specified as a directory
jamesmbaazam Oct 27, 2023
8b52163
Import functions for assertions
jamesmbaazam Oct 27, 2023
e360309
Check that estimates input contains a "fit" element
jamesmbaazam Oct 27, 2023
6c56694
Various checks on "R" input
jamesmbaazam Oct 27, 2023
d55876a
Fix docs of check_reports_valid
jamesmbaazam Oct 30, 2023
dd422e3
Fix docs of check_reports_valid
jamesmbaazam Oct 30, 2023
82839d8
Fix docs of check_reports_valid
jamesmbaazam Oct 30, 2023
a6f2e89
Fix docs of check_reports_valid
jamesmbaazam Oct 30, 2023
c2c330f
Error if column names are outside of allowed set
jamesmbaazam Oct 30, 2023
34f8dd7
Remove boolean argument in favour of enumerated options
jamesmbaazam Oct 30, 2023
688190d
Generate fixed doc
jamesmbaazam Oct 30, 2023
1b5ce1f
Update docs to mention returned class
jamesmbaazam Oct 30, 2023
d47d55e
Replace binary argument with enumerated argument
jamesmbaazam Oct 30, 2023
dbeeae5
Don't allow null values
jamesmbaazam Oct 30, 2023
8323b68
Revert to have a minimal set of allowed columns
jamesmbaazam Oct 31, 2023
d908afc
Improve documentation
jamesmbaazam Oct 31, 2023
20e4f25
Allow model argument to be null.
jamesmbaazam Oct 31, 2023
e06d1f4
Improve typesetting
jamesmbaazam Oct 31, 2023
61df073
Styling
jamesmbaazam Oct 31, 2023
7a61847
Fix a wrong function link in docs
jamesmbaazam Oct 31, 2023
bb89302
Remove awkward line breaks
jamesmbaazam Nov 1, 2023
46fcf69
Use rlang arg_match() to prevent partial match
jamesmbaazam Nov 1, 2023
5410759
Add news item
jamesmbaazam Nov 1, 2023
db0bfce
Pass arguments to `stan_opts` as list in tests
sbfnk Nov 13, 2023
9b94515
Linting: Use == to match length-1 scalars, not %in%
jamesmbaazam Nov 13, 2023
7ccbc70
Linting: Switch logic of ifelse statement
jamesmbaazam Nov 13, 2023
3931cbc
Linting: contruct paths with file.path() instead of paste0.
jamesmbaazam Nov 13, 2023
841d340
Linting: Fix indentation
jamesmbaazam Nov 14, 2023
da6a20d
Fix wrong return value
jamesmbaazam Nov 14, 2023
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
34 changes: 17 additions & 17 deletions R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,15 @@ fit_model_with_nuts <- function(args, future = FALSE, max_execution_time = Inf,
}
}

if (!future) {
fit <- fit_chain(1,
stan_args = args, max_time = max_execution_time,
catch = !id %in% c("estimate_infections", "epinow")
)
if (stuck_chains > 0) {
fit <- NULL
}
if (is.null(fit)) {
rlang::abort("model fitting was timed out or failed")
}
} else {
if (future) {
chains <- args$chains
args$chains <- 1
args$cores <- 1
fits <- future.apply::future_lapply(1:chains, fit_chain,
stan_args = args,
max_time = max_execution_time,
catch = TRUE,
future.seed = TRUE
stan_args = args,
max_time = max_execution_time,
catch = TRUE,
future.seed = TRUE
sbfnk marked this conversation as resolved.
Show resolved Hide resolved
)
if (stuck_chains > 0) {
fits[1:stuck_chains] <- NULL
Expand All @@ -498,12 +487,23 @@ fit_model_with_nuts <- function(args, future = FALSE, max_execution_time = Inf,
if ((chains - failed_chains) < 2) {
rlang::abort(
"model fitting failed as too few chains were returned to assess",
" convergence (2 or more required)"
" convergence (2 or more required)"
)
}
}
fit <- rstan::sflist2stanfit(fit)
}
} else {
fit <- fit_chain(1,
stan_args = args, max_time = max_execution_time,
catch = !id %in% c("estimate_infections", "epinow")
)
if (stuck_chains > 0) {
fit <- NULL
}
if (is.null(fit)) {
rlang::abort("model fitting was timed out or failed")
}
}
return(fit)
}
Expand Down