5

I am developing a package that requires the namespace of another package, OpenMx. This package is only available from it's own repository, but specifying this repository in the Additional_repositories field does not work. When trying to build my package without OpenMx installed, I get:

ERROR: dependency 'OpenMx' is not available for blah blah

Is there a problem with my description, or something else I need to be doing?

The relevant piece of my description file:

Depends: R (>= 3.0.0)
Imports:  MASS, OpenMx (>= 2.0)
Additional_repositories: http://openmx.psyc.virginia.edu/OpenMx2/
LazyData: Yes
VignetteBuilder: knitr
Suggests: knitr

Log from a build attempt:

Thu Apr  2 18:08:10 2015: Building tarball for package ctsem (SVN revision 5)
using R version 3.1.3 Patched (2015-03-16 r67994) ...

* checking for file ‘ctsem/DESCRIPTION’ ... OK
* preparing ‘ctsem’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
      -----------------------------------
* installing *source* package ‘ctsem’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘OpenMx’
ERROR: lazy loading failed for package ‘ctsem’
* removing ‘/tmp/RtmpAHPlFq/Rinst5272759a2048/ctsem’
      -----------------------------------
ERROR: package installation failed
Run time: 1.09 seconds.
Charlie
  • 481
  • 4
  • 16
  • The R package system is pretty good but with four or five possible repositories, you don't always succeed with installing packages that have multiple dependencies. I usually just look at the list of missing packages and track them down. In your case I think that may not even be an R package and you would need to use your system resources outside of R. ... Nope I was wrong. Do some Google searching. It's not hard to find the answer. – IRTFM Apr 02 '15 at 20:53
  • That would be fine if I just wanted to install the package, but I'd like to make it available via R-forge and later CRAN, so it needs to pass build checks. – Charlie Apr 02 '15 at 21:27
  • Then look at how other package authors handle it. http://cran.r-project.org/web/packages/simsem/index.html – IRTFM Apr 02 '15 at 21:38
  • simsem doesn't use any OpenMx functions, as far as I can see - doesn't import the namespace. – Charlie Apr 02 '15 at 21:45
  • It doesn't import the NAMESPACE because that would make it ineligible for hosting on CRAN. It probably does use a `source` call in some of its examples that are bracketed by `## Not run:` ... `## End(Not run)`. – IRTFM Apr 02 '15 at 21:52
  • My package is much more dependent. Am I misunderstanding the function of the additional repositories field? – Charlie Apr 02 '15 at 22:01
  • 1
    I think CRAN has rules that prevent just any old repository from being used. The CRAN policies document: http://cran.r-project.org/web/packages/policies.html says they require "a mainstream repository". I think that might include GitHub but not openmx.psyc.virginia.edu. The only authoritative answer will come from the CRAN owners. – IRTFM Apr 02 '15 at 22:37
  • I understood the purpose of the additional repositories field was precisey to specify *non* mainstream repo's... – Charlie Apr 03 '15 at 13:07

3 Answers3

3

AFAIK Additional_repositories is still a free-form field and not automatically added to the options("repos") consulted by download.packages() and hence install.packages() or update.packages().

For the very problem of adding repos beyond CRAN, I wrote a little helper package drat which a few people, myself included, use to host repos either on GitHub (a "default" mode as it is so easy via gh-pages) or any other http-accessible server---ie local servers within a company or workgroup. Drat does nothing particularly difficult, but for this default case of adding a repository of user, say, openmx, all you need is drat::addRepo("openmx") and the rest is inferred from defaults (and assumes a drat repo in account openmx exists).

I deploy both use cases: newer packages via repos at GitHub, and a work-local repo.

Edit: But WRE says

The 'Addiitonal_repositories' field is a comma-separated list of repository URLs where the packages named in the other fields may be found. It is currently used by 'R CMD check' to check that the packages can be found, at least as source packages (which can be installed on any platform).

which implies it looks there. Odd. And the repo looks legit at the given URL.

Edit 2: And I sent a patch to R Core for the typo in the above quote.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
3

So it appears that the Additional_repositories field is only used to check the existence of any suggested packages, but they are not actually loaded, and hence if any examples or vignettes use these packages, the build process will break. I have worked around the problem for now by setting examples to not run and including a pre-built vignette instead.

Charlie
  • 481
  • 4
  • 16
3

See: http://thecoatlessprofessor.com/programming/r-data-packages-in-external-data-repositories-using-the-additional_repositories-field/

Specifically, note that you can specify:

if (!requireNamespace("namepackage", quietly = TRUE)) {
  install.packages("namepackage", repos = "http://location-of.com/repo")
}

To auto add the repo on package load, use:

.onLoad <- function(libname) {
  repos = getOption("repos")
  repos["<NAME_REPO>"] = "http://location-of.com/repo"
  options(repos = repos)
  invisible(repos)
}

This negates the need to set repos = ... in install.packages().

coatless
  • 20,011
  • 13
  • 69
  • 84