# [Rd] substitute(x$y)) corrupts 'y' component (PR#731)

**Thomas Lumley
**
thomas@biostat.washington.edu

*Wed, 8 Nov 2000 11:33:23 -0800 (PST)*

On Wed, 8 Nov 2000 cberry@tajo.ucsd.edu wrote:
>* viz.
*>*
*>*
*>* > (function(x,y=a) substitute(x$y))(x)
*>* x$a
*>* > (function(x,y=a) substitute(x$y))(list(y=1:3))
*>* list(y = 1:3)$a
*>* > (function(x,y) eval(substitute(substitute(y))))(x=list(y=1:3),y=x$y)
*>* list(y = 1:3)$x$y
*>*
*>*
*>* The behavior I expect and want is like that in Splus 3.4:
*>*
*>* > (function(x,y=a) substitute(x$y))(x)
*>* x$y
*>* > (function(x,y=a) substitute(x$y))(list(y=1:3))
*>* list(y = 1:3)$y
*>* > (function(x,y) eval(substitute(substitute(y))))(x=list(y=1:3),y=x$y)
*>* list(y = 1:3)$y
*
I don't think this is a bug - substitute is performing as intended and as
documented -- but it is an incompatibility. There are two issues here,
one easy and one difficult.
In your first two examples the problem is that you want to substitute only
for x (though in the second example I don't see why you expect this to
happen). If you want to substitute only for x you can do
substitute(x$y,list(x=x))
In the third example you want to perform substitution on the value of a
variable. This is a useful thing to want to do, and I don't know how to
do it.
eg
z<-quote(x$y)
x<-list(y=1:3)
and you want to produce
list(y=1:3)$y
Suggestions?
-thomas
Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._