Skip to contents

Lookup variables define piecewise relationships using specified (x, y) points. lookup() adds or changes a lookup variable. This is a convenience wrapper around update() with type = "lookup". See the Lookup Variables section of update() for more details.

Usage

lookup(
  object,
  name,
  xpts,
  ypts,
  source = NULL,
  interpolation = "linear",
  extrapolation = "nearest",
  label = name,
  doc = "",
  non_negative = FALSE
)

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.

xpts

Only for graphical functions: vector of x-domain points. Must be of the same length as ypts.

ypts

Only for graphical functions: vector of y-domain points. Must be of the same length as xpts.

source

Only for graphical functions: name of the variable which will serve as the input to the graphical function. Accepts a bare symbol or string. Defaults to NULL.

interpolation

Only for graphical functions: interpolation method. Must be either "constant" or "linear". Defaults to "linear".

extrapolation

Only for graphical functions: extrapolation method. Must be either "nearest" or "NA". Defaults to "nearest".

label

Name of variable used for plotting. Defaults to the same as name.

doc

Description of variable. Defaults to "" (no description).

non_negative

If TRUE, variable is enforced to be non-negative (i.e., strictly 0 or positive). Defaults to FALSE.

Value

A stock-and-flow model object of class stockflow

Examples

# Create a lookup variable for a non-linear relationship
sfm <- stockflow() |>
  lookup(output,
    source = t,
    xpts = c(0, 5, 10),
    ypts = c(0, 10, 15),
    interpolation = "linear"
  ) |>
  stock(x) |>
  flow(x_in, eqn = output(t), to = x)

sim <- simulate(sfm)
plot(sim)