# Invoke Mplus and save output
#' Run Mplus and save full output
#'
#' [MplusAutomation::mplusModeler()] runs Mplus and augments the
#' `mplusObject` with a `$results` element.
#' This wrapper saves the full text output from Mplus in an element named
#' `$stdout` within that `$results` element.
#'
#' This function has side-effects, just like [MplusAutomation::mplusModeler()],
#' in that it leaves Mplus input, output, and savedata files in the current
#' directory.
#'
#' @param .obj mplusObject as created by [MplusAutomation::mplusObject()]
#' @param name basename for generated Mplus files (no extension)
#' @param run set to 0 for dry-run (passed to [MplusAutomation::mplusModeler()])
#' @param ... additional options passed to [MplusAutomation::mplusModeler()]
#' @return an `mplusObject` with a `$results` section
#'
#' @importFrom utils capture.output
#' @importFrom MplusAutomation mplusModeler
#'
#' @export
#' @family Invocation of Mplus
#'
mplus <- function(.obj, name = "mp", run = 1, ...) {
out <- utils::capture.output({
suppressMessages({
res <- MplusAutomation::mplusModeler(
.obj, dataout = paste0(name, ".dat"), run = run, ...)
})
})
res$results$stdout <- out
res$results$tech4 <- parse_tech4(readLines(paste0(name, ".out")))
res
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.