From murdoch.duncan at gmail.com  Fri Sep 23 20:44:57 2011
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Fri, 23 Sep 2011 14:44:57 -0400
Subject: [Rd] "could not find function" after import
In-Reply-To: <CAFFLneR_tuCSx0GG9jZBz4oF9ysnVTz5Ut8P6gQ_LW2aNcXNmA@mail.gmail.com>
References: <4E77AA8D.2040409@u.washington.edu> <4E77D9C3.1070307@gmail.com>
	<CAFFLneR_tuCSx0GG9jZBz4oF9ysnVTz5Ut8P6gQ_LW2aNcXNmA@mail.gmail.com>
Message-ID: <4E7CD3A9.9020808@gmail.com>

On 23/09/2011 12:57 PM, steven mosher wrote:
> Duncan
>
> I have a related question.
>
> I need one function from R.utils.  But R.utils depends on R.oo and  R.methodsS3.
> so I made R.util an import and then used importFrom() in the namespace.
>
> The package passed the  "check".  However when it came to use the function
> it had not been loaded? do I need to add the upstream packages that
> R.util  depends
> upon?  also in the code do I need a library or require?

Sounds exactly like the situation with sandwich below.    The workaround 
available to you is to Depend on R.utils.  The author of R.utils could 
fix the problem by importing R.oo and R.methodsS3, and the authors of R 
could fix it by changing the behaviour of how R handles imports.

Duncan Murdoch

> A bit confused
>
> Steve
>
> On Mon, Sep 19, 2011 at 5:09 PM, Duncan Murdoch
> <murdoch.duncan at gmail.com>  wrote:
> >  On 11-09-19 4:48 PM, Stephanie M. Gogarten wrote:
> >>
> >>  I am trying to build a package (GWASTools, submitted to Bioconductor)
> >>  that uses the "sandwich" package.  I have references to "sandwich" in
> >>  DESCRIPTION:
> >>  Imports: methods, DBI, RSQLite, sandwich, survival, DNAcopy
> >>
> >>  and NAMESPACE:
> >>  import(sandwich)
> >>
> >>  In the code itself is a call to vcovHC:
> >>  Vhat<- vcovHC(mod, type="HC0")
> >>
> >>  I have sandwich version 2.2-7 installed.
> >>
> >>  When I run R CMD check on my package, I get the following error during
> >>  checking of examples:
> >>  * using R Under development (unstable) (2011-08-29 r56828)
> >>  * using platform: x86_64-apple-darwin9.8.0 (64-bit)
> >>  ...
> >>  * checking examples ... ERROR
> >>  ...
> >>  Error in estfun.glm(x) : could not find function "is.zoo"
> >>  Calls: assocTestRegression ... meatHC ->    rowMeans ->    is.data.frame ->
> >>  estfun ->    estfun.glm
> >>
> >>  I import sandwich, sandwich depends on zoo, but a function in zoo cannot
> >>  be found during execution.
> >>
> >>  I tried to get around this by explicitly including a "require" statement
> >>  in assocTestRegression:
> >>  require(sandwich)
> >>
> >>  The example now runs, but I have a warning in R CMD check:
> >>  * checking for unstated dependencies in R code ... WARNING
> >>  ?library? or ?require? call not declared from: ?sandwich?
> >>
> >>  I am not sure why this is a problem, as there is a "require" statement
> >>  (for a different package) in another function which does not cause any
> >>  warnings.
> >>
> >>  Can anyone advise on how to get my package to successfully pass R CMD
> >>  check?
> >>
> >
> >  If you said that your package Depends on sandwich, you'd probably pass
> >  checks, but this is arguably a bug in the sandwich package.
> >
> >  The problem is that since you only import sandwich, it never gets attached.
> >    So it never attaches its dependency zoo.   It should import zoo (or import
> >  the functions in zoo that it uses) to work properly the way you are calling
> >  it.
> >
> >  You can see the same error as follows:
> >
> >  1.  Install sandwich, but don't attach it or zoo.
> >
> >  2.  Run
> >
> >  example(glm)
> >
> >  to create the "glm" object glm.D93.
> >
> >  Try to call
> >
> >  sandwich::estfun(glm.D93)
> >
> >  You'll get the same error as before because is.zoo() will not be loaded.
> >
> >  It's also arguably a design flaw in R.  For testing sandwich, zoo would
> >  generally end up being attached, because the testing of sandwich would
> >  attach it.  However, examples like the one above are never tested.
> >
> >  Duncan Murdoch
> >
> >  ______________________________________________
> >  R-devel at r-project.org mailing list
> >  https://stat.ethz.ch/mailman/listinfo/r-devel
> >



[Rd] "could not find function" after import
Duncan Murdoch