Re: [Rd] import question

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu, 24 Mar 2011 04:30:31 +0000

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).

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 24 Mar 2011 - 04:38:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Mar 2011 - 19:10:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive