cberry@tajo.ucsd.edu
2000-Nov-08 18:59 UTC
[Rd] substitute(x$y)) corrupts 'y' component (PR#731)
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 Is there a workaround to achieve this behavior under fairly general circumstances, i.e. when one does not know whether to expect an object with a component, but encounters one? Chuck Berry --please do not edit the information below-- Version: platform = sparc-sun-solaris2.7 arch = sparc os = solaris2.7 system = sparc, solaris2.7 status = major = 1 minor = 1.0 year = 2000 month = June day = 15 language = R Search Path: .GlobalEnv, package:bqtl, Autoloads, package:base>-- Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry@tajo.ucsd.edu UC San Diego http://hacuna.ucsd.edu/members/ccb.html La Jolla, San Diego 92093-0645 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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)$yI 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._