[Rd] instantiating a reference class with an initialize() method from .onLoad fails
Martin Morgan
mtmorgan at fhcrc.org
Fri Feb 21 04:41:04 CET 2014
PkgA has a single R/binding.R file containing
.A <- setRefClass("A", methods=list(initialize=function(...) {}))
.onLoad <- function(...) .A()
A NAMESPACE with
import(methods)
exportClasses("A")
and DESCRIPTION
Package: PkgA
Type: Package
Title: Documenting reference classes
Version: 0.0.1
Date: 2012-08-05
Author: Martin Morgan
Maintainer: Martin Morgan <mtmorgan at fhcrc.org>
Description: This package implements a simple 'reference' class
Depends: methods
Imports: methods
License: Apache License 2.0
Collate: binding.R
R CMD INSTALL PkgA results in
p$ R --vanilla CMD INSTALL PkgA
* installing to library ‘/home/mtmorgan/R/x86_64-unknown-linux-gnu-library/3.1’
* installing *source* package ‘PkgA’ ...
** R
** preparing package for lazy loading
** help
No man pages found in package ‘PkgA’
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'PkgA', details:
call: initialize(value, ...)
error: attempt to apply non-function
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/mtmorgan/R/x86_64-unknown-linux-gnu-library/3.1/PkgA’
* restoring previous ‘/home/mtmorgan/R/x86_64-unknown-linux-gnu-library/3.1/PkgA’
Having read
https://stat.ethz.ch/pipermail/r-devel/2013-October/067636.html
I used
setLoadAction(function(nmspc) .A())
in place of .onLoad, and had success. However, a more complicated scenario,
https://stat.ethz.ch/pipermail/bioc-devel/2014-February/005271.html
where a data file contains an instance of a class defined in a package that
imports PkgA, fails during R CMD check or in an R session with
env = new.env(); load("data.Rdata", env); get("data", env)
including when .A() is eval() or evalq()'d in envir=nmspc.
Thanks for any hints.
Martin
--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109
Location: Arnold Building M1 B861
Phone: (206) 667-2793
More information about the R-devel
mailing list