Skip to content

Commit

Permalink
fixed issues with global variables, paths, and makeing sure target ou…
Browse files Browse the repository at this point in the history
…tputs update with new file paths
  • Loading branch information
collinschwantes committed Jun 7, 2022
1 parent 35427ad commit 9a4f9ef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
4 changes: 3 additions & 1 deletion 1- Run RVFV Simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ vxp <- (unlist(param_vec["vax"])/(unlist(param_vec["muL"])+ unlist(param_vec["g"

save.image(file = rdata_path)

return("RVFV Sim")
return_value <- paste("RVFV Sim:",run_path_target,sep = " ")

return(return_value)

}

6 changes: 3 additions & 3 deletions 2_RVF_LHC_Sensitivity_Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# library(here)
RVF_LHC_SA <- function(target, h = 4000){
#Set scenario
SA <- TRUE
h <- h #Number of simulations to run in sensitivity anlaysis
SA <<- TRUE
h <<- h #Number of simulations to run in sensitivity analysis

#Source data and code
#Functions for setting the hatching switches the data
Expand All @@ -48,7 +48,7 @@ model_run_path <- target

#Set timing
start.time <- 0
end.time <- nrow(All_Precip)
end.time <<- nrow(All_Precip)
timestep <- 1
times <- seq(from = start.time,
to = end.time,
Expand Down
10 changes: 5 additions & 5 deletions 3- Calculate and Plot_R0.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pts$X <- R0params[x]
if(!names(R0params[x])=="biteA"){
stop()
}
plot.biteA <- ggplot()+#
plot.biteA <<- ggplot()+#
geom_line(data = df_plot, aes(x = Value, y = R0_both, col = "1B"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_A, col = "2A"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_C, col = "3C"), size = 1, alpha = .5, linetype = "dashed") +
Expand All @@ -132,7 +132,7 @@ pts$X <- R0params[x]
if(!names(R0params[x])=="q"){
stop()
}
plot.q <- ggplot()+#
plot.q <<- ggplot()+#
geom_line(data = df_plot, aes(x = Value, y = R0_both, col = "1B"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_A, col = "2A"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_C, col = "3C"), size = 1, alpha = .5, linetype = "dashed") +
Expand All @@ -155,7 +155,7 @@ pts$X <- R0params[x]
if(!names(R0params[x])=="Tcsl"){
stop()
}
plot.Tcsl <- ggplot()+#
plot.Tcsl <<- ggplot()+#
geom_line(data = df_plot, aes(x = Value, y = R0_both, col = "1B"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_A, col = "2A"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_C, col = "3C"), size = 1, alpha = .5, linetype = "dashed") +
Expand All @@ -178,7 +178,7 @@ pts$X <- R0params[x]
if(!names(R0params[x])=="muC"){
stop()
}
plot.muC <- ggplot()+#
plot.muC <<- ggplot()+#
geom_line(data = df_plot, aes(x = Value, y = R0_both, col = "1B"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_A, col = "2A"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_C, col = "3C"), size = 1, alpha = .5, linetype = "dashed") +
Expand All @@ -201,7 +201,7 @@ pts$X <- R0params[x]
if(!names(R0params[x])=="biteC"){
stop()
}
plot.biteC <- ggplot()+#
plot.biteC <<- ggplot()+#
geom_line(data = df_plot, aes(x = Value, y = R0_both, col = "1B"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_A, col = "2A"), size = 1, alpha = .5, linetype = "dashed") +
geom_line(data = df_plot, aes(x = Value, y = R0_C, col = "3C"), size = 1, alpha = .5, linetype = "dashed") +
Expand Down
19 changes: 12 additions & 7 deletions Functions/Function 7 Manage model outputs.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## create folder for outputs from hash of params vector


get_run_id <- function(){
rlang::hash(Sys.time())
get_run_id <- function(value = Sys.time()){
rlang::hash(value)
}

create_model_folders <- function(run_id,overwrite = FALSE){
folder_path <- sprintf("%s/%s", "model_runs", run_id)
dir.create(folder_path,recursive = TRUE)

## Create set of subfolders for different outputs ----
sub_folders <- c("Publication_Figures/Draft_Figures","Data for sensistivity analysis" )
sub_folders <- c("Publication_Figures/Draft_Figures","Data for sensitivity analyses" )

for(folder in sub_folders){
sub_folder_path <- sprintf("%s/%s", folder_path, folder)
Expand All @@ -25,8 +25,8 @@ write_model_run_path <- function(folder_path){
saveRDS(object = folder_path,"model_runs/current_run_path.RDS")
}

create_model_run_path <- function(){
run_id <- get_run_id()
create_model_run_path <- function(value = Sys.time()){
run_id <- get_run_id(value)
print(sprintf("Model run id: %s", run_id))

folder_path <- create_model_folders(run_id)
Expand All @@ -47,10 +47,15 @@ read_model_run_path <- function(){

delete_model_run_path <- function(target,...){
dep_obj <- paste(target,...,collapse = ", ")
pathRemoved <- readRDS("model_runs/current_run_path.RDS")
unlink("model_runs/current_run_path.RDS")
message("Current_run_path.RDS removed.
message(glue::glue("Current_run_path.RDS removed.
Any outputs were saved in {pathRemoved}
Use set_model_run_path to interactively
set the model run path")
set the model run path"))


return("current_run_path.RDS removed")
}

Expand Down
4 changes: 2 additions & 2 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ list(
),
tar_target(
name = b_LHC_SA,
command = RVF_LHC_SA(Create_Run_Path, h = 1),
cue = targets::tar_cue("never") ## takes around 100hrs on 8 core machine
command = RVF_LHC_SA(Create_Run_Path, h = 1)
#cue = targets::tar_cue("never") ## 4k sims takes around 100hrs on 8 core machine
),
tar_target(
name = c_Calc_Plot_R0,
Expand Down

0 comments on commit 9a4f9ef

Please sign in to comment.