Skip to content

Commit

Permalink
recode: allow convergence status in json
Browse files Browse the repository at this point in the history
  • Loading branch information
gufengzhou committed May 3, 2023
1 parent b0b4ef7 commit f12aa4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions R/R/clusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ confidence_calcs <- function(xDecompAgg, cls, all_paid, dep_var_type, k, boot_n
boot_ci = sprintf("[%s, %s]", round(.data$ci_low, 2), round(.data$ci_up, 2)),
ci_low = .data$ci_low,
ci_up = .data$ci_up,
sd = boot_se * sqrt(.data$n - 1),
dist100 = (.data$ci_up - .data$ci_low + 2 * boot_se * sqrt(.data$n - 1)) / 99,
.groups = "drop"
) %>%
ungroup()
Expand Down
11 changes: 9 additions & 2 deletions R/R/json.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#'
#' @inheritParams robyn_outputs
#' @param InputCollect \code{robyn_inputs()} output.
#' @param OutputModels \code{robyn_run()} output.
#' @param select_model Character. Which model ID do you want to export
#' into the JSON file?
#' @param dir Character. Existing directory to export JSON file to.
Expand All @@ -30,6 +31,7 @@
#' @export
robyn_write <- function(InputCollect,
OutputCollect = NULL,
OutputModels = NULL,
select_model = NULL,
dir = OutputCollect$plot_folder,
export = TRUE,
Expand All @@ -51,7 +53,12 @@ robyn_write <- function(InputCollect,
ret <- list()
skip <- which(unlist(lapply(InputCollect, function(x) is.list(x) | is.null(x))))
skip <- skip[!names(skip) %in% c("calibration_input", "hyperparameters", "custom_params")]
ret[["InputCollect"]] <- inputs <- InputCollect[-skip]
ret[["InputCollect"]] <- InputCollect[-skip]
conv_msg <- mapply(function(x) x[[1]], x = gregexpr(":", OutputModels$convergence$conv_msg),
SIMPLIFY = FALSE)
conv_msg <- mapply(function(x, y) substr(x, 1, y-1), x = OutputModels$convergence$conv_msg,
y = conv_msg, USE.NAMES = FALSE)
ret[["OutputCollect"]][["conv_msg"]] <- conv_msg
# toJSON(inputs, pretty = TRUE)

# ExportedModel JSON
Expand Down Expand Up @@ -100,7 +107,7 @@ robyn_write <- function(InputCollect,
(all_sol_json %>% filter(.data$cluster == x))$solID
})
names(all_sol_json) <- paste0("cluster", all_c)
ret[["all_sols"]] <- all_sol_json
ret[["OutputCollect"]][["all_sols"]] <- all_sol_json
}
write_json(ret, filename, pretty = TRUE)
}
Expand Down
3 changes: 2 additions & 1 deletion R/R/outputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ robyn_outputs <- function(InputCollect, OutputModels,
} else {
all_sol_json <- NULL
}
robyn_write(InputCollect, dir = OutputCollect$plot_folder, quiet = quiet, all_sol_json = all_sol_json)
robyn_write(InputCollect = InputCollect, OutputModels = OutputModels,
dir = OutputCollect$plot_folder, quiet = quiet, all_sol_json = all_sol_json)

# For internal use -> UI Code
if (ui && plot_pareto) OutputCollect$UI$pareto_onepagers <- pareto_onepagers
Expand Down
3 changes: 3 additions & 0 deletions R/man/robyn_write.Rd

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

0 comments on commit f12aa4a

Please sign in to comment.