gives an error in R. In both S+3 and S+5, it "works" by returning NULL or logical(0), respectively. As a consequence, all(x == y) returns TRUE in Splus, when x <- y <- NULL but gives an error in R. Do we have a good reason *not* to return logical(0) ? Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
{following up myself on the NULL == NULL topic} I found that x == y is allowed in R when x and y are (generalized) ``Vectors'' (accidentally, I'm quite sure !), which includes lists and expressions, but the result is pretty `funny' in some cases, e.g. > e3 <- expression(1,x,x^2) > e3 == expression(1,x,x^2) [1] FALSE TRUE FALSE > e3 == e3 ## all TRUE.. [1] TRUE TRUE TRUE Note that it's not just "==", but all 6 relation operators ( "!=", "<", ...). It's been quite easy for me to make R produce an error in these cases {the same as for > cl <- quote(sin(x)) ; cl == cl Error in cl == cl : comparison (1) is possible only for vector types } But with that "make check" would fail (we have at least on case in the examples where we test equality of two expr) and it might be that people's R code already is doing these comparisons with list()s and expression()s. What should be done? -- One possibility would be to make these work for call()s and expressions, by using deparse(.) on the non-symbol calls {symbol calls already *do* work -- and this is *not* accidental : > cl <- as.name("X"); cl == cl; cl > cl [1] TRUE [1] FALSE } and dealing with expressions as "vector of calls". It is still less clear how list()s should be dealt with. We really have the problem of differing backcompatibility to R and compatibility to S (in S, these rel.ops only apply to atomic objects and NULL). Opinions? -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 Fri, 15 Sep 2000, Martin Maechler wrote:> gives an error in R. > > In both S+3 and S+5, it "works" by returning NULL or logical(0), > respectively. > > As a consequence, > > all(x == y) > > returns TRUE in Splus, when x <- y <- NULL > but gives an error in R. > > Do we have a good reason *not* to return logical(0) ?I think returning logical(0) is a good idea. Having all(NULL==NULL) be TRUE is consistent with what we do for vacuous cases of min and max. However, a arguable reason for not doing it is that NULL is actually a list with no elements rather than a vector with no elements, and you can't compare lists with ==. On the gripping hand, you can't turn NULL into a vector of length zero using eg unlist(), so the only way to get this comparison to work is to have NULL==NULL. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._