Skip to content

Commit

Permalink
fix: adapt robyn_performance() to Robyn 3.12.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
laresbernardo committed Dec 20, 2024
1 parent d3d8856 commit 380d24f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: lares
Type: Package
Title: Analytics & Machine Learning Sidekick
Version: 5.2.10.9002
Version: 5.2.10.9003
Authors@R: c(
person("Bernardo", "Lares", , "[email protected]", c("aut", "cre")))
Maintainer: Bernardo Lares <[email protected]>
Expand Down
13 changes: 11 additions & 2 deletions R/robyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ robyn_performance <- function(
solID = NULL, totals = TRUE,
marginals = FALSE, carryovers = FALSE,
quiet = FALSE, ...) {
dt_mod <- InputCollect$dt_mod
df <- OutputCollect$mediaVecCollect
if (!is.null(solID)) {
if (length(solID) > 1) {
Expand All @@ -554,22 +555,30 @@ robyn_performance <- function(
stopifnot(start_date <= end_date)

# Filter data for ID, modeling window and selected date range
dt_mod <- dt_mod %>%
filter(
.data$ds >= InputCollect$window_start,
.data$ds <= InputCollect$window_end,
.data$ds >= start_date, .data$ds <= end_date
) %>%
mutate(solID = solID, type = "rawSpend") %>%
select(c("ds", "solID", "type", InputCollect$all_media))
df <- df[df$solID %in% solID, ] %>%
filter(
.data$ds >= InputCollect$window_start,
.data$ds <= InputCollect$window_end,
.data$ds >= start_date, .data$ds <= end_date
) %>%
select(c("ds", "solID", "type", InputCollect$all_media))
if (nrow(df) == 0 && !quiet) {
if (nrow(dt_mod) == 0 && !quiet) {
warning(sprintf(
"No data for model %s within modeling window (%s:%s) and date range filtered (%s:%s)",
solID, InputCollect$window_start, InputCollect$window_end,
start_date, end_date
))
return(NULL)
}
spends <- df %>%
spends <- dt_mod %>%
filter(.data$type == "rawSpend") %>%
summarise_if(is.numeric, function(x) sum(x, na.rm = TRUE))
response <- df %>%
Expand Down

0 comments on commit 380d24f

Please sign in to comment.