michaelhallquist / MplusAutomation

The MplusAutomation package leverages the flexibility of the R language to automate latent variable model estimation and interpretation using Mplus, a powerful latent variable modeling program developed by Muthen and Muthen (www.statmodel.com). Specifically, MplusAutomation provides routines for creating related groups of models, running batches of models, and extracting and tabulating model parameters and fit statistics.
84 stars 46 forks source link

Check for whether MPlus is installed? #76

Closed jrosen48 closed 6 years ago

jrosen48 commented 6 years ago

Is there a way or a way to check whether MPlus is installed on a user's computer? I'm one of the authors of a package that depends upon MplusAutomation (tidyLPA) and on occasion folks don't realize they don't have MPlus on the computer they're using. It would be nice to write a message or stop() function that addresses this.

cjvanlissa commented 6 years ago

Have you checked how MplusAutomation handles this?

jrosen48 commented 6 years ago

I checked for a function and in the code but couldn't find it. Can you point me in the right direction?

cjvanlissa commented 6 years ago

The code is a bit confusing indeed. The way to check if Mplus is installed will be platform-dependent. I'm a windows guy; on windows, this works:

grepl("Mplus", Sys.getenv()[["PATH"]])

Combine this with an "OS-check", as found in the runModels() code from line 154-169:

if (.Platform$OS.type == "unix" && Mplus_command == "Mplus") { if (Sys.info()["sysname"] == "Darwin") Mplus_command <- "/Applications/Mplus/mplus" else Mplus_command <- "mplus" } command <- paste("cd \"", dirtocd, "\" && \"", Mplus_command, "\" \"", inputSplit$filename, "\"", sep = "") if (.Platform$OS.type == "windows") { command <- chartr("/", "\\", command) shellcommand <- Sys.getenv("COMSPEC") flag <- "/c" command <- paste(shellcommand, flag, command) } else if (.Platform$OS.type == "unix") { }

jrosen48 commented 6 years ago

Thanks!

JWiley commented 6 years ago

@jrosen48 I've pushed a new utility function mplusAvailable() to the GitHub version, it can optionally print a message but otherwise silently returns status 0/1 for no issues / Mplus not installed or not findable, respectively. It is exported so you should be able to use that or depend on it. I will support this and deal with any issues over time as this has been an issue some for me as well with people installing MplusAutomation and wondering if anything else is needed or everything is "ready to go". mplusAvailable() checks across different OSes and should be relatively robust (although if you or your users run into problems, open an issue).

jrosen48 commented 6 years ago

This is @JWiley. Thank you for doing this (and mentiong this). Would it be okay if I were to use it directly in the package until the development version is pushed to CRAN--with a note such as this:

#' Note: This is copied directly from the MplusAutomation 
#' repository. This is because it is only available for the 
#' development version. When it is part of an update, it will 
#' be imported from MplusAutomation.

If you'd prefer I wait until the update and to import it, then I have no problem with that and will do that.

Thank you again!

JWiley commented 5 years ago

@jrosen48 sorry for the delay, I thought I got emails when there were replies on GitHub but apparently not. Yes, absolutely fine to copy, its all open source :)