Skip to content

Commit

Permalink
feat: new date_min and date_max checks for robyn_allocator #366
Browse files Browse the repository at this point in the history
  • Loading branch information
laresbernardo committed Apr 6, 2022
1 parent 13462d1 commit 3df9705
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion R/R/allocator.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#' @param constr_mode Character. Options are \code{"eq"} or \code{"ineq"},
#' indicating constraints with equality or inequality.
#' @param date_min,date_max Character. Date range to calculate mean (of non-zero spends) and
#' total spends. Default will consider all dates within window.
#' total spends. Default will consider all dates within window. Length must be 1.
#' @return A list object containing allocator result.
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -186,6 +186,7 @@ robyn_allocator <- function(robyn_object = NULL,

# Spend values based on date range set
dt_optimCost <- dt_mod %>% slice(startRW:endRW)
check_daterange(date_min, date_max, dt_optimCost$ds)
if (is.null(date_min)) date_min <- min(dt_optimCost$ds)
if (is.null(date_max)) date_max <- max(dt_optimCost$ds)
if (date_min < min(dt_optimCost$ds)) date_min <- min(dt_optimCost$ds)
Expand Down
13 changes: 13 additions & 0 deletions R/R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,16 @@ check_run_inputs <- function(cores, iterations, trials, intercept_sign, nevergra
stop(sprintf("Input 'intercept_sign' must be any of: %s", paste(opts, collapse = ", ")))
}
}

check_daterange <- function(date_min, date_max, dates) {
if (!is.null(date_min)) {
if (length(date_min) > 1) stop("Set a single date for 'date_min' parameter")
if (date_min < min(dates)) warning(sprintf(
"Parameter 'date_min' not in your data's date range. Changed to '%s'", min(dates)))
}
if (!is.null(date_max)) {
if (length(date_max) > 1) stop("Set a single date for 'date_max' parameter")
if (date_max > max(dates)) warning(sprintf(
"Parameter 'date_max' not in your data's date range. Changed to '%s'", max(dates)))
}
}
2 changes: 1 addition & 1 deletion R/man/robyn_allocator.Rd

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

9 changes: 5 additions & 4 deletions R/man/robyn_converge.Rd

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

0 comments on commit 3df9705

Please sign in to comment.