Skip to content

Commit

Permalink
feat: export/save raw data for reproducibility (raw_data.csv)
Browse files Browse the repository at this point in the history
  • Loading branch information
laresbernardo committed Sep 1, 2022
1 parent 01610a4 commit c1d9c35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ check_factorvars <- function(dt_input, factor_vars, context_vars, organic_vars)
temp <- select(dt_input, all_of(c(context_vars, organic_vars)))
are_not_numeric <- !sapply(temp, is.numeric)
if (any(are_not_numeric)) {
these <- are_not_numeric[!are_not_numeric %in% factor_vars]
these <- are_not_numeric[!names(are_not_numeric) %in% factor_vars]
these <- these[these]
if (length(these) > 0) {
message("Automatically set these variables as 'factor_vars': ", v2t(names(these)))
Expand Down
6 changes: 4 additions & 2 deletions R/R/outputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ robyn_outputs <- function(InputCollect, OutputModels,

if (csv_out %in% c("all", "pareto")) {
if (!quiet) message(paste(">> Exporting", csv_out, "results as CSVs into directory..."))
robyn_csv(OutputCollect, csv_out, export = export)
robyn_csv(InputCollect, OutputCollect, csv_out, export = export)
}

if (!quiet) message(">> Exporting general plots into directory...")
Expand Down Expand Up @@ -205,11 +205,12 @@ Pareto-front ({x$pareto_fronts}) All solutions ({nSols}): {paste(x$allSolutions,
####################################################################
#' Output results into local files: CSV files
#'
#' @param InputCollect \code{robyn_inputs()} output.
#' @param OutputCollect \code{robyn_run(..., export = FALSE)} output.
#' @rdname robyn_outputs
#' @return Invisible \code{NULL}.
#' @export
robyn_csv <- function(OutputCollect, csv_out = NULL, export = TRUE) {
robyn_csv <- function(InputCollect, OutputCollect, csv_out = NULL, export = TRUE) {
if (export) {
check_class("robyn_outputs", OutputCollect)
temp_all <- OutputCollect$allPareto
Expand All @@ -222,6 +223,7 @@ robyn_csv <- function(OutputCollect, csv_out = NULL, export = TRUE) {
write.csv(temp_all$xDecompAgg, paste0(OutputCollect$plot_folder, "all_aggregated.csv"))
}
if (!is.null(csv_out)) {
write.csv(InputCollect$dt_input, paste0(OutputCollect$plot_folder, "raw_data.csv"))
write.csv(OutputCollect$mediaVecCollect, paste0(OutputCollect$plot_folder, "pareto_media_transform_matrix.csv"))
write.csv(OutputCollect$xDecompVecCollect, paste0(OutputCollect$plot_folder, "pareto_alldecomp_matrix.csv"))
}
Expand Down

0 comments on commit c1d9c35

Please sign in to comment.