% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/update.R
\name{custom_func}
\alias{custom_func}
\title{Create or modify custom variables or functions}
\usage{
custom_func(object, name, eqn = 0, label = name, doc = "")
}
\arguments{
\item{object}{Stock-and-flow model, object of class \code{\link{stockflow}}.}

\item{name}{Name of the function variable. The equation will be assigned to this name.}

\item{eqn}{Equation of the function variable. A character vector. Defaults to \code{0}.}

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

\item{doc}{Documentation. Defaults to "".}
}
\value{
A stock-and-flow model object of class \code{\link{stockflow}}
}
\description{
Custom functions are user-defined functions that can be used
throughout a stock-and-flow model. \code{\link[=custom_func]{custom_func()}} adds or changes a function. This is a convenience wrapper around \code{\link[=update]{update()}} with
\code{type = "func"}.
}
\examples{

# Simple function
sfm <- stockflow() |>
  custom_func(double, eqn = "function(x) x * 2") |>
  constant(a, eqn = double(2))

# Function with defaults
sfm <- stockflow() |>
  custom_func(scale, eqn = "function(x, factor = 10) x * factor") |>
  constant(b, eqn = scale(2))

# If the logistic() function did not exist, you could create it yourself:
sfm <- stockflow() |>
  custom_func(my_logistic, eqn = "function(x, slope = 1, midpoint = .5){
   1 / (1 + exp(-slope*(x-midpoint)))
 }") |>
  constant(c_, eqn = my_logistic(2, slope = 50))

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