write_diagram()
generates code in the form of a stand-alone R script to
produce a diagram. By editing the generated code, the user can
make manual adjustments to the diagram.
write_diagram(
diagram_list = NULL,
directory = "./",
filename = "diagram_code.R",
always_overwrite = FALSE
)
A flowdiagramr input structure, resulting from
a call to prepare_diagram
. See Details
below.
File directory in which to save the produced R file. Default location is the current working directory.
Name of the file, must end in '.R'. Default name is 'diagram_code.R'.
A logical indicating if you want to skip being asked if you want to overwrite an already existing file. Default is FALSE. Change to TRUE at own risk.
R code written to a file as specified by settings. Also, a message is returned telling the user where the file is.
You need to supply at least one of model_list
or diagram_list
. If you supply both, model_list
is included in the
resulting R file, but it is not used. Including it can be good just so
you have the complete model specification in one script.
if (FALSE) {
varlabels <- c("S","I","R")
varnames <- c("Susceptible","Infected","Recovered") # optional
flows <- list(S_flows = c("-b*S*I"),
I_flows = c("b*S*I","-g*I"),
R_flows = c("g*I"))
varlocations <- matrix(data = c("S", "", "R", "", "I", "" ),
nrow = 2, ncol = 3, byrow = TRUE)
model_list <- list(varlabels = varlabels, varnames = varnames,
flows = flows, varlocations = varlocations)
diagram_list <- prepare_diagram(model_list = model_list)
# generate R code from model_list
write_diagram(model_list = model_list)
# generate R code from diagram_list
write_diagram(diagram_list = diagram_list)
#' # generate R code from both
write_diagram(model_list = model_list, diagram_list = diagram_list)
}