Skip to content

Commit

Permalink
Merge pull request #5 from BiologicalRecordsCentre/metadata
Browse files Browse the repository at this point in the history
Metadata slot and functions writing data to the slot closes #3
  • Loading branch information
simonrolph authored Apr 10, 2024
2 parents 8f658b1 + 030c97d commit 77df3de
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/SimulationObjectClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ setClass("SimulationObject",
effort = "ANY",
detect = "ANY",
report = "ANY",
metadata = "ANY",
hash = "ANY"
)
)
Expand All @@ -22,6 +23,7 @@ SimulationObject <- function(background, state_env = NULL, state_target_suitabil
effort = effort,
detect = detect,
report = report,
metadata = list(),
hash = NULL)

new("SimulationObject",
Expand All @@ -32,6 +34,7 @@ SimulationObject <- function(background, state_env = NULL, state_target_suitabil
effort = effort,
detect = detect,
report = report,
metadata = list(),
hash = hash_sim_obj(tmp)
)
}
2 changes: 2 additions & 0 deletions R/sim_detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sim_detect <- function(simulation_object, fun, ...) {
detections <- fun(simulation_object, ...)

# validity checks
fun_args <- as.list(match.call())
simulation_object_original@metadata[["detect"]] <- fun_args[3:length(fun_args)]

simulation_object_original@detect <- detections
simulation_object_original@hash <- hash_sim_obj(simulation_object_original)
Expand Down
2 changes: 2 additions & 0 deletions R/sim_effort.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sim_effort <- function(simulation_object, fun, ...) {
effort <- fun(simulation_object, ...)

# validity checks
fun_args <- as.list(match.call())
simulation_object_original@metadata[["effort"]] <- fun_args[3:length(fun_args)]

simulation_object_original@effort <- effort
simulation_object_original@hash <- hash_sim_obj(simulation_object_original)
Expand Down
2 changes: 2 additions & 0 deletions R/sim_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sim_report <- function(simulation_object, fun, ...) {
report <- fun(simulation_object, ...)

# validity checks
fun_args <- as.list(match.call())
simulation_object_original@metadata[["report"]] <- fun_args[3:length(fun_args)]

simulation_object_original@report <- report
simulation_object_original@hash <- hash_sim_obj(simulation_object_original)
Expand Down
4 changes: 4 additions & 0 deletions R/sim_state_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ sim_state_env <- function(simulation_object, fun= NULL, filename = NULL, spatras
#create hash, having set the hash to NULL
simulation_object_original@hash <- hash_sim_obj(simulation_object_original)

#set metadata
fun_args <- as.list(match.call())
simulation_object_original@metadata[["state_env"]] <- fun_args[3:length(fun_args)]

# Return the updated simulation_object
return(simulation_object_original)
}
3 changes: 3 additions & 0 deletions R/sim_state_target_realise.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ sim_state_target_realise <- function(simulation_object,fun, filename=NULL, ...)
realised <- write_raster_return_filename(realised,filename)
}

fun_args <- as.list(match.call())
simulation_object_original@metadata[["state_target_realised"]] <- fun_args[3:length(fun_args)]

simulation_object_original@state_target_realised <- realised
simulation_object_original@hash <- hash_sim_obj(simulation_object_original)
simulation_object_original
Expand Down
3 changes: 3 additions & 0 deletions R/sim_state_target_suitability.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ sim_state_target_suitability <- function(simulation_object,fun,filename = NULL,
suitability <- write_raster_return_filename(suitability,filename)
}

fun_args <- as.list(match.call())
simulation_object_original@metadata[["state_target_suitability"]] <- fun_args[3:length(fun_args)]

simulation_object_original@state_target_suitability <- suitability
simulation_object_original@hash <- hash_sim_obj(simulation_object_original)
simulation_object_original
Expand Down

0 comments on commit 77df3de

Please sign in to comment.