Skip to content

Commit

Permalink
Adding checkmates
Browse files Browse the repository at this point in the history
  • Loading branch information
SofiaOtero committed Oct 21, 2024
1 parent b4158ff commit 79abb6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 10 additions & 3 deletions R/fit_peak.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' uses the peak observations from each previous season it can only
#' explain the current intensity in relation to the peak of the season.
#'
#' @param weighted_observations A tibble containing three columns of size n;
#' @param weighted_observations A tibble containing two columns of size n;
#' `observation`, which represents the data points, and `weight`, which is the
#' importance assigned to an observation. Higher weights indicate that an
#' observation has more influence on the model outcome, while lower weights
Expand Down Expand Up @@ -62,8 +62,7 @@
#' # Add into a tibble with weight decreasing going one season step back
#' peak_input <- tibble::tibble(
#' observation = observations,
#' weight = 0.8^rep(season_num_rev, each = obs),
#' season = season[rep(seq(from = 1, to = length(season)), each = obs)]
#' weight = 0.8^rep(season_num_rev, each = obs)
#' )
#'
#' # Use the peak model
Expand All @@ -86,6 +85,14 @@ fit_peak <- function(
lower_optim = -Inf,
upper_optim = Inf
) {
# Check input arguments
coll <- checkmate::makeAssertCollection()
checkmate::assert_tibble(weighted_observations, add = coll)
checkmate::assert_names(colnames(weighted_observations),
identical.to = c("observation", "weight"), add = coll)
checkmate::assert_numeric(lower_optim, add = coll)
checkmate::assert_numeric(upper_optim, add = coll)
checkmate::reportAssertions(coll)
# Match the arguements.
family <- rlang::arg_match(family)
optim_method <- rlang::arg_match(optim_method)
Expand Down
5 changes: 2 additions & 3 deletions man/fit_peak.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/testthat/test-fit_peak.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ test_that("Can run the fit_peak fun without error", {

peak_input <- tibble::tibble(
observation = observations,
weight = 0.8^rep(season_num_rev, each = obs),
season = season[rep(seq(from = 1, to = length(season)), each = obs)]
weight = 0.8^rep(season_num_rev, each = obs)
)

expect_no_error(fit_peak(weighted_observations = peak_input))
Expand Down

0 comments on commit 79abb6e

Please sign in to comment.