From mtmorgan at fhcrc.org  Tue Nov 16 02:27:34 2010
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Mon, 15 Nov 2010 17:27:34 -0800
Subject: [Rd] Trying to understand the search path and namespaces
In-Reply-To: <AANLkTimckaNaUb6SjY=njVZuRSa1iJ+4entWVA2ghBxD@mail.gmail.com>
References: <AANLkTin090pRti8dXknLKtpFmUmmvRsAz6a0V2mx5iOM@mail.gmail.com>	<AANLkTi=3K0T7qzQnRU-Q8h3RVTDS+UQ5CmcOs4xZJYfD@mail.gmail.com>	<AANLkTikPE5acZ6CKJeoq9RpphUJffr4W8Lm_8c7O7i08@mail.gmail.com>
	<AANLkTimckaNaUb6SjY=njVZuRSa1iJ+4entWVA2ghBxD@mail.gmail.com>
Message-ID: <4CE1DE06.9060809@fhcrc.org>

On 11/15/2010 04:56 PM, Hadley Wickham wrote:
>> Well, that's what I thought too.  But:
>>
>> parents <- function(x) {
>>  if (identical(x, emptyenv())) return()
>>  c(environmentName(x), parents(parent.env(x)))
>> }
>>> parents(as.environment("package:devtools"))
>> [1] "package:devtools" "package:methods"  "Autoloads"        "base"
>>
>> And package:testthat isn't listed there.  (But Autoloads is suggestive...)
> 
> Hmmm, autoloads isn't it:
> 
>> parent.env(parent.env(as.environment("package:devtools")))
> <environment: 0x100951f88>
> attr(,"name")
> [1] "Autoloads"
>> ls(parent.env(parent.env(as.environment("package:devtools"))))
> character(0)

1.6 of Writing R Extensions says

Note that adding a name space to a package changes the search strategy.
The package name space comes first in the search, then the imports, then
the base name space and then the normal search path.

I'm not sure of the details, but I think

  parents(getNamespace("devtools"))

will give you what you want, with the gory details in loadNamespace
makeNamespace

Martin


> 
> Hadley
> 


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



[Rd] Trying to understand the search path and namespaces
Martin Morgan