[Rd] Puzzled by eval
Therneau, Terry M., Ph.D.
therneau at mayo.edu
Fri Nov 6 15:20:57 CET 2015
Duncan,
That's helpful. Two follow-up questions:
1. Where would I have found this information? I had looked at eval and model.frame.
2. What stops the following code from falling down the same rabbit hole? Shouldn't it
find base::cos first?
library(survival)
cos <- lung
coxph(Surv(time, status) ~ age, data=cos)
Terry T.
On 11/06/2015 07:51 AM, Duncan Murdoch wrote:
> On 06/11/2015 7:36 AM, Therneau, Terry M., Ph.D. wrote:
>> I am currently puzzled by a seach path behavior. I have a library of a dozen routines
>> getlabs(), getssn(), getecg(), ... that interface to local repositories and pull back
>> patient information. All have a the first 6 arguments in common, and immediately call a
>> second routine to do initial processing of these 6. The functions "joe" and "fred" below
>> capture the relevant portion of them.
>> My puzzle is this: the last test in the "test" file works fine if these routines are
>> sourced and executed at the command line, it fails if the routines are bundled up and
>> loaded as a library. That test is motivated by a user who called his data set "t", and
>> ended up with a match to base:::t instead of his data, resulting in a strange error
>> message out of model.frame --- you can always count on the users! (There are a few
>> hundred.)
>> I'm attempting to be careful with envr and enclos arguments -- how does base end up
>> earlier in the search path? Perhaps this is clearly stated in the docs and just not
>> clear to me? A working solution to the dilemma is of course more than welcome.
>
> I haven't followed through all the details in fred(), but I can answer the last question.
> In package code, the search order is:
>
> - the package environment
> - the imports to the package (with base being an implicit import)
> - the global environment and the rest of the search list.
>
> In code sourced to the global environment, only the third of these is searched. Since
> base is in the second one, it is found first in the package version.
>
> Duncan Murdoch
More information about the R-devel
mailing list