numeric(0)[FALSE] bug[let]
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 19 Dec 1997 00:15:05 +0100
This is not a joke, but a problem appearing in real code of mine.
I used ifelse in a context which can be simplified to
R> ifelse(T, 3, NULL)
Error: incompatible types in subset assignment
R> ifelse(T, 3, numeric(0))
Error: invalid subscript type
R>
R> ifelse
function (test, yes, no)
{
ans <- test
test <- as.logical(test)
nas <- is.na(test)
ans[test] <- rep(yes, length = length(ans))[test]
ans[!test] <- rep(no, length = length(ans))[!test]
ans[nas] <- NA
ans
}
R>
R> numeric(0)[F]
Error: invalid subscript type
R> NULL[F]
NULL
R>
--------------------------------------------
whereas S-plus does as I expect:
S> ifelse(T, 3, NULL)
[1] 3
S> ifelse(T, 3, numeric(0))
[1] 3
S>
S> NULL[F]
NULL
S> numeric(0)[F]
numeric(0)
S> logical(0)[F]
logical(0)
S>
-----------------
I see an easy workaround for either fixing ifelse(.) and or
solving my problem.
However, I think
anytype(0)[FALSE] should return
anytype(0)
Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._