You are here

Trouble with importing specific functions from OpenMx into my package

3 posts / 0 new
Last post
Veronica_echo's picture
Offline
Joined: 02/23/2018 - 01:57
Trouble with importing specific functions from OpenMx into my package

Hello OpenMx community,

I am currently developing an R package called nlpsem, and I am trying to use some functions from the OpenMx package. Specifically, I am trying to use the mxOption and imxReportProgress functions. However, I am encountering some issues when trying to use these functions without explicitly loading the OpenMx package with library(OpenMx).

In my DESCRIPTION file, I have the following lines:

Imports:
    OpenMx, ggplot2, dplyr, tidyr, stringr, Matrix, nnet, readr, methods

And in my NAMESPACE file, I have the following lines:

importFrom(OpenMx,diag2vec)
importFrom(OpenMx,imxReportProgress)
importFrom(OpenMx,mxAlgebra)
importFrom(OpenMx,mxAlgebraFromString)
importFrom(OpenMx,mxBootstrap)
importFrom(OpenMx,mxCI)
importFrom(OpenMx,mxCompare)
importFrom(OpenMx,mxData)
importFrom(OpenMx,mxEval)
importFrom(OpenMx,mxEvalByName)
importFrom(OpenMx,mxExpectationMixture)
importFrom(OpenMx,mxFactorScores)
importFrom(OpenMx,mxFitFunctionAlgebra)
importFrom(OpenMx,mxFitFunctionML)
importFrom(OpenMx,mxMatrix)
importFrom(OpenMx,mxModel)
importFrom(OpenMx,mxOption)
importFrom(OpenMx,mxPath)
importFrom(OpenMx,mxRun)
importFrom(OpenMx,mxSE)
importFrom(OpenMx,mxTryHard)
importFrom(OpenMx,omxGetParameters)

Despite having these lines in my DESCRIPTION and NAMESPACE files, I still get the following error when trying to use the mxOption function without loading the OpenMx package:

Error in mxOption(model = NULL, key = "Default optimizer", "CSOLNP", reset = FALSE) : 
  could not find function "mxOption"

I have tried several approaches to resolve this issue, including checking the OpenMx version, checking the function documentation, explicitly loading the OpenMx package, using the double colon operator, checking for conflicts, and rebuilding and reloading my package. However, none of these steps have resolved the issue.

I would greatly appreciate any guidance or suggestions on how to properly import and use the mxOption and imxReportProgress functions from the OpenMx package in my nlpsem package.

Thank you for your time and assistance!

Best regards,
Veronica

lf-araujo's picture
Offline
Joined: 11/25/2020 - 13:24
Hi Veronica,

Hi Veronica,

I suggest looking at either umx or EasyMx approaches.

Hunter's approach in EasyMx seems the easiest, he just Depends: R (>= 3.0.0), OpenMx in the DESCRIPTION, then he import(OpenMx) in NAMESPACE.

Our impression is that your code should also work, have you tried OpenMx::mxOption(model = NULL, key = "Default optimizer", "CSOLNP", reset = FALSE) though this is a bit cumbersome.

Best,

Luis

Veronica_echo's picture
Offline
Joined: 02/23/2018 - 01:57
Thanks Luis :) I set OpenMx

Thanks Luis :) I set OpenMx as "Depends" and now it works. Thank you for the kind suggestion.

Best regards,
Veronica