From bbolker at gmail.com  Thu Mar 24 19:47:05 2011
From: bbolker at gmail.com (Ben Bolker)
Date: Thu, 24 Mar 2011 18:47:05 +0000
Subject: [Rd] import question
References: <4D8A85F4.1070507@gmail.com>
	<loom.20110324T011932-297@post.gmane.org>
	<alpine.LFD.2.02.1103240417290.25247@gannet.stats.ox.ac.uk>
Message-ID: <loom.20110324T194207-571@post.gmane.org>

Prof Brian Ripley <ripley <at> stats.ox.ac.uk> writes:

> 
> On Thu, 24 Mar 2011, Ben Bolker wrote:
> 
> > Ben Bolker <bbolker <at> gmail.com> writes:
> >
> >>
> >>
> >>   I have been struggling all day to import a particular function/method
> >> combination (ranef(), which extracts the random effects from a mixed
> >> model fit) from the nlme package into another package ... so far without
> >> success.
> >>
> >
> >  Answered my own question, finally.
> >
> >  Apparently an explicit
> >
> > export(ranef)
> >
> > is required, even though there is also an
> >
> > exportPattern("^[^\\.]")
> >
> > in the NAMESPACE file, which I would have thought would
> > export 'ranef' along with everything else ... ?
> 
> It exports everything excpet dot-namesin the package's namespace. 
> Imports are not in the namespace per se, but in the import environment 
> (which is the enclosure of the namespace).  Here is the actual code:
> 
>          for (p in nsInfo$exportPatterns)
>              exports <- c(ls(env, pattern = p, all.names = TRUE), exports)
> 
> So to re-export a function, you need to do so explicitly.
> 
> It is consdered good practice not to use exportPattern() (at least, 
> not for broadly defined patterns) in production code: see the current 
> 'Writing R Extensions'.  Otherwise things may change under you (what 
> nlme exports has changed recently, hence what import(nlme) brings it 
> has).

  Thank you.
  I will transition away from using exportPattern (although it seemed
like a good quick and dirty solution to this testing problem).

  Please consider the following patch to R-exts ...

  thanks
    Ben Bolker

===================================================================
--- R-exts.texi	(revision 55002)
+++ R-exts.texi	(working copy)
@@ -2310,7 +2310,9 @@
 package @pkg{foo} are to be imported.
 
 It is possible to export variables from a name space that it has
-imported from other name spaces.
+imported from other name spaces (they need to be exported 
+using an explicit @code{export} directive;
+i.e. @code{exportPattern} will not work).
 
 If a package only needs a few objects from another package it can use a
 fully qualified variable reference in the code instead of a formal



[Rd] import question
Ben Bolker