Learn R Programming

sdbuildR (version 2.0.0)

export_model: Export a stock-and-flow model

Description

Export a model of class stockflow to another format.

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
)

Value

For file = NULL: a character string containing the exported content. For file specified: invisibly returns the file path.

Arguments

object

Stock-and-flow model, object of class stockflow.

format

Export format. One of "sdbuildR", "deSolve", or "psychomodels".

file

Output file path, or NULL to return the result directly.

title

[psychomodels] Model title. Defaults to object[["meta"]][["name"]].

description

[psychomodels] Model description. Defaults to object[["meta"]][["caption"]].

explanation

[psychomodels] Free-text explanation. Defaults to description.

publication_doi

[psychomodels] DOI for the associated publication.

publication_citation

[psychomodels] Citation text.

framework

[psychomodels] Modeling framework. Defaults to "Ordinary Differential Equations".

programming_language

[psychomodels] Programming language.

psychology_discipline

[psychomodels] Discipline id(s), comma-separated.

software_package

[psychomodels] Package id(s), comma-separated.

model_variable

[psychomodels] Variable id(s), comma-separated.

code_repository_url

[psychomodels] URL to code repository.

data_url

[psychomodels] URL to model data.

submission_remarks

[psychomodels] Optional remarks.

created_by

[psychomodels] Identifier of creating user.

updated_by

[psychomodels] Identifier of last updating user.

published_by

[psychomodels] Identifier of publishing user.

published_at

[psychomodels] Publication timestamp. Defaults to current time.

published_pending_moderation_at

[psychomodels] Moderation timestamp.

publication_citation_fetched_at

[psychomodels] Citation fetch timestamp.

publication_csl_fetched_at

[psychomodels] CSL fetch timestamp.

publication_csl_json

[psychomodels] CSL JSON text.

id

[psychomodels] Optional record id.

slug

[psychomodels] Optional slug. Generated from title if NULL.

include_latex

[psychomodels] If TRUE, append LaTeX equations to explanation.

pretty

[psychomodels] If TRUE, pretty-print output JSON.

Details

sdbuildR format (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.

deSolve format (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).

Psychomodels format (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.

See Also

import_insightmaker(), import_desolve()

Examples

Run this code
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