Export a model of class stockflow to another format.
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
)For file = NULL: a character string containing the exported content.
For file specified: invisibly returns the file path.
Stock-and-flow model, object of class stockflow.
Export format. One of "sdbuildR", "deSolve", or
"psychomodels".
Output file path, or NULL to return the result directly.
[psychomodels] Model title. Defaults to object[["meta"]][["name"]].
[psychomodels] Model description.
Defaults to object[["meta"]][["caption"]].
[psychomodels] Free-text explanation. Defaults to description.
[psychomodels] DOI for the associated publication.
[psychomodels] Citation text.
[psychomodels] Modeling framework.
Defaults to "Ordinary Differential Equations".
[psychomodels] Programming language.
[psychomodels] Discipline id(s), comma-separated.
[psychomodels] Package id(s), comma-separated.
[psychomodels] Variable id(s), comma-separated.
[psychomodels] URL to code repository.
[psychomodels] URL to model data.
[psychomodels] Optional remarks.
[psychomodels] Identifier of creating user.
[psychomodels] Identifier of last updating user.
[psychomodels] Identifier of publishing user.
[psychomodels] Publication timestamp. Defaults to current time.
[psychomodels] Moderation timestamp.
[psychomodels] Citation fetch timestamp.
[psychomodels] CSL fetch timestamp.
[psychomodels] CSL JSON text.
[psychomodels] Optional record id.
[psychomodels] Optional slug. Generated from title if NULL.
[psychomodels] If TRUE, append LaTeX equations to explanation.
[psychomodels] If TRUE, pretty-print output JSON.
format = "sdbuildR")
Returns R code that reconstructs the model using sdbuildR functions.
When file = NULL, returns a character string.
When file is provided, writes an .R file and returns the path invisibly.
If file has no .R extension, one is appended.
format = "deSolve")
Returns a standalone R script using deSolve::ode() directly — no sdbuildR
dependency required to run the output.
When file = NULL, returns a character string.
When file is provided, writes an .R file and returns the path invisibly.
If file has no .R extension, one is appended.
Requires sim_settings(language = "R") (the default).
format = "psychomodels")
Generates a JSON record for upload to
Psychomodels.
When file = NULL, returns a JSON character string.
When file is provided, writes a .json file and returns the path invisibly.
If file has no .json extension, one is appended.
import_insightmaker(), import_desolve()
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
if (FALSE) {
json <- export_model(sfm,
format = "psychomodels",
publication_doi = "10.0000/example"
)
}
Run the code above in your browser using DataLab