Skip to content

Commit 17b7206

Browse files
committed
fix: removed duplicated results in JSON files + refresh doc typo
1 parent 3bca15d commit 17b7206

File tree

7 files changed

+32
-24
lines changed

7 files changed

+32
-24
lines changed

R/R/inputs.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ robyn_inputs <- function(dt_input = NULL,
278278
check_novar(select(dt_input, -all_of(unused_vars)))
279279

280280
## Collect input
281-
InputCollect <- output <- list(
281+
InputCollect <- list(
282282
dt_input = dt_input,
283283
dt_holidays = dt_holidays,
284284
dt_mod = NULL,
@@ -320,7 +320,7 @@ robyn_inputs <- function(dt_input = NULL,
320320
if (!is.null(hyperparameters)) {
321321
### Conditional output 1.2
322322
## Running robyn_inputs() for the 1st time & 'hyperparameters' provided --> run robyn_engineering()
323-
output <- robyn_engineering(InputCollect, ...)
323+
InputCollect <- robyn_engineering(InputCollect, ...)
324324
}
325325
} else {
326326
### Use case 2: adding 'hyperparameters' and/or 'calibration_input' using robyn_inputs()
@@ -351,17 +351,17 @@ robyn_inputs <- function(dt_input = NULL,
351351
## Update & check hyperparameters
352352
if (is.null(InputCollect$hyperparameters)) InputCollect$hyperparameters <- hyperparameters
353353
check_hyperparameters(InputCollect$hyperparameters, InputCollect$adstock, InputCollect$all_media)
354-
output <- robyn_engineering(InputCollect, ...)
354+
InputCollect <- robyn_engineering(InputCollect, ...)
355355
}
356356
}
357357

358358
if (!is.null(json_file)) {
359-
pending <- which(!names(json$InputCollect) %in% output)
360-
output <- append(output, json$InputCollect[pending])
359+
pending <- which(!names(json$InputCollect) %in% names(InputCollect))
360+
InputCollect <- append(InputCollect, json$InputCollect[pending])
361361
}
362362

363-
class(output) <- c("robyn_inputs", class(output))
364-
return(output)
363+
class(InputCollect) <- c("robyn_inputs", class(InputCollect))
364+
return(InputCollect)
365365
}
366366

367367
#' @param x \code{robyn_inputs()} output.
@@ -760,7 +760,8 @@ prophet_decomp <- function(dt_transform, dt_holidays,
760760
use_weekday <- "weekday" %in% prophet_vars | "weekly.seasonality" %in% prophet_vars
761761

762762
dt_regressors <- bind_cols(recurrence, select(
763-
dt_transform, all_of(c(context_vars, paid_media_spends)))) %>%
763+
dt_transform, all_of(c(context_vars, paid_media_spends))
764+
)) %>%
764765
mutate(ds = as.Date(.data$ds))
765766

766767
prophet_params <- list(

R/R/model.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,9 @@ init_msgs_run <- function(InputCollect, refresh, lambda_control = NULL, quiet =
12271227
"refreshDepth" %in% names(InputCollect),
12281228
InputCollect$refreshDepth,
12291229
ifelse("refreshCounter" %in% names(InputCollect),
1230-
InputCollect$refreshCounter, 0))
1230+
InputCollect$refreshCounter, 0
1231+
)
1232+
)
12311233
refresh <- as.integer(depth) > 0
12321234
message(sprintf(
12331235
"%s model is built on rolling window of %s %s: %s to %s",

R/R/outputs.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ robyn_outputs <- function(InputCollect, OutputModels,
115115
"refreshDepth" %in% names(InputCollect),
116116
InputCollect$refreshDepth,
117117
ifelse("refreshCounter" %in% names(InputCollect),
118-
InputCollect$refreshCounter, 0))
118+
InputCollect$refreshCounter, 0
119+
)
120+
)
119121
refresh <- as.integer(depth) > 0
120122
folder_var <- ifelse(!refresh, "init", paste0("rf", depth))
121123
plot_folder_sub <- paste("Robyn", format(Sys.time(), "%Y%m%d%H%M"), folder_var, sep = "_")

R/R/refresh.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#' data("dt_simulated_weekly")
6868
#' data("dt_prophet_holidays")
6969
#' # Set the (pre-trained and exported) Robyn model JSON file
70-
#' json_file <- "~/Robyn_202208081444_init/RobynModel-2_55_4.json
70+
#' json_file <- "~/Robyn_202208081444_init/RobynModel-2_55_4.json"
7171
#'
7272
#' # Run \code{robyn_refresh()} with 13 weeks cadence in auto mode
7373
#' Robyn <- robyn_refresh(
@@ -81,7 +81,7 @@
8181
#' )
8282
#'
8383
#' # Run \code{robyn_refresh()} with 4 weeks cadence in manual mode
84-
#' json_file2 <- "~/Robyn_202208081444_init/Robyn_202208090847_rf/RobynModel-1_2_3.json
84+
#' json_file2 <- "~/Robyn_202208081444_init/Robyn_202208090847_rf/RobynModel-1_2_3.json"
8585
#' Robyn <- robyn_refresh(
8686
#' json_file = json_file2,
8787
#' dt_input = dt_simulated_weekly,

R/R/response.R

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ robyn_response <- function(InputCollect = NULL,
9494
### Use previously exported model using json_file
9595
if (!is.null(json_file)) {
9696
if (is.null(InputCollect)) InputCollect <- robyn_inputs(json_file = json_file, ...)
97-
if (is.null(OutputCollect)) OutputCollect <- robyn_run(
98-
InputCollect = InputCollect,
99-
json_file = json_file,
100-
export = FALSE,
101-
quiet = quiet,
102-
...
103-
)
97+
if (is.null(OutputCollect)) {
98+
OutputCollect <- robyn_run(
99+
InputCollect = InputCollect,
100+
json_file = json_file,
101+
export = FALSE,
102+
quiet = quiet,
103+
...
104+
)
105+
}
104106
if (is.null(dt_hyppar)) dt_hyppar <- OutputCollect$resultHypParam
105107
if (is.null(dt_coef)) dt_coef <- OutputCollect$xDecompAgg
106108
} else {
@@ -140,8 +142,9 @@ robyn_response <- function(InputCollect = NULL,
140142
}
141143
}
142144

143-
if ("selectID" %in% names(OutputCollect))
145+
if ("selectID" %in% names(OutputCollect)) {
144146
select_model <- OutputCollect$selectID
147+
}
145148

146149
## Prep environment
147150
if (TRUE) {

R/man/robyn_refresh.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/demo.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ RobynRefresh <- robyn_refresh(
437437
dt_input = dt_simulated_weekly,
438438
dt_holidays = dt_prophet_holidays,
439439
refresh_steps = 13,
440-
refresh_iters = 1000, # 1k is estimation. Use refresh_mode = "manual" to try out.
440+
refresh_iters = 1000, # 1k is an estimation
441441
refresh_trials = 1
442442
)
443443

@@ -447,7 +447,7 @@ RobynRefresh <- robyn_refresh(
447447
dt_input = dt_simulated_weekly,
448448
dt_holidays = dt_prophet_holidays,
449449
refresh_steps = 7,
450-
refresh_iters = 1000, # 1k is estimation. Use refresh_mode = "manual" to try out.
450+
refresh_iters = 1000, # 1k is an estimation
451451
refresh_trials = 1
452452
)
453453

0 commit comments

Comments
 (0)