% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/update.R
\name{lookup}
\alias{lookup}
\title{Add or modify lookup variables (graphical functions)}
\usage{
lookup(
  object,
  name,
  xpts,
  ypts,
  source = NULL,
  interpolation = "linear",
  extrapolation = "nearest",
  label = name,
  doc = "",
  non_negative = FALSE
)
}
\arguments{
\item{object}{Stock-and-flow model, object of class \code{\link{stockflow}}.}

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

\item{xpts}{Only for graphical functions: vector of x-domain points. Must be of the same length as ypts.}

\item{ypts}{Only for graphical functions: vector of y-domain points. Must be of the same length as xpts.}

\item{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 \code{NULL}.}

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

\item{extrapolation}{Only for graphical functions: extrapolation method. Must be either \code{"nearest"} or \code{"NA"}. Defaults to \code{"nearest"}.}

\item{label}{Name of variable used for plotting. Defaults to the same as name.}

\item{doc}{Description of variable. Defaults to \code{""} (no description).}

\item{non_negative}{If TRUE, variable is enforced to be non-negative (i.e., strictly 0 or positive). Defaults to \code{FALSE}.}
}
\value{
A stock-and-flow model object of class \code{\link{stockflow}}
}
\description{
Lookup variables define piecewise relationships using specified (x, y) points. \code{\link[=lookup]{lookup()}} adds or changes a lookup variable. This is a convenience wrapper around \code{\link[=update]{update()}} with \code{type = "lookup"}. See the \strong{Lookup Variables} section of \code{\link[=update]{update()}} for more details.
}
\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)

}
\seealso{
\code{\link[=update.stockflow]{update()}}, \code{\link[=discard]{discard()}}, \code{\link[=change_name]{change_name()}}
}
\concept{build}
