Skip to content

Commit

Permalink
fix: usecase error #815
Browse files Browse the repository at this point in the history
usecase error that compared NULL value with character
  • Loading branch information
gufengzhou committed Sep 13, 2023
1 parent 5dc6b1e commit b8f5ece
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions R/R/response.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ robyn_response <- function(InputCollect = NULL,
}

which_usecase <- function(metric_value, date_range) {
case_when(
usecase <- case_when(
# Case 1: raw historical spend and all dates -> model decomp as out of the model (no mean spends)
(is.null(metric_value) & is.null(date_range)) | (date_range == "all") ~ "all_historical_vec",
is.null(metric_value) & is.null(date_range) ~ "all_historical_vec",
# Case 2: same as case 1 for date_range
is.null(metric_value) & !is.null(date_range) ~ "selected_historical_vec",
######### Simulations: use metric_value, not the historical real spend anymore
Expand All @@ -350,6 +350,12 @@ which_usecase <- function(metric_value, date_range) {
length(metric_value) > 1 & is.null(date_range) ~ "unit_metric_default_last_n",
TRUE ~ "unit_metric_selected_dates"
)
if (!is.null(date_range)) {
if (date_range == "all") {
usecase <- "all_historical_vec"
}
}
return(usecase)
}

# ####### SCENARIOS CHECK FOR date_range
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# LICENSE file in the root directory of this source tree.

#############################################################################################
#################### Meta MMM Open Source: Robyn 3.10.3 #######################
#################### Meta MMM Open Source: Robyn 3.10.4 #######################
#################### Quick demo guide #######################
#############################################################################################

Expand Down

2 comments on commit b8f5ece

@vlulla
Copy link

@vlulla vlulla commented on b8f5ece Sep 26, 2023

Choose a reason for hiding this comment

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

This if statement breaks, with the error Error in if (date_range == "all") { : the condition has length > 1 when the date_range is a vector of start and end dates. I suspect there needs to be an additional check to ensure that date_range is length 1 before checking that it is set to "all". Regardless, if (length(date_range)==1 & date_range == "all") would not hurt!

@gufengzhou
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good feedback. just pushed your suggestion on 825ced4

Please sign in to comment.