% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/export_model.R
\name{export_model}
\alias{export_model}
\title{Export a stock-and-flow model}
\usage{
export_model(
  object,
  format = c("sdbuildR", "deSolve", "psychomodels"),
  file = NULL,
  title = object[["meta"]][["name"]],
  description = object[["meta"]][["caption"]],
  explanation = description,
  publication_doi = "",
  publication_citation = "",
  framework = "Ordinary Differential Equations",
  programming_language = "R",
  psychology_discipline = "",
  software_package = "",
  model_variable = "",
  code_repository_url = "",
  data_url = "",
  submission_remarks = "",
  created_by = "",
  updated_by = "",
  published_by = "",
  published_at = Sys.time(),
  published_pending_moderation_at = Sys.time(),
  publication_citation_fetched_at = Sys.time(),
  publication_csl_fetched_at = Sys.time(),
  publication_csl_json = "",
  id = NA,
  slug = NULL,
  include_latex = TRUE,
  pretty = TRUE
)
}
\arguments{
\item{object}{Stock-and-flow model, object of class \code{\link{stockflow}}.}

\item{format}{Export format. One of \code{"sdbuildR"}, \code{"deSolve"}, or
\code{"psychomodels"}.}

\item{file}{Output file path, or \code{NULL} to return the result directly.}

\item{title}{[psychomodels] Model title. Defaults to \code{object[["meta"]][["name"]]}.}

\item{description}{[psychomodels] Model description.
Defaults to \code{object[["meta"]][["caption"]]}.}

\item{explanation}{[psychomodels] Free-text explanation. Defaults to \code{description}.}

\item{publication_doi}{[psychomodels] DOI for the associated publication.}

\item{publication_citation}{[psychomodels] Citation text.}

\item{framework}{[psychomodels] Modeling framework.
Defaults to \code{"Ordinary Differential Equations"}.}

\item{programming_language}{[psychomodels] Programming language.}

\item{psychology_discipline}{[psychomodels] Discipline id(s), comma-separated.}

\item{software_package}{[psychomodels] Package id(s), comma-separated.}

\item{model_variable}{[psychomodels] Variable id(s), comma-separated.}

\item{code_repository_url}{[psychomodels] URL to code repository.}

\item{data_url}{[psychomodels] URL to model data.}

\item{submission_remarks}{[psychomodels] Optional remarks.}

\item{created_by}{[psychomodels] Identifier of creating user.}

\item{updated_by}{[psychomodels] Identifier of last updating user.}

\item{published_by}{[psychomodels] Identifier of publishing user.}

\item{published_at}{[psychomodels] Publication timestamp. Defaults to current time.}

\item{published_pending_moderation_at}{[psychomodels] Moderation timestamp.}

\item{publication_citation_fetched_at}{[psychomodels] Citation fetch timestamp.}

\item{publication_csl_fetched_at}{[psychomodels] CSL fetch timestamp.}

\item{publication_csl_json}{[psychomodels] CSL JSON text.}

\item{id}{[psychomodels] Optional record id.}

\item{slug}{[psychomodels] Optional slug. Generated from \code{title} if \code{NULL}.}

\item{include_latex}{[psychomodels] If \code{TRUE}, append LaTeX equations to explanation.}

\item{pretty}{[psychomodels] If \code{TRUE}, pretty-print output JSON.}
}
\value{
For \code{file = NULL}: a character string containing the exported content.
For \code{file} specified: invisibly returns the file path.
}
\description{
Export a model of class \code{\link{stockflow}} to another format.
}
\details{
\subsection{sdbuildR format (\code{format = "sdbuildR"})}{

Returns R code that reconstructs the model using sdbuildR functions.
When \code{file = NULL}, returns a character string.
When \code{file} is provided, writes an \code{.R} file and returns the path invisibly.
If \code{file} has no \code{.R} extension, one is appended.
}

\subsection{deSolve format (\code{format = "deSolve"})}{

Returns a standalone R script using \code{\link[deSolve:ode]{deSolve::ode()}} directly — no sdbuildR
dependency required to run the output.
When \code{file = NULL}, returns a character string.
When \code{file} is provided, writes an \code{.R} file and returns the path invisibly.
If \code{file} has no \code{.R} extension, one is appended.
Requires \code{sim_settings(language = "R")} (the default).
}

\subsection{Psychomodels format (\code{format = "psychomodels"})}{

Generates a JSON record for upload to
\href{https://www.psychomodels.org/models/}{Psychomodels}.
When \code{file = NULL}, returns a JSON character string.
When \code{file} is provided, writes a \code{.json} file and returns the path invisibly.
If \code{file} has no \code{.json} extension, one is appended.
}
}
\examples{
sfm <- stockflow("sir")

# Get sdbuildR reconstruction code
cat(export_model(sfm, format = "sdbuildR"))

# Get standalone deSolve script
cat(export_model(sfm, format = "deSolve"))

# Export to Psychomodels JSON
\dontrun{
json <- export_model(sfm,
  format = "psychomodels",
  publication_doi = "10.0000/example"
)
}
}
\seealso{
\code{\link[=import_insightmaker]{import_insightmaker()}}, \code{\link[=import_desolve]{import_desolve()}}
}
\concept{importExport}
