[R] are arithmetic comparison operators binary?
the man page for relational operators (see, e.g., ?'') says: Binary operators which allow the comparison of values in atomic vectors. Arguments: x, y: atomic vectors, symbols, calls, or other objects for which methods have been written. it is somewhat surprizing that the following works: ''(1) # logical(0) ''() # logical(0) ''(1,2,3) # TRUE what does 'binary' mean here, precisely? in the first two examples, one might suspect that '' treats the missing arguments as missing values, but this would not be coherent with what the man page says: Missing values ('NA') and 'NaN' values are regarded as non-comparable even to themselves, so comparisons involving them will always result in 'NA'. i can't find the above explained in the documentation. typing `` shows that it is a function(e1, e2) .Primitive() how come can/should it work with no complaint on input that does not consist of exactly 2 arguments? in scheme (which is claimed to have been an inspiration for r), works on an arbitrary number of arguments: () ;; #t ( 1) ;; #t ( 1 2 3) ;; #t ( 1 2 0) ;; #f but there is an arity-dispatched procedure, not a binary one, and it produces sensible output for any number of arguments (arguably for n=0, 1). vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] are arithmetic comparison operators binary?
WK == Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no on Mon, 23 Feb 2009 12:06:32 +0100 writes: Thank you, Wacek, though .. wrong mailing list WK the man page for relational operators (see, e.g., ?'') says: WK WK Binary operators which allow the comparison of values in atomic vectors. WK Arguments: WK x, y: atomic vectors, symbols, calls, or other objects for which WK methods have been written. WK WK it is somewhat surprizing that the following works: WK ''(1) WK # logical(0) WK ''() WK # logical(0) WK ''(1,2,3) WK # TRUE a bit surprising (sic!), indeed, even for me. Thanks for your notice and report! If you'd looked a bit in the sources, you'd seen that they really are supposed to be binary only. A very small change in the sources does accomplish this, passes the standard checks (and I cannot imagine reasonable code that would have relied on the more lenient behavior), so this will have changed in one of the next versions of R-devel. Martin Maechler, ETH Zurich WK what does 'binary' mean here, precisely? in the first two examples, one WK might suspect that '' treats the missing arguments as missing values, WK but this would not be coherent with what the man page says: WK WK Missing values ('NA') and 'NaN' values are regarded as WK non-comparable even to themselves, so comparisons involving them WK will always result in 'NA'. WK WK i can't find the above explained in the documentation. typing `` shows WK that it is a WK function(e1, e2) .Primitive() WK how come can/should it work with no complaint on input that does not WK consist of exactly 2 arguments? WK in scheme (which is claimed to have been an inspiration for r), works WK on an arbitrary number of arguments: WK () WK ;; #t WK ( 1) WK ;; #t WK ( 1 2 3) WK ;; #t WK ( 1 2 0) WK ;; #f WK but there is an arity-dispatched procedure, not a binary one, and it WK produces sensible output for any number of arguments (arguably for n=0, 1). WK vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] are arithmetic comparison operators binary?
Martin Maechler wrote: WK == Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no on Mon, 23 Feb 2009 12:06:32 +0100 writes: Thank you, Wacek, though .. wrong mailing list apologies. i was actually asking for explanation, assuming that it might be my misunderstanding, rather than reporting a bug. WK the man page for relational operators (see, e.g., ?'') says: WK WK Binary operators which allow the comparison of values in atomic vectors. WK Arguments: WK x, y: atomic vectors, symbols, calls, or other objects for which WK methods have been written. WK WK it is somewhat surprizing that the following works: WK ''(1) WK # logical(0) WK ''() WK # logical(0) WK ''(1,2,3) WK # TRUE a bit surprising (sic!), indeed, even for me. Thanks for your notice and report! you're welcome. shouldn't the tests have captured it? i think you should have a check for every feature following from the docs. plus those undocumented, but assumed by the developers. If you'd looked a bit in the sources, you'd seen that they really are supposed to be binary only. it wouldn't be nonsensical to let them be of arbitrary arity (in a well-documented manner), though it might confuse users. A very small change in the sources does accomplish this, passes the standard checks (and I cannot imagine reasonable code that would have relied on the more lenient behavior), so this will have changed in one of the next versions of R-devel. thanks. just a question (i haven't checked the sources, maybe i should): what is it that happens when one of the operators is called with n = 0 or 1 argument? how does it come up with logical(0) rather than NA? cheers, vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.