Depends and Imports with OpenMx

Posted on
No user picture. fife Joined: 07/01/2010
Forums
Hi everyone,

I am currently in the process of getting a new package on CRAN. My package uses openMx to estimate SE Models. Normally, to upload a package on CRAN, one would specify what packages are required. For example, I would put the following in my Description file:

Depends: OpenMx, MASS
Imports: OpenMx, MASS

if I had functions that use openmx and the MASS package. And in my Namespace file:

import("OpenMx", "MASS")

The problem is that R doesn't recognize OpenMx because it is not on R's repository. Does anyone know a way around this? Thanks in advance for the help.

Replied on Fri, 08/23/2013 - 04:15
Picture of user. tbates Joined: 07/31/2009

I don't think there's a problem putting a package on CRAN which depends on packages that are not on CRAN. I'd use the devtools package to build and check (and release) the package: very good at doing these sanity checks (and for a nice development cycle, roxygen etc.)

I'd guess you'll just need to wrap the examples in don't run tags..
Add an INSTALL maybe to help people find OpenMx, and document the requirement and manual element in yourName-package.Rd


setwd("~/bin/yourpackage/");
devtools::check()

FYI, other stuff I use a bit (but have not yet pushed to cran with...) is

setwd("~/bin/umx/umx"); devtools::document(); devtools::install();
devtools::load_all()
devtools::dev_help("yourFun")

https://github.com/hadley/devtools

https://github.com/hadley/devtools/wiki/Philosophy

Replied on Mon, 08/26/2013 - 13:11
No user picture. fife Joined: 07/01/2010

In reply to by tbates

Thanks for the input. I commented out all the examples, and removed openmx from the namespace and dependencies, but the problem is that many of the functions have "require(OpenMx)." When I run CMD check on my computer, it flags that as problematic and gives me the following message:

* checking for unstated dependencies in R code . . . WARNING 'library' or 'require' call not declared from: 'OpenMx'

Any ideas?

Replied on Mon, 08/26/2013 - 15:43
Picture of user. mhunter Joined: 07/31/2009

In reply to by fife

Is it a warning or an error? The difference being that a warning indicates that something might not be right but it will let you do it anyway, whereas an error stops anything from being done. If it's just a warning, then I think you're all set.
Replied on Thu, 09/05/2013 - 08:34
Picture of user. tbrick Joined: 07/31/2009

In reply to by mhunter

require() should return FALSE and give a warning if the package isn't found.

You can use a snippet like:

hasOpenMx <- suppressWarnings(require("OpenMx"))
if(!hasOpenMx) {
stop(paste("This package uses OpenMx, but you do not currently have it installed. ",
"You can get it by visiting [http://openmx.psyc.virginia.edu/installing-openmx] and",
"following the instructions there.")
}

Or whatever you'd like to happen in the case that OpenMx doesn't load. The require() command above won't say anything if it fails. If you don't want it to say anything on success either, you can wrap the suppressWarnings() in a suppressMessages() as well.

Replied on Fri, 09/06/2013 - 04:49
Picture of user. tbates Joined: 07/31/2009

In reply to by tbrick

It will be interesting to see how this works out: I'd have thought the issue that the cran algorithm has is that it wants to know what happens when OpenMx IS available: so just exiting all the functions prematurely won't pass the checks? But perhaps it does.

There must be a way, because semTools suggests OpenMx and is up on cran

https://github.com/simsem/semTools/wiki

I'd love to hear how this works out

Replied on Sat, 08/31/2013 - 10:45
Picture of user. mdewey Joined: 01/21/2011

In reply to by fife

If you get a Warning then I do not think CRAN will accept the package. I wonder though are you just calling require() or have you wrapped it in an if statement and issue an error if it returns FALSE? Does it make a difference?

Another avenue might be to see how packages on CRAN which augment OpenMx like semtools handle the issue.