lav_step17_lavaan <- function(lavmc = NULL,
                              timing = NULL,
                              lavoptions = NULL,
                              lavpartable = NULL,
                              lavdata = NULL,
                              lavsamplestats = NULL,
                              lavmodel = NULL,
                              lavcache = NULL,
                              lavfit = NULL,
                              lavboot = NULL,
                              lavoptim = NULL,
                              lavimplied = NULL,
                              lavloglik = NULL,
                              lavvcov = NULL,
                              lavtest = NULL,
                              lavh1 = NULL,
                              lavbaseline = NULL,
                              laveqs = NULL,
                              start_time0 = NULL,
                              lav_monte_carlo = NULL) {
  # # # # # # # # # #
  # #  17. lavaan # #
  # # # # # # # # # #

  # stop timer
  # create lavaan object
  # if lavmodel@nefa > 0
  #   compute standardizedSolution and store in ParTable slot in lavaan object
  # if post-checking demanded and converged, execute
  #   lavInspect(lavaan, "post.check")
  #
  timing$total <- (proc.time()[3] - start_time0)
  timing$start.time <- NULL
  lavpta <- lav_pt_attributes(lavpartable)
  lavpartable <- lav_pt_remove_cache(lavpartable)
  lavaan <- new("lavaan", # type_of_slot - where created or modified ?
    # ------------   ------------------------- -
    version = packageDescription("lavaan", fields = "Version"),
    call = lavmc, # match.call - lav_step00_parameters
    timing = timing, # list - ldw_add_timing
    Options = lavoptions, # list - options (2) / data (3) / partable (4)
    ParTable = lavpartable,
    # list - partable/bounds/start/model/estoptim/vcovboot/rotation
    pta = lavpta, # list - lav_partable_attributes
    Data = lavdata, # S4 class - data (3)
    SampleStats = lavsamplestats, # S4 class - samplestats (5)
    Model = lavmodel, # S4 class - model (9) / estoptim (11) / vcovboot (13)
    Cache = lavcache, # list - cache (10)
    Fit = lavfit, # S4 class - lav_model_fit (14bis)
    boot = lavboot, # list - vcovboot (13)
    optim = lavoptim, # list - estoptim (11)
    implied = lavimplied, # list - lav_model_implied (12)
    loglik = lavloglik, # list - lav_model_loglik (12)
    vcov = lavvcov, # list - vcovboot (13)
    test = lavtest, # list - test (14)
    h1 = lavh1, # list - h1 (6)
    baseline = lavbaseline, # list - baseline (15)
    internal = if (is.null(lav_monte_carlo) || length(lav_monte_carlo) == 0L) {
      list()
    } else {
      list(monte.carlo = lav_monte_carlo)
    },
    external = list() # empty list
  )

  # if model.type = "efa", add standardized solution to partable
  if (lavmodel@nefa > 0L) {
    if (lav_verbose()) {
      cat("computing standardized solution ... ")
    }
    std <- standardizedSolution(lavaan,
      remove_eq = FALSE,
      remove_ineq = FALSE, remove_def = FALSE
    )
    if (lav_verbose()) {
      cat(" done.\n")
    }
    lavaan@ParTable$est.std <- std$est.std
  if (!is.null(std$se)) {
      lavaan@ParTable$se.std <- std$se
    }
  }

  # eqs?
  if (length(laveqs) > 0L) {
    lavaan@internal$eqs <- laveqs
  }

  # post-fitting check of parameters
  if (!is.null(lavoptions$check.post) && lavoptions$check.post &&
    lavTech(lavaan, "converged")) {
    if (lav_verbose()) {
      cat("post check  ...")
    }
    lavInspect(lavaan, "post.check")
    if (lav_verbose()) {
      cat(" done.\n")
    }
  }

  lavaan
}
