Learn R Programming

sdbuildR (version 2.0.0)

change_name: Change name of variable

Description

Change the name of a variable throughout the model. This updates the data frame and all references in equations, flow connections, and labels.

Usage

change_name(object, name, new_name)

Value

A stock-and-flow model object of class stockflow with the name changed throughout the model.

Arguments

object

Stock-and-flow model, object of class stockflow.

name

Variable name. Accepts a bare symbol (e.g., population), a string ("population"), or a vector via c() (e.g., c(a, b) or c("a", "b")). Use !! to inject from a variable.

new_name

New name. Character vector of the same length as name. Must be unique across all existing variables.

See Also

update(), discard()

Examples

Run this code
sfm <- stockflow("SIR")
sfm <- change_name(sfm, c(susceptible, infected, recovered),
  new_name = c(S, I, R)
)
print(sfm)

# References to old names are updated
as.data.frame(sfm, type = "flow", properties = c("name", "eqn", "to", "from"))

Run the code above in your browser using DataLab