[R] What purpose is served by reflexive function assignments?

andrewH ahoerner at rprogress.org
Mon Dec 30 00:57:29 CET 2013


Dear David--

Thanks so much for your helpful reply!

 David Winsemius wrote:
>>The LHS X becomes a name, the RHS X will be looked up in the calling
environment and fails if no value is positionally matched and then no X is
found (at the time of the function definition. 

Does X really have to exist when the function is defined? I thought it was
enough if it existed in the environment of the calling function, or
somewhere up the environment chain of the calling function. If this is not
true, then that means it matters a lot whether you write a function inside
another function or just call it in that function.  Suppose a function with
a reflexive assignment X=X is defined in the global environment but called
inside another function, and X has a different value in those two places.
Will it look first in the global environment and only then in the calling
environment? And is this different from the behavior without the reflexive
assignment?

I should not bother you with those questions. I should just run it both ways
and see what happens.calling function and will it look first in the 

>>If you use`X <- value` in the argument list, then what is returned is only
the value and the name `X` may be lost. Or in the case of data.frame morphed
into a strange name: 

[example omitted]
I am not sure that I am understanding you correctly here. Are you saying
that assignment using the "=" retains the name (and other attributes? which
ones?) of the RHS, while "<-" does not? 




--
View this message in context: http://r.789695.n4.nabble.com/What-purpose-is-served-by-reflexive-function-assignments-tp4682794p4682819.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list