R : Copyright 2000, The R Development Core Team
Version 1.2.0 Under development (unstable) (2000-09-26)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type	"?license" or "?licence" for distribution details.

R is a collaborative project with many contributors.
Type	"?contributors" for a list.

Type	"demo()" for some demos, "help()" for on-line help, or
    	"help.start()" for a HTML browser interface to help.
Type	"q()" to quit R.

> ###---- ALL tests here should return  TRUE !
> ###
> ###---- "Real" Arithmetic; Numerics etc  -->  ./arith-true.R
> 
> ### mode checking, etc.
> is.recursive(expression(1+3, 2/sqrt(pi)))# fix PR#9
[1] TRUE
> 
> ## any & all [PR#36]
> any(NA,na.rm=TRUE) == any(numeric(0))
[1] TRUE
> all(c(1,NA),na.rm=TRUE) == all(1)
[1] TRUE
> 
> ## sum():
> all(1:12 == cumsum(rep(1,12)))
[1] TRUE
> x <- rnorm(127); sx <- sum(x);	abs((sum(rev(x)) -sx)) < 1e-12 * abs(sx)
[1] TRUE
> 
> ## seq():
> typeof(1:4) == "integer" #-- fails for 0.2, 0.3,.., 0.9
[1] TRUE
> 
> all((0:6) == pi + ((-pi):pi))
[1] TRUE
> all((0:7) == (pi+seq(-pi,pi, len=8))*7/(2*pi))
[1] TRUE
> 
> 1 == as.integer(is.na(c(pi,NA)[2]))
[1] TRUE
> 1 == as.integer(is.nan(0/0))
[1] TRUE
> 
> ## rev():
> cc <- c(1:10,10:1) ;		all(cc == rev(cc))
[1] TRUE
> 
> ## dim[names]():
> all(names(c(a=pi, b=1, d=1:4)) == c("a","b", paste("d", 1:4, sep="")))
[1] TRUE
> ##P names(c(a=pi, b=1, d=1:4))
> ncb <- dimnames(cbind(a=1, yy=1:3))[[2]]
> (!is.null(ncb)) && all(ncb == c("a","yy"))
[1] TRUE
> 
> all(cbind(a=1:2, b=1:3, c=1:6) == t(rbind(a=1:2, b=1:3, c=1:6)))
[1] TRUE
> ##P rbind(a=1:2, b=1:3, c=1:6)
> all(dim(cbind(cbind(I=1,x=1:4), c(a=pi))) == 4:3)# fails in S+
[1] TRUE
> 
> a <- b <- 1:3
> all(dimnames(cbind(a, b))[[2]] == c("a","b"))
[1] TRUE
> 
> ## rbind PR#338
> all(dim(m <- rbind(1:2, diag(2))) == 3:2)
[1] TRUE
> all(m == c(1,1,0, 2,0,1))
[1] TRUE
> 
> ## factor():
> is.factor(factor(list()))
[1] TRUE
> all(levels(ordered(rev(gl(3,4)))) == 1:3)# coercion to char
[1] TRUE
> all(levels(factor(factor(9:1)[3:5])) == 5:7)
[1] TRUE
> ## crossing bug PR#40
> is.factor(ff <- gl(2,3) : gl(3,2)) && length(ff) == 6
[1] TRUE
> all(levels(ff) == t(outer(1:2, 1:3, paste, sep=":")))
[1] TRUE
> ## from PR#5
> ll <- c("A","B"); ff <- factor(ll); f0 <- ff[, drop=TRUE]
> all(f0 == ff) && all(levels(ff) == ll) && is.factor(ff) && is.factor(f0)
[1] TRUE
> 
> ### data.frame s :
> 
> ## from lists [bug PR#100]
> x <- NULL
> x$x1 <- 1:10
> x$x2 <- 0:9
> all(dim(dx <- as.data.frame(x)) == c(10,2))
[1] TRUE
> 
> ## Logicals: (S is wrong)
> l1 <- c(TRUE,FALSE,TRUE)
> (! as.logical(as.data.frame(FALSE)[,1]))
[1] TRUE
> all(l1 == as.logical(as.data.frame(l1)[,1]))
[1] TRUE
> 
> ### Subsetting
> 
> ## bug PR#425
> x <- matrix(1:4, 2, 2, dimnames=list(c("abc","ab"), c("cde","cd")))
> y <- as.data.frame(x)
> all(x["ab",] == c(2,4))
[1] TRUE
> all(y["ab",] == c(2,4))
[1] TRUE
> 
> ## from bug PR#447
> x <- 1:2 ; x[c("2","2")] <- 4
> all.equal(x, c(1:2, "2" = 4))
[1] TRUE
> 
> ## stretching
> l2 <- list(a=1, b=2)
> l2["cc"] <- pi
> l2[["d"]] <- 4
> l2 $ e <- 55
> all.equal(l2, list(a = 1, b = 2, cc = pi, d = 4, e = 55), tol = 0)
[1] TRUE
> all.equal(l2["d"], list(d = 4))
[1] TRUE
> l2$d == 4 && l2$d == l2[["d"]]
[1] TRUE
> 
> ## bug in R <= 1.1
> f1 <- y1 ~ x1
> f2 <- y2 ~ x2
> f2[2] <- f1[2]
> deparse(f2) == "y1 ~ x2"
[1] TRUE
> 
> m <- cbind(a=1:2,b=c(R=10,S=11))
> all(sapply(dimnames(m), length) == c(2,2))
[1] TRUE
> ## [[ for matrix:
> m[[1,2]] == m[[3]] && m[[3]] == m[3] && m[3] == m[1,2]
[1] TRUE
> 
> ## bug in R <= 1.1.1 : unclass(*) didn't drop the class!
> d1 <- rbind(data.frame(a=1, b = I(TRUE)), new = c(7, "N"))
> is.null(class(unclass(d1$b)))
[1] TRUE
> 
> 
>