1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
R version 3.1.1 RC (2014-07-04 r66081) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
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 more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an 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
>
> ## 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
>
> ## Check parsing with L suffix for integer literals.
> typeof(1L) == "integer"
[1] TRUE
> typeof(1000L) == "integer"
[1] TRUE
> typeof(1e3L) == "integer"
[1] TRUE
> typeof(1e-3L) == "double" # gives warning
[1] TRUE
Warning message:
non-integer value 1e-3L qualified with L; using numeric value
> 1.L # gives warning
[1] 1
Warning message:
integer literal 1.L contains unnecessary decimal point
> try(parse(text = "12iL")) # gives syntax error
Error in parse(text = "12iL") : <text>:1:4: unexpected symbol
1: 12iL
^
>
>
> all((0:6) == pi + ((-pi):pi))
[1] TRUE
> all((0:7) == (pi+seq(-pi,pi, length=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(integer()))
[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
>
> ## empty data.frames :
> x <- data.frame(a=1:3)
> x30 <- {
+ if(is.R()) x[, -1]# not even possible in S+
+ else structure(list(), row.names = paste(1:3), class = "data.frame")
+ }
> all(dim(x30) == c(3,0))
[1] TRUE
> x01 <- x[-(1:3), , drop = FALSE]
> x00 <- x01[,-1]
> all(dim(x01) == 0:1)
[1] TRUE
> all(dim(x00) == 0)
[1] TRUE
> all(dim(x) == dim(rbind(x, x01)))
[1] TRUE
> ## bugs up to 1.2.3 :
> all(dim(x30) == dim(m30 <- as.matrix(x30)))
[1] TRUE
> all(dim(x01) == dim(m01 <- as.matrix(x01)))
[1] TRUE
> all(dim(x30) == dim(as.data.frame(m30)))
[1] TRUE
> all(dim(x01) == dim(as.data.frame(m01)))
[1] TRUE
> all(dim(x01) == dim( data.frame(m01)))
[1] TRUE
> all(dim(x30) == dim( data.frame(m30)))
[1] TRUE
> all(dim(x) == dim(cbind(x, x30)))
[1] TRUE
> ## up to 1.4.0 :
> all(dim(x30) == dim( data.matrix(x30)))
[1] TRUE
> all(dim(x00) == dim( data.matrix(x00)))
[1] TRUE
>
> m0 <- matrix(pi, 0,3)
> a302 <- array("", dim=c(3,0,2))
> identical(apply(m0, 1, dim), NULL)
[1] TRUE
> identical(apply(m0, 2, dim), NULL)
[1] TRUE
> identical(apply(m0, 1,length), integer(0))
[1] TRUE
> identical(apply(m0, 2,length), integer(3))
[1] TRUE
> identical(apply(a302, 1, mode), rep("character",3))
[1] TRUE
> ## NO (maybe later?):
> ## identical(apply(a302, 2, mode), rep("character",0))
> is.character(aa <- apply(a302, 2, mode)) && length(aa) == 0
[1] TRUE
> identical(apply(a302, 3, mode), rep("character",2))
[1] TRUE
> identical(apply(a302, 3, length),integer(2))
[1] TRUE
> identical(apply(a302, 3, dim), matrix(as.integer(c(3,0)), 2 ,2))
[1] TRUE
> identical(apply(a302, 1, dim), matrix(as.integer(c(0,2)), 2 ,3))
[1] TRUE
> identical(apply(array(dim=3), 1,length), rep(1:1, 3))
[1] TRUE
> identical(apply(array(dim=0), 1,length), rep(1:1, 0))# = integer(0)
[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), tolerance = 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!
> ## to be robust to S4 methods DON'T test for null class
> ## The test for attr(,"class") is valid, if essentially useless
> d1 <- rbind(data.frame(a=1, b = I(TRUE)), new = c(7, "N"))
> is.null(attr(unclass(d1$b), "class"))
[1] TRUE
>
> ## bugs in R 1.2.0
> format(as.POSIXct(relR120 <- "2000-12-15 11:24:40")) == relR120
[1] TRUE
> format(as.POSIXct(substr(relR120,1,10))) == substr(relR120,1,10)
[1] TRUE
>
> ## rank() with NAs (and ties)
> x <- c(3:1,6,4,3,NA,5,0,NA)
> rx <- rank(x)
> all(rx == c(4.5, 3:2, 8, 6, 4.5, 9, 7, 1, 10))
[1] TRUE
> rxK <- rank(x, na.last = "keep")
> all(rx [rx <= 8] == na.omit(rxK))
[1] TRUE
> all(rank(x, na.last = NA) == na.omit(rxK))
[1] TRUE
>
> ## as.list.function() instead of *.default():
> identical(as.list(as.list),
+ alist(x = , ... = , UseMethod("as.list")))
[1] TRUE
>
|