Huntsinger, Reid
2002-Nov-07 22:27 UTC
[R] language inconsistency puzzle (in the tradition of Bill V enables (Hi Bill) puzzle "what is x")
R allows you to dynamically extend a vector by assigning past the end. So if a has length 10, then assigning to a[11] creates also a[11] with value a2[11] NA. So a is now length 11, while a2 is still length 10. So the occurrence of a[11] has a different meaning on the assigned-to side than on the assigned-from side. E.g.>a <- rep(1,10) >b <- 11 >a2 <- a >a[b] <- a2[b] >a[1] 1 1 1 1 1 1 1 1 1 1 NA>a2[1] 1 1 1 1 1 1 1 1 1 1 This doesn't seem inconsistent to me; unavoidable yes, given that you want vectors to be dynamically extendible. Have I missed something? Reid Huntsinger -----Original Message----- From: oehl_list at gmx.de [mailto:oehl_list at gmx.de] Sent: Thursday, November 07, 2002 2:11 PM To: r-help at stat.math.ethz.ch Subject: [R] language inconsistency puzzle (in the tradition of Bill Venables (Hi Bill) puzzle "what is x")> # let's say we have two vectors a and b > # lets make a copy of a > > a2 <- a > > # not surprisingly > identical(a[b], a2[b])[1] TRUE> > # now assigning same to same > a[b] <- a2[b] > > # and SURPRISE > identical(a, a2)[1] FALSE>WHAT IS a AND b ? Hint: this "works" under 1.5.1 and 1.6.1. However, the final value of a will differ between 1.5.1 and 1.6.1 under certain circumstances. Explain why it is both, DOUBLY INCONSISTENT AND UNAVOIDABLE. BTW, the prototype does the same. The serious side of this: I think the situation deserves at least a WARNING. Best Jens Oehlschl?gel -- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it. ============================================================================= -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
oehl_list@gmx.de
2002-Nov-08 13:59 UTC
[R] language inconsistency puzzle (in the tradition of Bill V enables (Hi Bill) puzzle "what is x")
Reid, Thanks that you took up the challenge of this serious puzzle (the issue masked a bug in one of my functions under 1.5.1, which was unmasked when changing to 1.6.1, however the issue is still in 1.6.1). You are getting close. Your example might be seen as inconsistent, but not as DOUBLY inconsistent. And your example will not differ between R1.5.1 and R1.6.1. What if I tell you, that in my example> is.na(a2[b])[1] FALSE whereas yours> a <- rep(1,10) > b <- 11 > a2 <- a > is.na(a2[b])[1] TRUE in other words, you tell R to replace non-existent element no. 11 by NA, and dynamic extension makes <a> different from <a2>. In my case <b> DOES NOT SELECT AN NON-EXISTENT ELEMENT OF <a> (resp. <a2>). Any ideas? Jens BTW: Patrick, you guessed right: not a character a and numeric b -- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._