template: Create a template for use in diyPaths

View source: R/diyPaths.R

templateR Documentation

Create a template for use in diyPaths

Description

Takes your fitted model and prints a ready-to-run starting template (node list, path list, title list, note list, and diyPaths() call) to the console. Copy the output into your script, then fine-tune the diagram by adjusting values in the lines marked ⁠#EDIT ME!⁠

The template is also returned invisibly as a character string, so it can be stored as an object then viewed with writeLines() (see examples).

Usage

template(
  fit,
  include_variance_paths = TRUE,
  diyPaths_arguments = c("max", "min"),
  quiet = FALSE
)

Arguments

fit

A fitted model object of class lavaan.

include_variance_paths

Logical. Whether to include variance/residual paths in the path list. Default is TRUE.

diyPaths_arguments

Use either "max" (the printed call shows every diyPaths() argument) or "min" (only the required arguments). Default is "max".

quiet

Logical. If TRUE, the template is not printed to the console and is only returned invisibly. Default is FALSE.

Value

Invisibly returns the template as a single character string. Unless quiet = TRUE, it is also printed to the console.

See Also

diyPaths() to render the diagram from the template; node(), path(), panel_title(), and panel_note() for the helper functions the template uses.

Examples


library(lavaan)

data(HolzingerSwineford1939, package = "lavaan")


#specify the model

sem_model <- '
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9

  speed ~ visual + textual
  visual ~~ textual
'

#fit the model

fit <- sem(sem_model, data = HolzingerSwineford1939)

#print the maximal template to the console

# template(fit = fit, include_variance_paths = TRUE, diyPaths_arguments = "max", quiet = FALSE)

#store the template without printing it, then view it

tmpl <- template(fit = fit, diyPaths_arguments = "min", quiet = TRUE)
writeLines(tmpl)

diy.sem.plot documentation built on Nov. 11, 2026, 1:11 a.m.