write_diagram: Generate a reproducible R script to make the diagram.

View source: R/write_diagram.R

write_diagramR Documentation

Generate a reproducible R script to make the diagram.

Description

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.

Usage

write_diagram(
  diagram_list = NULL,
  directory = "./",
  filename = "diagram_code.R",
  always_overwrite = FALSE
)

Arguments

diagram_list

A flowdiagramr input structure, resulting from a call to prepare_diagram. See Details below.

directory

File directory in which to save the produced R file. Default location is the current working directory.

filename

Name of the file, must end in '.R'. Default name is 'diagram_code.R'.

always_overwrite

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.

Details

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.

Value

R code written to a file as specified by settings. Also, a message is returned telling the user where the file is.

Examples

## Not run: 
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)

## End(Not run)

andreashandel/modeldiagram documentation built on July 31, 2023, 10:05 a.m.