Skip to content

Commit

Permalink
add simulate_result as external object
Browse files Browse the repository at this point in the history
  • Loading branch information
emitanaka committed Oct 14, 2023
1 parent a1be5cc commit 3c03a77
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions R/design.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ design <- function(title = NULL, name = "edibble", .record = TRUE, seed = NULL,
anatomy = NULL,
recipe = NULL,
simulate = list(),
simulate_result = list(),
context = NULL),
class = c("edbl_design", "edbl"))
}
Expand Down
2 changes: 1 addition & 1 deletion R/graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' activate_provenance(takeout())
#' @export
activate_provenance <- function(.edibble,
overwrite = c("graph", "anatomy", "recipe", "validation", "simulate")) {
overwrite = c("graph", "anatomy", "recipe", "validation", "simulate", "simulate_result")) {
des <- edbl_design(.edibble)
prov <- des$provenance
if(!is_environment(prov)) {
Expand Down
10 changes: 7 additions & 3 deletions R/provenance.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,20 @@ Provenance <- R6::R6Class("Provenance",
rcrds = rcrds)
},


#' @description
#' Reactivate the graph in the provenance object.
#' @param design An edibble design
#' @param overwrite A vector of character to overwrite from the
#' supplied design object.
reactivate = function(design, overwrite = c("graph", "anatomy", "recipe", "validation", "simulate")) {
reactivate = function(design, overwrite = c("graph", "anatomy", "recipe", "validation", "simulate", "simualte_result")) {
#private$record_track_internal()
for(obj in overwrite) {
private[[obj]] <- design[[obj]]
if(obj=="simulate_result") {
private$simulate_result_env <- new_environment()
list2env(design[[obj]], envir = private$simulate_result_env)
} else {
private[[obj]] <- design[[obj]]
}
}
},

Expand Down
9 changes: 7 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ return_edibble_with_graph <- function(edibble, prov) {
des$graph <- prov$get_graph()
des$validation <- prov$get_validation()
des$simulate <- prov$get_simulate()
sim_res <- ls(envir = prov$get_simulate_result_env())
if(length(sim_res)) {
des$simulate_result <- mget(sim_res, prov$get_simulate_result_env())
}
if(is_edibble_table(edibble)) {
attr(edibble, "design") <- des
edibble
Expand Down Expand Up @@ -415,7 +419,8 @@ print.edbl_fct <- function(x, ...) {
# anatomy,
# simulate,
# context
e1 <- return_edibble_with_graph(e1, prov1)
des2 <- edbl_design(e2)
for(code in des2$recipe) e1 <- add_edibble_code(e1, code)
return_edibble_with_graph(e1, prov1)
for(code in des2$recipe[-1]) e1 <- add_edibble_code(e1, code)
e1
}

0 comments on commit 3c03a77

Please sign in to comment.