Learn R Programming

sdbuildR (version 2.0.0)

discard: Remove variable(s)

Description

Remove variable(s) from a stock-and-flow model. All references in flow connections and graphical function sources are also removed. A warning will be thrown if any lingering references to the removed name remain in the model.

Usage

discard(
  object,
  name,
  remove_references = c("to", "from", "source", "unit_test")
)

Value

A stock-and-flow model object of class stockflow

Arguments

object

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

name

Name(s) to remove. Accepts bare symbols (e.g., x), strings, or vectors via c(). Must be variable names.

remove_references

Where to remove references to the discarded variables. By default, references to discarded variables in "to", "from", "source", and "unit_test" are removed. Set to NULL to keep all references (not recommended). Note that any lingering references in equations will cause errors in simulation and should be removed or updated with update() after discarding the variable.

See Also

update(), change_name()

Examples

Run this code
# Add stock
sfm <- stockflow() |> stock(x)
print(sfm)

# Remove stock
sfm <- discard(sfm, x)
print(sfm)

Run the code above in your browser using DataLab