1
2R version 4.1.1 Patched (2021-10-12 r81047) -- "Kick Things"
3Copyright (C) 2021 The R Foundation for Statistical Computing
4Platform: x86_64-pc-linux-gnu (64-bit)
5
6R is free software and comes with ABSOLUTELY NO WARRANTY.
7You are welcome to redistribute it under certain conditions.
8Type 'license()' or 'licence()' for distribution details.
9
10R is a collaborative project with many contributors.
11Type 'contributors()' for more information and
12'citation()' on how to cite R or R packages in publications.
13
14Type 'demo()' for some demos, 'help()' for on-line help, or
15'help.start()' for an HTML browser interface to help.
16Type 'q()' to quit R.
17
18> ## Regression tests for which the printed output is the issue
19> ### _and_ must work (no Recommended packages, please)
20>
21> pdf("reg-tests-2.pdf", encoding = "ISOLatin1.enc")
22>
23> ## force standard handling for data frames
24> options(stringsAsFactors=FALSE) # R >= 4.0.0
25> options(useFancyQuotes=FALSE)
26>
27> ### moved from various .Rd files
28> ## abbreviate
29> for(m in 1:5) {
30+   cat("\n",m,":\n")
31+   print(as.vector(abbreviate(state.name, minl=m)))
32+ }
33
34 1 :
35 [1] "Alb"  "Als"  "Arz"  "Ark"  "Clf"  "Clr"  "Cn"   "D"    "F"    "G"
36[11] "H"    "Id"   "Il"   "In"   "Iw"   "Kns"  "Knt"  "L"    "Man"  "Mr"
37[21] "Mssc" "Mc"   "Mnn"  "Msss" "Mssr" "Mnt"  "Nb"   "Nv"   "NH"   "NJ"
38[31] "NM"   "NY"   "NC"   "ND"   "Oh"   "Ok"   "Or"   "P"    "RI"   "SC"
39[41] "SD"   "Tn"   "Tx"   "U"    "Vrm"  "Vrg"  "Wsh"  "WV"   "Wsc"  "Wy"
40
41 2 :
42 [1] "Alb"  "Als"  "Arz"  "Ark"  "Clf"  "Clr"  "Cn"   "Dl"   "Fl"   "Gr"
43[11] "Hw"   "Id"   "Il"   "In"   "Iw"   "Kns"  "Knt"  "Ls"   "Man"  "Mr"
44[21] "Mssc" "Mc"   "Mnn"  "Msss" "Mssr" "Mnt"  "Nb"   "Nv"   "NH"   "NJ"
45[31] "NM"   "NY"   "NC"   "ND"   "Oh"   "Ok"   "Or"   "Pn"   "RI"   "SC"
46[41] "SD"   "Tn"   "Tx"   "Ut"   "Vrm"  "Vrg"  "Wsh"  "WV"   "Wsc"  "Wy"
47
48 3 :
49 [1] "Alb"  "Als"  "Arz"  "Ark"  "Clf"  "Clr"  "Cnn"  "Dlw"  "Flr"  "Grg"
50[11] "Haw"  "Idh"  "Ill"  "Ind"  "Iow"  "Kns"  "Knt"  "Lsn"  "Man"  "Mry"
51[21] "Mssc" "Mch"  "Mnn"  "Msss" "Mssr" "Mnt"  "Nbr"  "Nvd"  "NwH"  "NwJ"
52[31] "NwM"  "NwY"  "NrC"  "NrD"  "Ohi"  "Okl"  "Org"  "Pnn"  "RhI"  "StC"
53[41] "StD"  "Tnn"  "Txs"  "Uth"  "Vrm"  "Vrg"  "Wsh"  "WsV"  "Wsc"  "Wym"
54
55 4 :
56 [1] "Albm" "Alsk" "Arzn" "Arkn" "Clfr" "Clrd" "Cnnc" "Dlwr" "Flrd" "Gerg"
57[11] "Hawa" "Idah" "Illn" "Indn" "Iowa" "Knss" "Kntc" "Losn" "Main" "Mryl"
58[21] "Mssc" "Mchg" "Mnns" "Msss" "Mssr" "Mntn" "Nbrs" "Nevd" "NwHm" "NwJr"
59[31] "NwMx" "NwYr" "NrtC" "NrtD" "Ohio" "Oklh" "Orgn" "Pnns" "RhdI" "SthC"
60[41] "SthD" "Tnns" "Texs" "Utah" "Vrmn" "Vrgn" "Wshn" "WstV" "Wscn" "Wymn"
61
62 5 :
63 [1] "Alabm" "Alask" "Arizn" "Arkns" "Clfrn" "Colrd" "Cnnct" "Delwr" "Flord"
64[10] "Georg" "Hawai" "Idaho" "Illns" "Indin" "Iowa"  "Kanss" "Kntck" "Lousn"
65[19] "Maine" "Mryln" "Mssch" "Mchgn" "Mnnst" "Mssss" "Missr" "Montn" "Nbrsk"
66[28] "Nevad" "NwHmp" "NwJrs" "NwMxc" "NwYrk" "NrthC" "NrthD" "Ohio"  "Oklhm"
67[37] "Oregn" "Pnnsy" "RhdIs" "SthCr" "SthDk" "Tnnss" "Texas" "Utah"  "Vrmnt"
68[46] "Virgn" "Wshng" "WstVr" "Wscns" "Wymng"
69>
70> ## apply
71> x <- cbind(x1 = 3, x2 = c(4:1, 2:5))
72> dimnames(x)[[1]] <- letters[1:8]
73> apply(x,  2, summary) # 6 x n matrix
74        x1 x2
75Min.     3  1
761st Qu.  3  2
77Median   3  3
78Mean     3  3
793rd Qu.  3  4
80Max.     3  5
81> apply(x,  1, quantile)# 5 x n matrix
82        a b    c   d    e f    g   h
830%   3.00 3 2.00 1.0 2.00 3 3.00 3.0
8425%  3.25 3 2.25 1.5 2.25 3 3.25 3.5
8550%  3.50 3 2.50 2.0 2.50 3 3.50 4.0
8675%  3.75 3 2.75 2.5 2.75 3 3.75 4.5
87100% 4.00 3 3.00 3.0 3.00 3 4.00 5.0
88>
89> d.arr <- 2:5
90> arr <- array(1:prod(d.arr), d.arr,
91+          list(NULL,letters[1:d.arr[2]],NULL,paste("V",4+1:d.arr[4],sep="")))
92> aa <- array(1:20,c(2,2,5))
93> str(apply(aa[FALSE,,,drop=FALSE], 1, dim))# empty integer, `incorrect' dim.
94 int(0)
95> stopifnot(
96+        apply(arr, 1:2, sum) == t(apply(arr, 2:1, sum)),
97+        aa == apply(aa,2:3,function(x) x),
98+        all.equal(apply(apply(aa,2:3, sum),2,sum),
99+                  10+16*0:4, tolerance = 4*.Machine$double.eps)
100+ )
101> marg <- list(1:2, 2:3, c(2,4), c(1,3), 2:4, 1:3, 1:4)
102> for(m in marg) print(apply(arr, print(m), sum))
103[1] 1 2
104        a    b    c
105[1,] 1160 1200 1240
106[2,] 1180 1220 1260
107[1] 2 3
108  [,1] [,2] [,3] [,4]
109a  495  555  615  675
110b  515  575  635  695
111c  535  595  655  715
112[1] 2 4
113   V5  V6  V7  V8  V9
114a  84 276 468 660 852
115b 100 292 484 676 868
116c 116 308 500 692 884
117[1] 1 3
118     [,1] [,2] [,3] [,4]
119[1,]  765  855  945 1035
120[2,]  780  870  960 1050
121[1] 2 3 4
122, , V5
123
124  [,1] [,2] [,3] [,4]
125a    3   15   27   39
126b    7   19   31   43
127c   11   23   35   47
128
129, , V6
130
131  [,1] [,2] [,3] [,4]
132a   51   63   75   87
133b   55   67   79   91
134c   59   71   83   95
135
136, , V7
137
138  [,1] [,2] [,3] [,4]
139a   99  111  123  135
140b  103  115  127  139
141c  107  119  131  143
142
143, , V8
144
145  [,1] [,2] [,3] [,4]
146a  147  159  171  183
147b  151  163  175  187
148c  155  167  179  191
149
150, , V9
151
152  [,1] [,2] [,3] [,4]
153a  195  207  219  231
154b  199  211  223  235
155c  203  215  227  239
156
157[1] 1 2 3
158, , 1
159
160       a   b   c
161[1,] 245 255 265
162[2,] 250 260 270
163
164, , 2
165
166       a   b   c
167[1,] 275 285 295
168[2,] 280 290 300
169
170, , 3
171
172       a   b   c
173[1,] 305 315 325
174[2,] 310 320 330
175
176, , 4
177
178       a   b   c
179[1,] 335 345 355
180[2,] 340 350 360
181
182[1] 1 2 3 4
183, , 1, V5
184
185     a b c
186[1,] 1 3 5
187[2,] 2 4 6
188
189, , 2, V5
190
191     a  b  c
192[1,] 7  9 11
193[2,] 8 10 12
194
195, , 3, V5
196
197      a  b  c
198[1,] 13 15 17
199[2,] 14 16 18
200
201, , 4, V5
202
203      a  b  c
204[1,] 19 21 23
205[2,] 20 22 24
206
207, , 1, V6
208
209      a  b  c
210[1,] 25 27 29
211[2,] 26 28 30
212
213, , 2, V6
214
215      a  b  c
216[1,] 31 33 35
217[2,] 32 34 36
218
219, , 3, V6
220
221      a  b  c
222[1,] 37 39 41
223[2,] 38 40 42
224
225, , 4, V6
226
227      a  b  c
228[1,] 43 45 47
229[2,] 44 46 48
230
231, , 1, V7
232
233      a  b  c
234[1,] 49 51 53
235[2,] 50 52 54
236
237, , 2, V7
238
239      a  b  c
240[1,] 55 57 59
241[2,] 56 58 60
242
243, , 3, V7
244
245      a  b  c
246[1,] 61 63 65
247[2,] 62 64 66
248
249, , 4, V7
250
251      a  b  c
252[1,] 67 69 71
253[2,] 68 70 72
254
255, , 1, V8
256
257      a  b  c
258[1,] 73 75 77
259[2,] 74 76 78
260
261, , 2, V8
262
263      a  b  c
264[1,] 79 81 83
265[2,] 80 82 84
266
267, , 3, V8
268
269      a  b  c
270[1,] 85 87 89
271[2,] 86 88 90
272
273, , 4, V8
274
275      a  b  c
276[1,] 91 93 95
277[2,] 92 94 96
278
279, , 1, V9
280
281      a   b   c
282[1,] 97  99 101
283[2,] 98 100 102
284
285, , 2, V9
286
287       a   b   c
288[1,] 103 105 107
289[2,] 104 106 108
290
291, , 3, V9
292
293       a   b   c
294[1,] 109 111 113
295[2,] 110 112 114
296
297, , 4, V9
298
299       a   b   c
300[1,] 115 117 119
301[2,] 116 118 120
302
303> for(m in marg) ## 75% of the time here was spent on the names
304+   print(dim(apply(arr, print(m), quantile, names=FALSE)) == c(5,d.arr[m]))
305[1] 1 2
306[1] TRUE TRUE TRUE
307[1] 2 3
308[1] TRUE TRUE TRUE
309[1] 2 4
310[1] TRUE TRUE TRUE
311[1] 1 3
312[1] TRUE TRUE TRUE
313[1] 2 3 4
314[1] TRUE TRUE TRUE TRUE
315[1] 1 2 3
316[1] TRUE TRUE TRUE TRUE
317[1] 1 2 3 4
318[1] TRUE TRUE TRUE TRUE TRUE
319>
320> ## Bessel
321> nus <- c(0:5,10,20)
322>
323> x0 <- 2^(-20:10)
324> plot(x0,x0, log='xy', ylab="", ylim=c(.1,1e60),type='n',
325+      main = "Bessel Functions -Y_nu(x)  near 0\n log - log  scale")
326> for(nu in sort(c(nus,nus+.5))) lines(x0, -besselY(x0,nu=nu), col = nu+2)
327> legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)
328>
329> x <- seq(3,500);yl <- c(-.3, .2)
330> plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  Y_nu(x)")
331> for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
332> legend(300,-.08, leg=paste("nu=",nus), col = nus+2, lwd=1)
333>
334> x <- seq(10,50000,by=10);yl <- c(-.1, .1)
335> plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  Y_nu(x)")
336> for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
337> summary(bY <- besselY(2,nu = nu <- seq(0,100,len=501)))
338       Min.     1st Qu.      Median        Mean     3rd Qu.        Max.
339-3.001e+155 -1.067e+107  -1.976e+62 -9.961e+152  -2.059e+23   1.000e+00
340> which(bY >= 0)
341[1] 1 2 3 4 5
342> summary(bY <- besselY(2,nu = nu <- seq(3,300,len=51)))
343       Min.     1st Qu.      Median        Mean     3rd Qu.        Max.
344       -Inf        -Inf -2.248e+263        -Inf -3.777e+116  -1.000e+00
345There were 22 warnings (use warnings() to see them)
346> summary(bI <- besselI(x = x <- 10:700, 1))
347      Min.    1st Qu.     Median       Mean    3rd Qu.       Max.
348 2.671e+03  6.026e+77 3.161e+152 3.501e+299 2.409e+227 1.529e+302
349> ## end of moved from Bessel.Rd
350>
351> ## data.frame
352> set.seed(123)
353> L3 <- LETTERS[1:3]
354> d <- data.frame(cbind(x=1, y=1:10), fac = sample(L3, 10, replace=TRUE),
355+                 stringsAsFactors=TRUE)
356> str(d)
357'data.frame':	10 obs. of  3 variables:
358 $ x  : num  1 1 1 1 1 1 1 1 1 1
359 $ y  : num  1 2 3 4 5 6 7 8 9 10
360 $ fac: Factor w/ 3 levels "A","B","C": 3 3 3 2 3 2 2 2 3 1
361> (d0  <- d[, FALSE]) # NULL dataframe with 10 rows
362data frame with 0 columns and 10 rows
363> (d.0 <- d[FALSE, ]) # <0 rows> dataframe  (3 cols)
364[1] x   y   fac
365<0 rows> (or 0-length row.names)
366> (d00 <- d0[FALSE,]) # NULL dataframe with 0 rows
367data frame with 0 columns and 0 rows
368> stopifnot(identical(d, cbind(d, d0)),
369+           identical(d, cbind(d0, d)))
370> stopifnot(identical(d, rbind(d,d.0)),
371+           identical(d, rbind(d.0,d)),
372+           identical(d, rbind(d00,d)),
373+           identical(d, rbind(d,d00)))
374> ## Comments: failed before ver. 1.4.0
375>
376> ## diag
377> diag(array(1:4, dim=5))
378     [,1] [,2] [,3] [,4] [,5]
379[1,]    1    0    0    0    0
380[2,]    0    2    0    0    0
381[3,]    0    0    3    0    0
382[4,]    0    0    0    4    0
383[5,]    0    0    0    0    1
384> ## test behaviour with 0 rows or columns
385> diag(0)
386<0 x 0 matrix>
387> z <- matrix(0, 0, 4)
388> diag(z)
389numeric(0)
390> diag(z) <- numeric(0)
391> z
392     [,1] [,2] [,3] [,4]
393> ## end of moved from diag.Rd
394>
395> ## format
396> ## handling of quotes
397> zz <- data.frame(a=I("abc"), b=I("def\"gh"))
398> format(zz)
399    a      b
4001 abc def"gh
401> ## " (E fontification)
402>
403> ## printing more than 16 is platform-dependent
404> for(i in c(1:5,10,15,16)) cat(i,":\t",format(pi,digits=i),"\n")
4051 :	 3
4062 :	 3.1
4073 :	 3.14
4084 :	 3.142
4095 :	 3.1416
41010 :	 3.141592654
41115 :	 3.14159265358979
41216 :	 3.141592653589793
413>
414> p <- c(47,13,2,.1,.023,.0045, 1e-100)/1000
415> format.pval(p)
416[1] "0.0470"  "0.0130"  "0.0020"  "0.0001"  "2.3e-05" "4.5e-06" "< 2e-16"
417> format.pval(p / 0.9)
418[1] "0.05222222" "0.01444444" "0.00222222" "0.00011111" "2.5556e-05"
419[6] "5.0000e-06" "< 2.22e-16"
420> format.pval(p / 0.9, dig=3)
421[1] "0.052222" "0.014444" "0.002222" "0.000111" "2.56e-05" "5.00e-06" "< 2e-16"
422> ## end of moved from format.Rd
423>
424>
425> ## is.finite
426> x <- c(100,-1e-13,Inf,-Inf, NaN, pi, NA)
427> x #  1.000000 -3.000000       Inf      -Inf        NA  3.141593        NA
428[1]  1.000000e+02 -1.000000e-13           Inf          -Inf           NaN
429[6]  3.141593e+00            NA
430> names(x) <- formatC(x, dig=3)
431> is.finite(x)
432   100 -1e-13    Inf   -Inf    NaN   3.14     NA
433  TRUE   TRUE  FALSE  FALSE  FALSE   TRUE  FALSE
434> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
435> ##-     T      T   .    .   .    T  .
436> is.na(x)
437   100 -1e-13    Inf   -Inf    NaN   3.14     NA
438 FALSE  FALSE  FALSE  FALSE   TRUE  FALSE   TRUE
439> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
440> ##-     .      .   .    .   T    .  T
441> which(is.na(x) & !is.nan(x))# only 'NA': 7
442  NA
443   7
444>
445> is.na(x) | is.finite(x)
446   100 -1e-13    Inf   -Inf    NaN   3.14     NA
447  TRUE   TRUE  FALSE  FALSE   TRUE   TRUE   TRUE
448> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
449> ##-     T      T   .    .   T    T  T
450> is.infinite(x)
451   100 -1e-13    Inf   -Inf    NaN   3.14     NA
452 FALSE  FALSE   TRUE   TRUE  FALSE  FALSE  FALSE
453> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
454> ##-     .      .   T    T   .    .  .
455>
456> ##-- either  finite or infinite  or  NA:
457> all(is.na(x) != is.finite(x) | is.infinite(x)) # TRUE
458[1] TRUE
459> all(is.nan(x) != is.finite(x) | is.infinite(x)) # FALSE: have 'real' NA
460[1] FALSE
461>
462> ##--- Integer
463> (ix <- structure(as.integer(x),names= names(x)))
464   100 -1e-13    Inf   -Inf    NaN   3.14     NA
465   100      0     NA     NA     NA      3     NA
466Warning message:
467In structure(as.integer(x), names = names(x)) :
468  NAs introduced by coercion to integer range
469> ##-   100 -1e-13    Inf   -Inf    NaN   3.14     NA
470> ##-   100      0     NA     NA     NA      3     NA
471> all(is.na(ix) != is.finite(ix) | is.infinite(ix)) # TRUE (still)
472[1] TRUE
473>
474> storage.mode(ii <- -3:5)
475[1] "integer"
476> storage.mode(zm <- outer(ii,ii, FUN="*"))# integer
477[1] "double"
478> storage.mode(zd <- outer(ii,ii, FUN="/"))# double
479[1] "double"
480> range(zd, na.rm=TRUE)# -Inf  Inf
481[1] -Inf  Inf
482> zd[,ii==0]
483[1] -Inf -Inf -Inf  NaN  Inf  Inf  Inf  Inf  Inf
484>
485> (storage.mode(print(1:1 / 0:0)))# Inf "double"
486[1] Inf
487[1] "double"
488> (storage.mode(print(1:1 / 1:1)))# 1 "double"
489[1] 1
490[1] "double"
491> (storage.mode(print(1:1 + 1:1)))# 2 "integer"
492[1] 2
493[1] "integer"
494> (storage.mode(print(2:2 * 2:2)))# 4 "integer"
495[1] 4
496[1] "integer"
497> ## end of moved from is.finite.Rd
498>
499>
500> ## kronecker
501> fred <- matrix(1:12, 3, 4, dimnames=list(LETTERS[1:3], LETTERS[4:7]))
502> bill <- c("happy" = 100, "sad" = 1000)
503> kronecker(fred, bill, make.dimnames = TRUE)
504          D:   E:   F:    G:
505A:happy  100  400  700  1000
506A:sad   1000 4000 7000 10000
507B:happy  200  500  800  1100
508B:sad   2000 5000 8000 11000
509C:happy  300  600  900  1200
510C:sad   3000 6000 9000 12000
511>
512> bill <- outer(bill, c("cat"=3, "dog"=4))
513> kronecker(fred, bill, make.dimnames = TRUE)
514        D:cat D:dog E:cat E:dog F:cat F:dog G:cat G:dog
515A:happy   300   400  1200  1600  2100  2800  3000  4000
516A:sad    3000  4000 12000 16000 21000 28000 30000 40000
517B:happy   600   800  1500  2000  2400  3200  3300  4400
518B:sad    6000  8000 15000 20000 24000 32000 33000 44000
519C:happy   900  1200  1800  2400  2700  3600  3600  4800
520C:sad    9000 12000 18000 24000 27000 36000 36000 48000
521>
522> # dimnames are hard work: let's test them thoroughly
523>
524> dimnames(bill) <- NULL
525> kronecker(fred, bill, make=TRUE)
526     D:    D:    E:    E:    F:    F:    G:    G:
527A:  300   400  1200  1600  2100  2800  3000  4000
528A: 3000  4000 12000 16000 21000 28000 30000 40000
529B:  600   800  1500  2000  2400  3200  3300  4400
530B: 6000  8000 15000 20000 24000 32000 33000 44000
531C:  900  1200  1800  2400  2700  3600  3600  4800
532C: 9000 12000 18000 24000 27000 36000 36000 48000
533> kronecker(bill, fred, make=TRUE)
534     :D    :E    :F    :G    :D    :E    :F    :G
535:A  300  1200  2100  3000   400  1600  2800  4000
536:B  600  1500  2400  3300   800  2000  3200  4400
537:C  900  1800  2700  3600  1200  2400  3600  4800
538:A 3000 12000 21000 30000  4000 16000 28000 40000
539:B 6000 15000 24000 33000  8000 20000 32000 44000
540:C 9000 18000 27000 36000 12000 24000 36000 48000
541>
542> dim(bill) <- c(2, 2, 1)
543> dimnames(bill) <- list(c("happy", "sad"), NULL, "")
544> kronecker(fred, bill, make=TRUE)
545, , :
546
547          D:    D:    E:    E:    F:    F:    G:    G:
548A:happy  300   400  1200  1600  2100  2800  3000  4000
549A:sad   3000  4000 12000 16000 21000 28000 30000 40000
550B:happy  600   800  1500  2000  2400  3200  3300  4400
551B:sad   6000  8000 15000 20000 24000 32000 33000 44000
552C:happy  900  1200  1800  2400  2700  3600  3600  4800
553C:sad   9000 12000 18000 24000 27000 36000 36000 48000
554
555>
556> bill <- array(1:24, c(3, 4, 2))
557> dimnames(bill) <- list(NULL, NULL, c("happy", "sad"))
558> kronecker(bill, fred, make=TRUE)
559, , happy:
560
561   :D :E :F :G :D :E :F :G :D :E :F  :G :D :E  :F  :G
562:A  1  4  7 10  4 16 28 40  7 28 49  70 10 40  70 100
563:B  2  5  8 11  8 20 32 44 14 35 56  77 20 50  80 110
564:C  3  6  9 12 12 24 36 48 21 42 63  84 30 60  90 120
565:A  2  8 14 20  5 20 35 50  8 32 56  80 11 44  77 110
566:B  4 10 16 22 10 25 40 55 16 40 64  88 22 55  88 121
567:C  6 12 18 24 15 30 45 60 24 48 72  96 33 66  99 132
568:A  3 12 21 30  6 24 42 60  9 36 63  90 12 48  84 120
569:B  6 15 24 33 12 30 48 66 18 45 72  99 24 60  96 132
570:C  9 18 27 36 18 36 54 72 27 54 81 108 36 72 108 144
571
572, , sad:
573
574   :D :E  :F  :G :D  :E  :F  :G :D  :E  :F  :G :D  :E  :F  :G
575:A 13 52  91 130 16  64 112 160 19  76 133 190 22  88 154 220
576:B 26 65 104 143 32  80 128 176 38  95 152 209 44 110 176 242
577:C 39 78 117 156 48  96 144 192 57 114 171 228 66 132 198 264
578:A 14 56  98 140 17  68 119 170 20  80 140 200 23  92 161 230
579:B 28 70 112 154 34  85 136 187 40 100 160 220 46 115 184 253
580:C 42 84 126 168 51 102 153 204 60 120 180 240 69 138 207 276
581:A 15 60 105 150 18  72 126 180 21  84 147 210 24  96 168 240
582:B 30 75 120 165 36  90 144 198 42 105 168 231 48 120 192 264
583:C 45 90 135 180 54 108 162 216 63 126 189 252 72 144 216 288
584
585> kronecker(fred, bill, make=TRUE)
586, , :happy
587
588   D: D: D: D: E: E: E: E: F: F: F:  F: G: G:  G:  G:
589A:  1  4  7 10  4 16 28 40  7 28 49  70 10 40  70 100
590A:  2  5  8 11  8 20 32 44 14 35 56  77 20 50  80 110
591A:  3  6  9 12 12 24 36 48 21 42 63  84 30 60  90 120
592B:  2  8 14 20  5 20 35 50  8 32 56  80 11 44  77 110
593B:  4 10 16 22 10 25 40 55 16 40 64  88 22 55  88 121
594B:  6 12 18 24 15 30 45 60 24 48 72  96 33 66  99 132
595C:  3 12 21 30  6 24 42 60  9 36 63  90 12 48  84 120
596C:  6 15 24 33 12 30 48 66 18 45 72  99 24 60  96 132
597C:  9 18 27 36 18 36 54 72 27 54 81 108 36 72 108 144
598
599, , :sad
600
601   D: D: D: D: E:  E:  E:  E:  F:  F:  F:  F:  G:  G:  G:  G:
602A: 13 16 19 22 52  64  76  88  91 112 133 154 130 160 190 220
603A: 14 17 20 23 56  68  80  92  98 119 140 161 140 170 200 230
604A: 15 18 21 24 60  72  84  96 105 126 147 168 150 180 210 240
605B: 26 32 38 44 65  80  95 110 104 128 152 176 143 176 209 242
606B: 28 34 40 46 70  85 100 115 112 136 160 184 154 187 220 253
607B: 30 36 42 48 75  90 105 120 120 144 168 192 165 198 231 264
608C: 39 48 57 66 78  96 114 132 117 144 171 198 156 192 228 264
609C: 42 51 60 69 84 102 120 138 126 153 180 207 168 204 240 276
610C: 45 54 63 72 90 108 126 144 135 162 189 216 180 216 252 288
611
612>
613> fred <- outer(fred, c("frequentist"=4, "bayesian"=4000))
614> kronecker(fred, bill, make=TRUE)
615, , frequentist:happy
616
617   D: D:  D:  D: E:  E:  E:  E:  F:  F:  F:  F:  G:  G:  G:  G:
618A:  4 16  28  40 16  64 112 160  28 112 196 280  40 160 280 400
619A:  8 20  32  44 32  80 128 176  56 140 224 308  80 200 320 440
620A: 12 24  36  48 48  96 144 192  84 168 252 336 120 240 360 480
621B:  8 32  56  80 20  80 140 200  32 128 224 320  44 176 308 440
622B: 16 40  64  88 40 100 160 220  64 160 256 352  88 220 352 484
623B: 24 48  72  96 60 120 180 240  96 192 288 384 132 264 396 528
624C: 12 48  84 120 24  96 168 240  36 144 252 360  48 192 336 480
625C: 24 60  96 132 48 120 192 264  72 180 288 396  96 240 384 528
626C: 36 72 108 144 72 144 216 288 108 216 324 432 144 288 432 576
627
628, , frequentist:sad
629
630    D:  D:  D:  D:  E:  E:  E:  E:  F:  F:  F:  F:  G:  G:   G:   G:
631A:  52  64  76  88 208 256 304 352 364 448 532 616 520 640  760  880
632A:  56  68  80  92 224 272 320 368 392 476 560 644 560 680  800  920
633A:  60  72  84  96 240 288 336 384 420 504 588 672 600 720  840  960
634B: 104 128 152 176 260 320 380 440 416 512 608 704 572 704  836  968
635B: 112 136 160 184 280 340 400 460 448 544 640 736 616 748  880 1012
636B: 120 144 168 192 300 360 420 480 480 576 672 768 660 792  924 1056
637C: 156 192 228 264 312 384 456 528 468 576 684 792 624 768  912 1056
638C: 168 204 240 276 336 408 480 552 504 612 720 828 672 816  960 1104
639C: 180 216 252 288 360 432 504 576 540 648 756 864 720 864 1008 1152
640
641, , bayesian:happy
642
643      D:    D:     D:     D:    E:     E:     E:     E:     F:     F:     F:
644A:  4000 16000  28000  40000 16000  64000 112000 160000  28000 112000 196000
645A:  8000 20000  32000  44000 32000  80000 128000 176000  56000 140000 224000
646A: 12000 24000  36000  48000 48000  96000 144000 192000  84000 168000 252000
647B:  8000 32000  56000  80000 20000  80000 140000 200000  32000 128000 224000
648B: 16000 40000  64000  88000 40000 100000 160000 220000  64000 160000 256000
649B: 24000 48000  72000  96000 60000 120000 180000 240000  96000 192000 288000
650C: 12000 48000  84000 120000 24000  96000 168000 240000  36000 144000 252000
651C: 24000 60000  96000 132000 48000 120000 192000 264000  72000 180000 288000
652C: 36000 72000 108000 144000 72000 144000 216000 288000 108000 216000 324000
653       F:     G:     G:     G:     G:
654A: 280000  40000 160000 280000 400000
655A: 308000  80000 200000 320000 440000
656A: 336000 120000 240000 360000 480000
657B: 320000  44000 176000 308000 440000
658B: 352000  88000 220000 352000 484000
659B: 384000 132000 264000 396000 528000
660C: 360000  48000 192000 336000 480000
661C: 396000  96000 240000 384000 528000
662C: 432000 144000 288000 432000 576000
663
664, , bayesian:sad
665
666       D:     D:     D:     D:     E:     E:     E:     E:     F:     F:     F:
667A:  52000  64000  76000  88000 208000 256000 304000 352000 364000 448000 532000
668A:  56000  68000  80000  92000 224000 272000 320000 368000 392000 476000 560000
669A:  60000  72000  84000  96000 240000 288000 336000 384000 420000 504000 588000
670B: 104000 128000 152000 176000 260000 320000 380000 440000 416000 512000 608000
671B: 112000 136000 160000 184000 280000 340000 400000 460000 448000 544000 640000
672B: 120000 144000 168000 192000 300000 360000 420000 480000 480000 576000 672000
673C: 156000 192000 228000 264000 312000 384000 456000 528000 468000 576000 684000
674C: 168000 204000 240000 276000 336000 408000 480000 552000 504000 612000 720000
675C: 180000 216000 252000 288000 360000 432000 504000 576000 540000 648000 756000
676       F:     G:     G:      G:      G:
677A: 616000 520000 640000  760000  880000
678A: 644000 560000 680000  800000  920000
679A: 672000 600000 720000  840000  960000
680B: 704000 572000 704000  836000  968000
681B: 736000 616000 748000  880000 1012000
682B: 768000 660000 792000  924000 1056000
683C: 792000 624000 768000  912000 1056000
684C: 828000 672000 816000  960000 1104000
685C: 864000 720000 864000 1008000 1152000
686
687> ## end of moved from kronecker.Rd
688>
689> ## merge
690> authors <- data.frame(
691+     surname = c("Tukey", "Venables", "Tierney", "Ripley", "McNeil"),
692+     nationality = c("US", "Australia", "US", "UK", "Australia"),
693+     deceased = c("yes", rep("no", 4)), stringsAsFactors=TRUE)
694> books <- data.frame(
695+     name = c("Tukey", "Venables", "Tierney",
696+              "Ripley", "Ripley", "McNeil", "R Core"),
697+     title = c("Exploratory Data Analysis",
698+               "Modern Applied Statistics ...",
699+               "LISP-STAT",
700+               "Spatial Statistics", "Stochastic Simulation",
701+               "Interactive Data Analysis",
702+               "An Introduction to R"),
703+     other.author = c(NA, "Ripley", NA, NA, NA, NA,
704+ 		     "Venables & Smith"),
705+ 	   stringsAsFactors=TRUE)
706> b2 <- books; names(b2)[1] <- names(authors)[1]
707>
708> merge(authors, b2, all.x = TRUE)
709   surname nationality deceased                         title other.author
7101   McNeil   Australia       no     Interactive Data Analysis         <NA>
7112   Ripley          UK       no            Spatial Statistics         <NA>
7123   Ripley          UK       no         Stochastic Simulation         <NA>
7134  Tierney          US       no                     LISP-STAT         <NA>
7145    Tukey          US      yes     Exploratory Data Analysis         <NA>
7156 Venables   Australia       no Modern Applied Statistics ...       Ripley
716> merge(authors, b2, all.y = TRUE)
717   surname nationality deceased                         title     other.author
7181   McNeil   Australia       no     Interactive Data Analysis             <NA>
7192   Ripley          UK       no            Spatial Statistics             <NA>
7203   Ripley          UK       no         Stochastic Simulation             <NA>
7214  Tierney          US       no                     LISP-STAT             <NA>
7225    Tukey          US      yes     Exploratory Data Analysis             <NA>
7236 Venables   Australia       no Modern Applied Statistics ...           Ripley
7247   R Core        <NA>     <NA>          An Introduction to R Venables & Smith
725>
726> ## empty d.f. :
727> merge(authors, b2[7,])
728[1] surname      nationality  deceased     title        other.author
729<0 rows> (or 0-length row.names)
730>
731> merge(authors, b2[7,], all.y = TRUE)
732  surname nationality deceased                title     other.author
7331  R Core        <NA>     <NA> An Introduction to R Venables & Smith
734> merge(authors, b2[7,], all.x = TRUE)
735   surname nationality deceased title other.author
7361   McNeil   Australia       no  <NA>         <NA>
7372   Ripley          UK       no  <NA>         <NA>
7383  Tierney          US       no  <NA>         <NA>
7394    Tukey          US      yes  <NA>         <NA>
7405 Venables   Australia       no  <NA>         <NA>
741> ## end of moved from merge.Rd
742>
743> ## NA
744> is.na(c(1,NA))
745[1] FALSE  TRUE
746> is.na(paste(c(1,NA)))
747[1] FALSE FALSE
748> is.na(list())# logical(0)
749logical(0)
750> ll <- list(pi,"C",NaN,Inf, 1:3, c(0,NA), NA)
751> is.na (ll)
752[1] FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE
753> lapply(ll, is.nan)  # is.nan no longer works on lists
754[[1]]
755[1] FALSE
756
757[[2]]
758[1] FALSE
759
760[[3]]
761[1] TRUE
762
763[[4]]
764[1] FALSE
765
766[[5]]
767[1] FALSE FALSE FALSE
768
769[[6]]
770[1] FALSE FALSE
771
772[[7]]
773[1] FALSE
774
775> ## end of moved from NA.Rd
776>
777> ## is.na was returning unset values on nested lists
778> ll <- list(list(1))
779> for (i in 1:5) print(as.integer(is.na(ll)))
780[1] 0
781[1] 0
782[1] 0
783[1] 0
784[1] 0
785>
786> ## scale
787> ## test out NA handling
788> tm <- matrix(c(2,1,0,1,0,NA,NA,NA,0), nrow=3)
789> scale(tm, , FALSE)
790     [,1] [,2] [,3]
791[1,]    1  0.5   NA
792[2,]    0 -0.5   NA
793[3,]   -1   NA    0
794attr(,"scaled:center")
795[1] 1.0 0.5 0.0
796> scale(tm)
797     [,1]       [,2] [,3]
798[1,]    1  0.7071068   NA
799[2,]    0 -0.7071068   NA
800[3,]   -1         NA  NaN
801attr(,"scaled:center")
802[1] 1.0 0.5 0.0
803attr(,"scaled:scale")
804[1] 1.0000000 0.7071068 0.0000000
805> ## end of moved from scale.Rd
806>
807> ## tabulate
808> tabulate(numeric(0))
809[1] 0
810> ## end of moved from tabulate.Rd
811>
812> ## ts
813> # Ensure working arithmetic for 'ts' objects :
814> z <- ts(matrix(1:900, 100, 3), start = c(1961, 1), frequency = 12)
815> stopifnot(z == z)
816> stopifnot(z-z == 0)
817>
818> ts(1:5, start=2, end=4) # truncate
819Time Series:
820Start = 2
821End = 4
822Frequency = 1
823[1] 1 2 3
824> ts(1:5, start=3, end=17)# repeat
825Time Series:
826Start = 3
827End = 17
828Frequency = 1
829 [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
830> ## end of moved from ts.Rd
831>
832> ### end of moved
833>
834>
835> ## PR 715 (Printing list elements w/attributes)
836> ##
837> l <- list(a=10)
838> attr(l$a, "xx") <- 23
839> l
840$a
841[1] 10
842attr(,"xx")
843[1] 23
844
845> ## Comments:
846> ## should print as
847> # $a:
848> # [1] 10
849> # attr($a, "xx"):
850> # [1] 23
851>
852> ## On the other hand
853> m <- matrix(c(1, 2, 3, 0, 10, NA), 3, 2)
854> na.omit(m)
855     [,1] [,2]
856[1,]    1    0
857[2,]    2   10
858attr(,"na.action")
859[1] 3
860attr(,"class")
861[1] "omit"
862> ## should print as
863> #      [,1] [,2]
864> # [1,]    1    0
865> # [2,]    2   10
866> # attr(,"na.action")
867> # [1] 3
868> # attr(,"na.action")
869> # [1] "omit"
870>
871> ## and
872> x <- 1
873> attr(x, "foo") <- list(a="a")
874> x
875[1] 1
876attr(,"foo")
877attr(,"foo")$a
878[1] "a"
879
880> ## should print as
881> # [1] 1
882> # attr(,"foo")
883> # attr(,"foo")$a
884> # [1] "a"
885>
886>
887> ## PR 746 (printing of lists)
888> ##
889> test.list <- list(A = list(formula=Y~X, subset=TRUE),
890+                   B = list(formula=Y~X, subset=TRUE))
891>
892> test.list
893$A
894$A$formula
895Y ~ X
896
897$A$subset
898[1] TRUE
899
900
901$B
902$B$formula
903Y ~ X
904
905$B$subset
906[1] TRUE
907
908
909> ## Comments:
910> ## should print as
911> # $A
912> # $A$formula
913> # Y ~ X
914> #
915> # $A$subset
916> # [1] TRUE
917> #
918> #
919> # $B
920> # $B$formula
921> # Y ~ X
922> #
923> # $B$subset
924> # [1] TRUE
925>
926> ## Marc Feldesman 2001-Feb-01.  Precision in summary.data.frame & *.matrix
927> summary(attenu)
928     event            mag           station         dist
929 Min.   : 1.00   Min.   :5.000   117    :  5   Min.   :  0.50
930 1st Qu.: 9.00   1st Qu.:5.300   1028   :  4   1st Qu.: 11.32
931 Median :18.00   Median :6.100   113    :  4   Median : 23.40
932 Mean   :14.74   Mean   :6.084   112    :  3   Mean   : 45.60
933 3rd Qu.:20.00   3rd Qu.:6.600   135    :  3   3rd Qu.: 47.55
934 Max.   :23.00   Max.   :7.700   (Other):147   Max.   :370.00
935                                 NA's   : 16
936     accel
937 Min.   :0.00300
938 1st Qu.:0.04425
939 Median :0.11300
940 Mean   :0.15422
941 3rd Qu.:0.21925
942 Max.   :0.81000
943
944> summary(attenu, digits = 5)
945     event             mag            station         dist
946 Min.   : 1.000   Min.   :5.0000   117    :  5   Min.   :  0.500
947 1st Qu.: 9.000   1st Qu.:5.3000   1028   :  4   1st Qu.: 11.325
948 Median :18.000   Median :6.1000   113    :  4   Median : 23.400
949 Mean   :14.742   Mean   :6.0841   112    :  3   Mean   : 45.603
950 3rd Qu.:20.000   3rd Qu.:6.6000   135    :  3   3rd Qu.: 47.550
951 Max.   :23.000   Max.   :7.7000   (Other):147   Max.   :370.000
952                                   NA's   : 16
953     accel
954 Min.   :0.00300
955 1st Qu.:0.04425
956 Median :0.11300
957 Mean   :0.15422
958 3rd Qu.:0.21925
959 Max.   :0.81000
960
961> summary(data.matrix(attenu), digits = 5)# the same for matrix
962     event             mag            station             dist
963 Min.   : 1.000   Min.   :5.0000   Min.   :  1.000   Min.   :  0.500
964 1st Qu.: 9.000   1st Qu.:5.3000   1st Qu.: 24.250   1st Qu.: 11.325
965 Median :18.000   Median :6.1000   Median : 56.500   Median : 23.400
966 Mean   :14.742   Mean   :6.0841   Mean   : 56.928   Mean   : 45.603
967 3rd Qu.:20.000   3rd Qu.:6.6000   3rd Qu.: 86.750   3rd Qu.: 47.550
968 Max.   :23.000   Max.   :7.7000   Max.   :117.000   Max.   :370.000
969                                   NA's   :16
970     accel
971 Min.   :0.00300
972 1st Qu.:0.04425
973 Median :0.11300
974 Mean   :0.15422
975 3rd Qu.:0.21925
976 Max.   :0.81000
977
978> ## Comments:
979> ## No difference between these in 1.2.1 and earlier
980> set.seed(1)
981> x <- c(round(runif(10), 2), 10000)
982> summary(x)
983     Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
984    0.060     0.320     0.630   909.592     0.905 10000.000
985> summary(data.frame(x))
986       x
987 Min.   :    0.060
988 1st Qu.:    0.320
989 Median :    0.630
990 Mean   :  909.592
991 3rd Qu.:    0.905
992 Max.   :10000.000
993> ## Comments:
994> ## All entries show all 3 digits after the decimal point now.
995>
996> ## Chong Gu 2001-Feb-16.  step on binomials
997> detg1 <-
998+ structure(list(Temp = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L,
999+     1L, 2L, 1L, 2L, 1L), .Label = c("High", "Low"), class = "factor"),
1000+     M.user = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
1001+     1L, 2L, 2L), .Label = c("N", "Y"), class = "factor"),
1002+     Soft = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L),
1003+     .Label = c("Hard", "Medium", "Soft"), class = "factor"),
1004+     M = c(42, 30, 52, 43,
1005+     50, 23, 55, 47, 53, 27, 49, 29), X = c(68, 42, 37, 24, 66,
1006+     33, 47, 23, 63, 29, 57, 19)), .Names = c("Temp", "M.user",
1007+ "Soft", "M", "X"), class = "data.frame", row.names = c("1", "3",
1008+ "5", "7", "9", "11", "13", "15", "17", "19", "21", "23"))
1009> detg1.m0 <- glm(cbind(X,M)~1,binomial,detg1)
1010> detg1.m0
1011
1012Call:  glm(formula = cbind(X, M) ~ 1, family = binomial, data = detg1)
1013
1014Coefficients:
1015(Intercept)
1016    0.01587
1017
1018Degrees of Freedom: 11 Total (i.e. Null);  11 Residual
1019Null Deviance:	    32.83
1020Residual Deviance: 32.83 	AIC: 92.52
1021> step(detg1.m0,scope=list(upper=~M.user*Temp*Soft))
1022Start:  AIC=92.52
1023cbind(X, M) ~ 1
1024
1025         Df Deviance    AIC
1026+ M.user  1   12.244 73.942
1027+ Temp    1   28.464 90.162
1028<none>        32.826 92.524
1029+ Soft    2   32.430 96.128
1030
1031Step:  AIC=73.94
1032cbind(X, M) ~ M.user
1033
1034         Df Deviance    AIC
1035+ Temp    1    8.444 72.142
1036<none>        12.244 73.942
1037+ Soft    2   11.967 77.665
1038- M.user  1   32.826 92.524
1039
1040Step:  AIC=72.14
1041cbind(X, M) ~ M.user + Temp
1042
1043              Df Deviance    AIC
1044+ M.user:Temp  1    5.656 71.354
1045<none>              8.444 72.142
1046- Temp         1   12.244 73.942
1047+ Soft         2    8.228 75.926
1048- M.user       1   28.464 90.162
1049
1050Step:  AIC=71.35
1051cbind(X, M) ~ M.user + Temp + M.user:Temp
1052
1053              Df Deviance    AIC
1054<none>             5.6560 71.354
1055- M.user:Temp  1   8.4440 72.142
1056+ Soft         2   5.4952 75.193
1057
1058Call:  glm(formula = cbind(X, M) ~ M.user + Temp + M.user:Temp, family = binomial,
1059    data = detg1)
1060
1061Coefficients:
1062    (Intercept)          M.userY          TempLow  M.userY:TempLow
1063        0.26236         -0.85183          0.04411          0.44427
1064
1065Degrees of Freedom: 11 Total (i.e. Null);  8 Residual
1066Null Deviance:	    32.83
1067Residual Deviance: 5.656 	AIC: 71.35
1068>
1069> ## PR 829 (empty values in all.vars)
1070> ## This example by Uwe Ligges <ligges@statistik.uni-dortmund.de>
1071>
1072> temp <- matrix(1:4, 2)
1073> all.vars(temp ~ 3) # OK
1074[1] "temp"
1075> all.vars(temp[1, ] ~ 3) # wrong in 1.2.1
1076[1] "temp"
1077>
1078> ## 2001-Feb-22 from David Scott.
1079> ## rank-deficient residuals in a manova model.
1080> gofX.df<-
1081+   structure(list(A = c(0.696706709347165, 0.362357754476673,
1082+ -0.0291995223012888,
1083+ 0.696706709347165, 0.696706709347165, -0.0291995223012888, 0.696706709347165,
1084+ -0.0291995223012888, 0.362357754476673, 0.696706709347165, -0.0291995223012888,
1085+ 0.362357754476673, -0.416146836547142, 0.362357754476673, 0.696706709347165,
1086+ 0.696706709347165, 0.362357754476673, -0.416146836547142, -0.0291995223012888,
1087+ -0.416146836547142, 0.696706709347165, -0.416146836547142, 0.362357754476673,
1088+ -0.0291995223012888), B = c(0.717356090899523, 0.932039085967226,
1089+ 0.999573603041505, 0.717356090899523, 0.717356090899523, 0.999573603041505,
1090+ 0.717356090899523, 0.999573603041505, 0.932039085967226, 0.717356090899523,
1091+ 0.999573603041505, 0.932039085967226, 0.909297426825682, 0.932039085967226,
1092+ 0.717356090899523, 0.717356090899523, 0.932039085967226, 0.909297426825682,
1093+ 0.999573603041505, 0.909297426825682, 0.717356090899523, 0.909297426825682,
1094+ 0.932039085967226, 0.999573603041505), C = c(-0.0291995223012888,
1095+ -0.737393715541246, -0.998294775794753, -0.0291995223012888,
1096+ -0.0291995223012888, -0.998294775794753, -0.0291995223012888,
1097+ -0.998294775794753, -0.737393715541246, -0.0291995223012888,
1098+ -0.998294775794753, -0.737393715541246, -0.653643620863612, -0.737393715541246,
1099+ -0.0291995223012888, -0.0291995223012888, -0.737393715541246,
1100+ -0.653643620863612, -0.998294775794753, -0.653643620863612,
1101+ -0.0291995223012888,
1102+ -0.653643620863612, -0.737393715541246, -0.998294775794753),
1103+     D = c(0.999573603041505, 0.67546318055115, -0.0583741434275801,
1104+     0.999573603041505, 0.999573603041505, -0.0583741434275801,
1105+     0.999573603041505, -0.0583741434275801, 0.67546318055115,
1106+     0.999573603041505, -0.0583741434275801, 0.67546318055115,
1107+     -0.756802495307928, 0.67546318055115, 0.999573603041505,
1108+     0.999573603041505, 0.67546318055115, -0.756802495307928,
1109+     -0.0583741434275801, -0.756802495307928, 0.999573603041505,
1110+     -0.756802495307928, 0.67546318055115, -0.0583741434275801
1111+     ), groups = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
1112+     2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3), class = "factor", .Label = c("1",
1113+     "2", "3"))), .Names = c("A", "B", "C", "D", "groups"), row.names = 1:24,
1114+             class = "data.frame")
1115>
1116> gofX.manova <- manova(formula = cbind(A, B, C, D) ~ groups, data = gofX.df)
1117> try(summary(gofX.manova))
1118Error in summary.manova(gofX.manova) : residuals have rank 3 < 4
1119> ## should fail with an error message `residuals have rank 3 < 4'
1120>
1121> ## Prior to 1.3.0 dist did not handle missing values, and the
1122> ## internal C code was incorrectly scaling for missing values.
1123> z <- as.matrix(t(trees))
1124> z[1,1] <- z[2,2] <- z[3,3] <- z[2,4] <- NA
1125> dist(z, method="euclidean")
1126          Girth   Height
1127Height 352.4365
1128Volume 123.5503 261.5802
1129> dist(z, method="maximum")
1130       Girth Height
1131Height  72.7
1132Volume  56.4   63.3
1133> dist(z, method="manhattan")
1134           Girth    Height
1135Height 1954.8821
1136Volume  557.1448 1392.3429
1137> dist(z, method="canberra")
1138          Girth   Height
1139Height 21.66477
1140Volume 10.96200 13.63365
1141>
1142> ## F. Tusell 2001-03-07.  printing kernels.
1143> kernel("daniell", m=5)
1144Daniell(5)
1145coef[-5] = 0.09091
1146coef[-4] = 0.09091
1147coef[-3] = 0.09091
1148coef[-2] = 0.09091
1149coef[-1] = 0.09091
1150coef[ 0] = 0.09091
1151coef[ 1] = 0.09091
1152coef[ 2] = 0.09091
1153coef[ 3] = 0.09091
1154coef[ 4] = 0.09091
1155coef[ 5] = 0.09091
1156> kernel("modified.daniell", m=5)
1157mDaniell(5)
1158coef[-5] = 0.05
1159coef[-4] = 0.10
1160coef[-3] = 0.10
1161coef[-2] = 0.10
1162coef[-1] = 0.10
1163coef[ 0] = 0.10
1164coef[ 1] = 0.10
1165coef[ 2] = 0.10
1166coef[ 3] = 0.10
1167coef[ 4] = 0.10
1168coef[ 5] = 0.05
1169> kernel("daniell", m=c(3,5,7))
1170Daniell(3,5,7)
1171coef[-15] = 0.0008658
1172coef[-14] = 0.0025974
1173coef[-13] = 0.0051948
1174coef[-12] = 0.0086580
1175coef[-11] = 0.0129870
1176coef[-10] = 0.0181818
1177coef[ -9] = 0.0242424
1178coef[ -8] = 0.0303030
1179coef[ -7] = 0.0363636
1180coef[ -6] = 0.0424242
1181coef[ -5] = 0.0484848
1182coef[ -4] = 0.0536797
1183coef[ -3] = 0.0580087
1184coef[ -2] = 0.0614719
1185coef[ -1] = 0.0640693
1186coef[  0] = 0.0649351
1187coef[  1] = 0.0640693
1188coef[  2] = 0.0614719
1189coef[  3] = 0.0580087
1190coef[  4] = 0.0536797
1191coef[  5] = 0.0484848
1192coef[  6] = 0.0424242
1193coef[  7] = 0.0363636
1194coef[  8] = 0.0303030
1195coef[  9] = 0.0242424
1196coef[ 10] = 0.0181818
1197coef[ 11] = 0.0129870
1198coef[ 12] = 0.0086580
1199coef[ 13] = 0.0051948
1200coef[ 14] = 0.0025974
1201coef[ 15] = 0.0008658
1202> ## fixed by patch from Adrian Trapletti 2001-03-08
1203>
1204> ## Start new year (i.e. line) at Jan:
1205> (tt <- ts(1:10, start = c(1920,7), end = c(1921,4), freq = 12))
1206     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
12071920                           1   2   3   4   5   6
12081921   7   8   9  10
1209> cbind(tt, tt + 1)
1210         tt tt + 1
1211Jul 1920  1      2
1212Aug 1920  2      3
1213Sep 1920  3      4
1214Oct 1920  4      5
1215Nov 1920  5      6
1216Dec 1920  6      7
1217Jan 1921  7      8
1218Feb 1921  8      9
1219Mar 1921  9     10
1220Apr 1921 10     11
1221>
1222>
1223> ## PR 883 (cor(x,y) when is.null(y))
1224> try(cov(rnorm(10), NULL))
1225Error in cov(rnorm(10), NULL) :
1226  supply both 'x' and 'y' or a matrix-like 'x'
1227> try(cor(rnorm(10), NULL))
1228Error in cor(rnorm(10), NULL) :
1229  supply both 'x' and 'y' or a matrix-like 'x'
1230> ## gave the variance and 1 respectively in 1.2.2.
1231>
1232>
1233> ## PR 960 (format() of a character matrix converts to vector)
1234> ## example from <John.Peters@tip.csiro.au>
1235> a <- matrix(c("axx","b","c","d","e","f","g","h"), nrow=2)
1236> format(a)
1237     [,1]  [,2]  [,3]  [,4]
1238[1,] "axx" "c  " "e  " "g  "
1239[2,] "b  " "d  " "f  " "h  "
1240> format(a, justify="right")
1241     [,1]  [,2]  [,3]  [,4]
1242[1,] "axx" "  c" "  e" "  g"
1243[2,] "  b" "  d" "  f" "  h"
1244> ## lost dimensions in 1.2.3
1245>
1246>
1247> ## PR 963
1248> res <- svd(rbind(1:7))## $v lost dimensions in 1.2.3
1249> if(res$u[1,1] < 0) {res$u <- -res$u; res$v <- -res$v}
1250> res
1251$d
1252[1] 11.83216
1253
1254$u
1255     [,1]
1256[1,]    1
1257
1258$v
1259           [,1]
1260[1,] 0.08451543
1261[2,] 0.16903085
1262[3,] 0.25354628
1263[4,] 0.33806170
1264[5,] 0.42257713
1265[6,] 0.50709255
1266[7,] 0.59160798
1267
1268>
1269>
1270> ## Make sure  on.exit() keeps being evaluated in the proper env [from PD]:
1271> ## A more complete example:
1272> g1 <- function(fitted) { on.exit(remove(fitted)); return(function(foo) foo) }
1273> g2 <- function(fitted) { on.exit(remove(fitted));        function(foo) foo }
1274> f <- function(g) { fitted <- 1; h <- g(fitted); print(fitted)
1275+                    ls(envir=environment(h)) }
1276> f(g1)
1277[1] 1
1278character(0)
1279> f(g2)
1280[1] 1
1281character(0)
1282>
1283> f2 <- function()
1284+ {
1285+   g.foo <- g1
1286+   g.bar <- g2
1287+   g <- function(x,...) UseMethod("g")
1288+   fitted <- 1; class(fitted) <- "foo"
1289+   h <- g(fitted); print(fitted); print(ls(envir=environment(h)))
1290+   fitted <- 1; class(fitted) <- "bar"
1291+   h <- g(fitted); print(fitted); print(ls(envir=environment(h)))
1292+   invisible(NULL)
1293+ }
1294> f2()
1295[1] 1
1296attr(,"class")
1297[1] "foo"
1298character(0)
1299[1] 1
1300attr(,"class")
1301[1] "bar"
1302character(0)
1303> ## The first case in f2() is broken in 1.3.0(-patched).
1304>
1305> ## on.exit() consistency check from Luke:
1306> g <- function() as.environment(-1)
1307> f <- function(x) UseMethod("f")
1308> f.foo <- function(x) { on.exit(e <<- g()); NULL }
1309> f.bar <- function(x) { on.exit(e <<- g()); return(NULL) }
1310> f(structure(1,class = "foo"))
1311NULL
1312> ls(env = e)# only "x", i.e. *not* the GlobalEnv
1313[1] "x"
1314> f(structure(1,class = "bar"))
1315NULL
1316> stopifnot("x" == ls(env = e))# as above; wrongly was .GlobalEnv in R 1.3.x
1317>
1318>
1319> ## some tests that R supports logical variables in formulae
1320> ## it coerced them to numeric prior to 1.4.0
1321> ## they should appear like 2-level factors, following S
1322>
1323> oldCon <- options("contrasts")
1324> y <- rnorm(10)
1325> x <- rep(c(TRUE, FALSE), 5)
1326> model.matrix(y ~ x)
1327   (Intercept) xTRUE
13281            1     1
13292            1     0
13303            1     1
13314            1     0
13325            1     1
13336            1     0
13347            1     1
13358            1     0
13369            1     1
133710           1     0
1338attr(,"assign")
1339[1] 0 1
1340attr(,"contrasts")
1341attr(,"contrasts")$x
1342[1] "contr.treatment"
1343
1344> lm(y ~ x)
1345
1346Call:
1347lm(formula = y ~ x)
1348
1349Coefficients:
1350(Intercept)        xTRUE
1351   -0.05293     -0.20018
1352
1353> DF <- data.frame(x, y)
1354> lm(y ~ x, data=DF)
1355
1356Call:
1357lm(formula = y ~ x, data = DF)
1358
1359Coefficients:
1360(Intercept)        xTRUE
1361   -0.05293     -0.20018
1362
1363> options(contrasts=c("contr.helmert", "contr.poly"))
1364> model.matrix(y ~ x)
1365   (Intercept) x1
13661            1  1
13672            1 -1
13683            1  1
13694            1 -1
13705            1  1
13716            1 -1
13727            1  1
13738            1 -1
13749            1  1
137510           1 -1
1376attr(,"assign")
1377[1] 0 1
1378attr(,"contrasts")
1379attr(,"contrasts")$x
1380[1] "contr.helmert"
1381
1382> lm(y ~ x, data=DF)
1383
1384Call:
1385lm(formula = y ~ x, data = DF)
1386
1387Coefficients:
1388(Intercept)           x1
1389    -0.1530      -0.1001
1390
1391> z <- 1:10
1392> lm(y ~ x*z)
1393
1394Call:
1395lm(formula = y ~ x * z)
1396
1397Coefficients:
1398(Intercept)           x1            z         x1:z
1399  -0.088089    -0.508170    -0.005102     0.073733
1400
1401> lm(y ~ x*z - 1)
1402
1403Call:
1404lm(formula = y ~ x * z - 1)
1405
1406Coefficients:
1407   xFALSE      xTRUE          z       x1:z
1408 0.420081  -0.596259  -0.005102   0.073733
1409
1410> options(oldCon)
1411>
1412> ## diffinv, Adrian Trapletti, 2001-08-27
1413> x <- ts(1:10)
1414> diffinv(diff(x),xi=x[1])
1415Time Series:
1416Start = 1
1417End = 10
1418Frequency = 1
1419 [1]  1  2  3  4  5  6  7  8  9 10
1420> diffinv(diff(x,lag=1,differences=2),lag=1,differences=2,xi=x[1:2])
1421Time Series:
1422Start = 1
1423End = 10
1424Frequency = 1
1425 [1]  1  2  3  4  5  6  7  8  9 10
1426> ## last had wrong start and end
1427>
1428> ## PR#1072  (Reading Inf and NaN values)
1429> as.numeric(as.character(NaN))
1430[1] NaN
1431> as.numeric(as.character(Inf))
1432[1] Inf
1433> ## were NA on Windows at least under 1.3.0.
1434>
1435> ## PR#1092 (rowsum dimnames)
1436> rowsum(matrix(1:12, 3,4), c("Y","X","Y"))
1437  [,1] [,2] [,3] [,4]
1438X    2    5    8   11
1439Y    4   10   16   22
1440> ## rownames were 1,2 in <= 1.3.1.
1441>
1442> ## PR#1115 (saving strings with ascii=TRUE)
1443> x <- y <- unlist(as.list(
1444+     parse(text=paste("\"\\", as.character(as.octmode(1:255)), "\"",sep=""))))
1445> save(x, ascii=TRUE, file=(fn <- tempfile(tmpdir = getwd())))
1446> load(fn)
1447> all(x==y)
1448[1] TRUE
1449> unlink(fn)
1450> ## 1.3.1 had trouble with \
1451>
1452>
1453> ## Some tests of sink() and connections()
1454> ## capture all the output to a file.
1455> zz <- file("all.Rout", open="wt")
1456> sink(zz)
1457> sink(zz, type="message")
1458> try(log("a"))
1459> ## back to the console
1460> sink(type="message")
1461> sink()
1462> try(log("a"))
1463Error in log("a") : non-numeric argument to mathematical function
1464>
1465> ## capture all the output to a file.
1466> zz <- file("all.Rout", open="wt")
1467> sink(zz)
1468> sink(zz, type="message")
1469> try(log("a"))
1470>
1471> ## bail out
1472> closeAllConnections()
1473> (foo <- showConnections())
1474     description class mode text isopen can read can write
1475> stopifnot(nrow(foo) == 0)
1476> try(log("a"))
1477Error in log("a") : non-numeric argument to mathematical function
1478> unlink("all.Rout")
1479> ## many of these were untested before 1.4.0.
1480>
1481>
1482> ## test mean() works on logical but not factor
1483> x <- c(TRUE, FALSE, TRUE, TRUE)
1484> mean(x)
1485[1] 0.75
1486> mean(as.factor(x))
1487[1] NA
1488Warning message:
1489In mean.default(as.factor(x)) :
1490  argument is not numeric or logical: returning NA
1491> ## last had confusing error message in 1.3.1.
1492>
1493>
1494> ## Kurt Hornik 2001-Nov-13
1495> z <- table(x = 1:2, y = 1:2)
1496> z - 1
1497   y
1498x    1  2
1499  1  0 -1
1500  2 -1  0
1501> unclass(z - 1)
1502   y
1503x    1  2
1504  1  0 -1
1505  2 -1  0
1506> ## lost object bit prior to 1.4.0, so printed class attribute.
1507>
1508>
1509> ## PR#1226  (predict.mlm ignored newdata)
1510> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
1511> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
1512> group <- gl(2,10,20, labels = c("Ctl","Trt"))
1513> weight <- c(ctl, trt)
1514> data <- data.frame(weight, group)
1515> fit <- lm(cbind(w=weight, w2=weight^2) ~ group, data=data)
1516> predict(fit, newdata=data[1:2, ])
1517      w       w2
15181 5.032 25.62702
15192 5.032 25.62702
1520> ## was 20 rows in R <= 1.4.0
1521>
1522>
1523> ## Chong Gu 2002-Feb-8: `.' not expanded in drop1
1524> lab <- dimnames(HairEyeColor)
1525> HairEye <- cbind(expand.grid(Hair=lab$Hair, Eye=lab$Eye, Sex=lab$Sex,
1526+ 			     stringsAsFactors = TRUE),
1527+ 		 Fr = as.vector(HairEyeColor))
1528> HairEye.fit <- glm(Fr ~ . ^2, poisson, HairEye)
1529> drop1(HairEye.fit)
1530Single term deletions
1531
1532Model:
1533Fr ~ (Hair + Eye + Sex)^2
1534         Df Deviance    AIC
1535<none>         6.761 191.64
1536Hair:Eye  9  156.678 323.56
1537Hair:Sex  3   18.327 197.21
1538Eye:Sex   3   11.764 190.64
1539> ## broken around 1.2.1 it seems.
1540>
1541>
1542> ## PR#1329  (subscripting matrix lists)
1543> m <- list(a1=1:3, a2=4:6, a3=pi, a4=c("a","b","c"))
1544> dim(m) <- c(2,2)
1545> m
1546     [,1]      [,2]
1547[1,] integer,3 3.141593
1548[2,] integer,3 character,3
1549> m[,2]
1550[[1]]
1551[1] 3.141593
1552
1553[[2]]
1554[1] "a" "b" "c"
1555
1556> m[2,2]
1557[[1]]
1558[1] "a" "b" "c"
1559
1560> ## 1.4.1 returned null components: the case was missing from a switch.
1561>
1562> m <- list(a1=1:3, a2=4:6, a3=pi, a4=c("a","b","c"))
1563> matrix(m, 2, 2)
1564     [,1]      [,2]
1565[1,] integer,3 3.141593
1566[2,] integer,3 character,3
1567> ## 1.4.1 gave `Unimplemented feature in copyVector'
1568>
1569> x <- vector("list",6)
1570> dim(x) <- c(2,3)
1571> x[1,2] <- list(letters[10:11])
1572> x
1573     [,1] [,2]        [,3]
1574[1,] NULL character,2 NULL
1575[2,] NULL NULL        NULL
1576> ## 1.4.1 gave `incompatible types in subset assignment'
1577>
1578>
1579> ## printing of matrix lists
1580> m <- list(as.integer(1), pi, 3+5i, "testit", TRUE, factor("foo"))
1581> dim(m) <- c(1, 6)
1582> m
1583     [,1] [,2]     [,3] [,4]     [,5] [,6]
1584[1,] 1    3.141593 3+5i "testit" TRUE foo
1585> ## prior to 1.5.0 had quotes for 2D case (but not kD, k > 2),
1586> ## gave "numeric,1" etc, (even "numeric,1" for integers and factors)
1587>
1588>
1589> ## ensure RNG is unaltered.
1590> for(type in c("Wichmann-Hill", "Marsaglia-Multicarry", "Super-Duper",
1591+               "Mersenne-Twister", "Knuth-TAOCP", "Knuth-TAOCP-2002"))
1592+ {
1593+     set.seed(123, type)
1594+     print(RNGkind())
1595+     runif(100); print(runif(4))
1596+     set.seed(1000, type)
1597+     runif(100); print(runif(4))
1598+     set.seed(77, type)
1599+     runif(100); print(runif(4))
1600+ }
1601[1] "Wichmann-Hill" "Inversion"     "Rejection"
1602[1] 0.8308841 0.4640221 0.9460082 0.8764644
1603[1] 0.12909876 0.07294851 0.45594560 0.68884911
1604[1] 0.4062450 0.7188432 0.6241738 0.2511611
1605[1] "Marsaglia-Multicarry" "Inversion"            "Rejection"
1606[1] 0.3479705 0.9469351 0.2489207 0.7329251
1607[1] 0.5041512 0.3617873 0.1469184 0.3798119
1608[1] 0.14388128 0.04196294 0.36214015 0.86053575
1609[1] "Super-Duper" "Inversion"   "Rejection"
1610[1] 0.2722510 0.9230240 0.3971743 0.8284474
1611[1] 0.5706241 0.1806023 0.9633860 0.8434444
1612[1] 0.09356585 0.41081124 0.38635627 0.72993396
1613[1] "Mersenne-Twister" "Inversion"        "Rejection"
1614[1] 0.5999890 0.3328235 0.4886130 0.9544738
1615[1] 0.5993679 0.4516818 0.1368254 0.7261788
1616[1] 0.09594961 0.31235651 0.81244335 0.72330846
1617[1] "Knuth-TAOCP" "Inversion"   "Rejection"
1618[1] 0.9445502 0.3366297 0.6296881 0.5914161
1619[1] 0.9213954 0.5468138 0.8817100 0.4442237
1620[1] 0.8016962 0.9226080 0.1473484 0.8827707
1621[1] "Knuth-TAOCP-2002" "Inversion"        "Rejection"
1622[1] 0.9303634 0.2812239 0.1085806 0.8053228
1623[1] 0.2916627 0.9085017 0.7958965 0.1980655
1624[1] 0.05247575 0.28290867 0.20930324 0.16794887
1625Warning messages:
16261: In set.seed(123, type) :
1627  RNGkind: Marsaglia-Multicarry has poor statistical properties
16282: In set.seed(1000, type) :
1629  RNGkind: Marsaglia-Multicarry has poor statistical properties
16303: In set.seed(77, type) :
1631  RNGkind: Marsaglia-Multicarry has poor statistical properties
1632> RNGkind(normal.kind = "Kinderman-Ramage")
1633> set.seed(123)
1634> RNGkind()
1635[1] "Knuth-TAOCP-2002" "Kinderman-Ramage" "Rejection"
1636> rnorm(4)
1637[1] -1.9699090 -2.2429340  0.5339321  0.2097153
1638> RNGkind(normal.kind = "Ahrens-Dieter")
1639> set.seed(123)
1640> RNGkind()
1641[1] "Knuth-TAOCP-2002" "Ahrens-Dieter"    "Rejection"
1642> rnorm(4)
1643[1]  0.06267229  0.12421568 -1.86653499 -0.14535921
1644> RNGkind(normal.kind = "Box-Muller")
1645> set.seed(123)
1646> RNGkind()
1647[1] "Knuth-TAOCP-2002" "Box-Muller"       "Rejection"
1648> rnorm(4)
1649[1]  2.26160990  0.59010303  0.30176045 -0.01346139
1650> set.seed(123)
1651> runif(4)
1652[1] 0.04062130 0.06511825 0.99290488 0.95540467
1653> set.seed(123, "default")
1654> set.seed(123, "Marsaglia-Multicarry") ## Careful, not the default anymore
1655Warning message:
1656In set.seed(123, "Marsaglia-Multicarry") :
1657  RNGkind: Marsaglia-Multicarry has poor statistical properties
1658> runif(4)
1659[1] 0.1200427 0.1991600 0.7292821 0.8115922
1660> ## last set.seed failed < 1.5.0.
1661>
1662>
1663> ## merging, ggrothendieck@yifan.net, 2002-03-16
1664> d.df <- data.frame(x = 1:3, y = c("A","D","E"), z = c(6,9,10))
1665> merge(d.df[1,], d.df)
1666  x y z
16671 1 A 6
1668> ## 1.4.1 got confused by inconsistencies in as.character
1669>
1670>
1671> ## PR#1394 (levels<-.factor)
1672> f <- factor(c("a","b"))
1673> levels(f) <- list(C="C", A="a", B="b")
1674> f
1675[1] A B
1676Levels: C A B
1677> ## was  [1] C A; Levels:  C A  in 1.4.1
1678>
1679>
1680> ## NA levels in factors
1681> (x <- factor(c("a", "NA", "b"), exclude=NULL))
1682[1] a  NA b
1683Levels: NA a b
1684> ## 1.4.1 had wrong order for levels
1685> is.na(x)[3] <- TRUE
1686> x
1687[1] a    NA   <NA>
1688Levels: NA a b
1689> ## missing entry prints as <NA>
1690>
1691>
1692> ## printing/formatting NA strings
1693> (x <- c("a", "NA", NA, "b"))
1694[1] "a"  "NA" NA   "b"
1695> print(x, quote = FALSE)
1696[1] a    NA   <NA> b
1697> paste(x)
1698[1] "a"  "NA" "NA" "b"
1699> format(x)
1700[1] "a " "NA" "NA" "b "
1701> format(x, justify = "right")
1702[1] " a" "NA" "NA" " b"
1703> format(x, justify = "none")
1704[1] "a"  "NA" "NA" "b"
1705> ## not ideal.
1706>
1707>
1708> ## print.ts problems  ggrothendieck@yifan.net on R-help, 2002-04-01
1709> x <- 1:20
1710> tt1 <- ts(x,start=c(1960,2), freq=12)
1711> tt2 <- ts(10+x,start=c(1960,2), freq=12)
1712> cbind(tt1, tt2)
1713         tt1 tt2
1714Feb 1960   1  11
1715Mar 1960   2  12
1716Apr 1960   3  13
1717May 1960   4  14
1718Jun 1960   5  15
1719Jul 1960   6  16
1720Aug 1960   7  17
1721Sep 1960   8  18
1722Oct 1960   9  19
1723Nov 1960  10  20
1724Dec 1960  11  21
1725Jan 1961  12  22
1726Feb 1961  13  23
1727Mar 1961  14  24
1728Apr 1961  15  25
1729May 1961  16  26
1730Jun 1961  17  27
1731Jul 1961  18  28
1732Aug 1961  19  29
1733Sep 1961  20  30
1734> ## 1.4.1 had `Jan 1961' as `NA 1961'
1735> ## ...and 1.9.1 had it as `Jan 1960'!!
1736>
1737> ## glm boundary bugs (related to PR#1331)
1738> x <- c(0.35, 0.64, 0.12, 1.66, 1.52, 0.23, -1.99, 0.42, 1.86, -0.02,
1739+        -1.64, -0.46, -0.1, 1.25, 0.37, 0.31, 1.11, 1.65, 0.33, 0.89,
1740+        -0.25, -0.87, -0.22, 0.71, -2.26, 0.77, -0.05, 0.32, -0.64, 0.39,
1741+        0.19, -1.62, 0.37, 0.02, 0.97, -2.62, 0.15, 1.55, -1.41, -2.35,
1742+        -0.43, 0.57, -0.66, -0.08, 0.02, 0.24, -0.33, -0.03, -1.13, 0.32,
1743+        1.55, 2.13, -0.1, -0.32, -0.67, 1.44, 0.04, -1.1, -0.95, -0.19,
1744+        -0.68, -0.43, -0.84, 0.69, -0.65, 0.71, 0.19, 0.45, 0.45, -1.19,
1745+        1.3, 0.14, -0.36, -0.5, -0.47, -1.31, -1.02, 1.17, 1.51, -0.33,
1746+        -0.01, -0.59, -0.28, -0.18, -1.07, 0.66, -0.71, 1.88, -0.14,
1747+        -0.19, 0.84, 0.44, 1.33, -0.2, -0.45, 1.46, 1, -1.02, 0.68, 0.84)
1748> y <- c(1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0,
1749+        0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1,
1750+        1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1751+        0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
1752+        1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0)
1753> try(glm(y ~ x, family = poisson(identity)))
1754Error : no valid set of coefficients has been found: please supply starting values
1755In addition: Warning message:
1756In log(y/mu) : NaNs produced
1757> ## failed because start = NULL in 1.4.1
1758> ## now gives useful error message
1759> glm(y ~ x, family = poisson(identity), start = c(1,0))
1760
1761Call:  glm(formula = y ~ x, family = poisson(identity), start = c(1,
1762    0))
1763
1764Coefficients:
1765(Intercept)            x
1766     0.5114       0.1690
1767
1768Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
1769Null Deviance:	    68.01
1770Residual Deviance: 60.66 	AIC: 168.7
1771Warning messages:
17721: step size truncated: out of bounds
17732: step size truncated: out of bounds
1774> ## step reduction failed in 1.4.1
1775> set.seed(123)
1776> y <- rpois(100, pmax(3*x, 0))
1777> glm(y ~ x, family = poisson(identity), start = c(1,0))
1778
1779Call:  glm(formula = y ~ x, family = poisson(identity), start = c(1,
1780    0))
1781
1782Coefficients:
1783(Intercept)            x
1784     1.1561       0.4413
1785
1786Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
1787Null Deviance:	    317.2
1788Residual Deviance: 228.5 	AIC: 344.7
1789There were 27 warnings (use warnings() to see them)
1790> warnings()
1791Warning messages:
17921: step size truncated: out of bounds
17932: step size truncated: out of bounds
17943: step size truncated: out of bounds
17954: step size truncated: out of bounds
17965: step size truncated: out of bounds
17976: step size truncated: out of bounds
17987: step size truncated: out of bounds
17998: step size truncated: out of bounds
18009: step size truncated: out of bounds
180110: step size truncated: out of bounds
180211: step size truncated: out of bounds
180312: step size truncated: out of bounds
180413: step size truncated: out of bounds
180514: step size truncated: out of bounds
180615: step size truncated: out of bounds
180716: step size truncated: out of bounds
180817: step size truncated: out of bounds
180918: step size truncated: out of bounds
181019: step size truncated: out of bounds
181120: step size truncated: out of bounds
181221: step size truncated: out of bounds
181322: step size truncated: out of bounds
181423: step size truncated: out of bounds
181524: step size truncated: out of bounds
181625: step size truncated: out of bounds
181726: glm.fit: algorithm did not converge
181827: glm.fit: algorithm stopped at boundary value
1819>
1820>
1821> ## extending char arrrays
1822> x <- y <- LETTERS[1:2]
1823> x[5] <- "C"
1824> length(y) <- 5
1825> x
1826[1] "A" "B" NA  NA  "C"
1827> y
1828[1] "A" "B" NA  NA  NA
1829> ## x was filled with "", y with NA in 1.5.0
1830>
1831>
1832> ## formula with no intercept, 2002-07-22
1833> oldcon <- options(contrasts = c("contr.helmert", "contr.poly"))
1834> U <- gl(3, 6, 18, labels=letters[1:3])
1835> V <- gl(3, 2, 18, labels=letters[1:3])
1836> A <- rep(c(0, 1), 9)
1837> B <- rep(c(1, 0), 9)
1838> set.seed(1); y <- rnorm(18)
1839> terms(y ~ A:U + A:V - 1)
1840y ~ A:U + A:V - 1
1841attr(,"variables")
1842list(y, A, U, V)
1843attr(,"factors")
1844  A:U A:V
1845y   0   0
1846A   2   2
1847U   2   0
1848V   0   1
1849attr(,"term.labels")
1850[1] "A:U" "A:V"
1851attr(,"order")
1852[1] 2 2
1853attr(,"intercept")
1854[1] 0
1855attr(,"response")
1856[1] 1
1857attr(,".Environment")
1858<environment: R_GlobalEnv>
1859> lm(y ~ A:U + A:V - 1)$coefficients  # 1.5.1 used dummies coding for V
1860       A:Ua        A:Ub        A:Uc        A:V1        A:V2
1861 0.25303884 -0.21875499 -0.71708528 -0.61467193 -0.09030436
1862> lm(y ~ (A + B) : (U + V) - 1) # 1.5.1 used dummies coding for A:V but not B:V
1863
1864Call:
1865lm(formula = y ~ (A + B):(U + V) - 1)
1866
1867Coefficients:
1868   A:Ua     A:Ub     A:Uc     A:V1     A:V2     B:Ua     B:Ub     B:Uc
1869 0.2530  -0.2188  -0.7171  -0.6147  -0.0903   1.7428   0.0613   0.7649
1870   B:V1     B:V2
1871-0.4420   0.5388
1872
1873> options(oldcon)
1874> ## 1.5.1 miscomputed the first factor in the formula.
1875>
1876>
1877> ## quantile extremes, MM 13 Apr 2000 and PR#1852
1878> (qq <- sapply(0:5, function(k) {
1879+     x <- c(rep(-Inf,k+1), 0:k, rep(Inf, k))
1880+     sapply(1:9, function(typ)
1881+            quantile(x, pr=(2:10)/10, type=typ))
1882+ }, simplify="array"))
1883, , 1
1884
1885     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
188620%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
188730%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
188840%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
188950%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
189060%     0    0 -Inf -Inf -Inf -Inf -Inf -Inf -Inf
189170%     0    0 -Inf -Inf -Inf    0 -Inf -Inf -Inf
189280%     0    0    0 -Inf    0    0 -Inf    0    0
189390%     0    0    0 -Inf    0    0 -Inf    0    0
1894100%    0    0    0    0    0    0    0    0    0
1895
1896, , 2
1897
1898     [,1] [,2] [,3] [,4] [,5] [,6] [,7]      [,8]  [,9]
189920%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
190030%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
190140%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
190250%     0  0.0 -Inf -Inf  0.0  0.0  0.0 0.0000000 0.000
190360%     0  0.5    0  0.0  0.5  0.6  0.4 0.5333333 0.525
190470%     1  1.0    1  0.5  1.0  Inf  0.8       Inf   Inf
190580%     1  Inf    1  1.0  Inf  Inf  Inf       Inf   Inf
190690%   Inf  Inf    1  Inf  Inf  Inf  Inf       Inf   Inf
1907100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
1908
1909, , 3
1910
1911     [,1] [,2] [,3] [,4] [,5] [,6] [,7]     [,8]  [,9]
191220%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
191330%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
191440%     0  0.0 -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
191550%     0  0.5    0  0.0  0.5  0.5  0.5 0.500000 0.500
191660%     1  1.0    1  0.8  1.3  1.4  1.2 1.333333 1.325
191770%     2  2.0    2  1.6  Inf  Inf  1.9      Inf   Inf
191880%   Inf  Inf    2  Inf  Inf  Inf  Inf      Inf   Inf
191990%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1920100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1921
1922, , 4
1923
1924     [,1] [,2] [,3] [,4] [,5] [,6] [,7]     [,8]  [,9]
192520%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
192630%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
192740%     0    0 -Inf -Inf -Inf -Inf    0     -Inf  -Inf
192850%     1    1    1  0.5  1.0  1.0    1 1.000000 1.000
192960%     2    2    2  1.6  2.1  2.2    2 2.133333 2.125
193070%     3    3    3  2.7  Inf  Inf    3      Inf   Inf
193180%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
193290%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1933100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1934
1935, , 5
1936
1937     [,1] [,2] [,3] [,4] [,5] [,6] [,7]       [,8]  [,9]
193820%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf       -Inf  -Inf
193930%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf       -Inf  -Inf
194040%     0  0.0    0 -Inf  0.1  0.0  0.2 0.06666667 0.075
194150%     1  1.5    1  1.0  1.5  1.5  1.5 1.50000000 1.500
194260%     3  3.0    2  2.4  2.9  3.0  2.8 2.93333333 2.925
194370%     4  4.0    4  3.8  Inf  Inf  Inf        Inf   Inf
194480%   Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
194590%   Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
1946100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
1947
1948, , 6
1949
1950     [,1] [,2] [,3] [,4] [,5] [,6] [,7]      [,8]  [,9]
195120%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
195230%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
195340%     0    0    0 -Inf  0.3  0.2  0.4 0.2666667 0.275
195450%     2    2    1  1.5  2.0  2.0  2.0 2.0000000 2.000
195560%     4    4    3  3.2  3.7  3.8  3.6 3.7333333 3.725
195670%     5    5    5  4.9  Inf  Inf  Inf       Inf   Inf
195780%   Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
195890%   Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
1959100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
1960
1961> x <- c(-Inf, -Inf, Inf, Inf)
1962> median(x)
1963[1] NaN
1964> quantile(x)
1965  0%  25%  50%  75% 100%
1966-Inf -Inf  NaN  Inf  Inf
1967> ## 1.5.1 had -Inf not NaN in several places
1968>
1969>
1970> ## NAs in matrix dimnames
1971> z <- matrix(1:9, 3, 3)
1972> dimnames(z) <- list(c("x", "y", NA), c(1, NA, 3))
1973> z
1974     1 <NA> 3
1975x    1    4 7
1976y    2    5 8
1977<NA> 3    6 9
1978> ## NAs in dimnames misaligned when printing in 1.5.1
1979>
1980>
1981> ## weighted aov (PR#1930)
1982> r <- c(10,23,23,26,17,5,53,55,32,46,10,8,10,8,23,0,3,22,15,32,3)
1983> n <- c(39,62,81,51,39,6,74,72,51,79,13,16,30,28,45,4,12,41,30,51,7)
1984> trt <- factor(rep(1:4,c(5,6,5,5)))
1985> Y <- r/n
1986> z <- aov(Y ~ trt, weights=n)
1987> ## 1.5.1 gave unweighted RSS
1988>
1989>
1990> ## rbind (PR#2266)
1991> test <- as.data.frame(matrix(1:25, 5, 5))
1992> test1 <- matrix(-(1:10), 2, 5)
1993> rbind(test, test1)
1994  V1 V2 V3 V4  V5
19951  1  6 11 16  21
19962  2  7 12 17  22
19973  3  8 13 18  23
19984  4  9 14 19  24
19995  5 10 15 20  25
20006 -1 -3 -5 -7  -9
20017 -2 -4 -6 -8 -10
2002> rbind(test1, test)
2003  V1 V2 V3 V4  V5
20041 -1 -3 -5 -7  -9
20052 -2 -4 -6 -8 -10
20063  1  6 11 16  21
20074  2  7 12 17  22
20085  3  8 13 18  23
20096  4  9 14 19  24
20107  5 10 15 20  25
2011> ## 1.6.1 treated matrix as a vector.
2012>
2013>
2014> ## escapes in non-quoted printing
2015> x <- "\\abc\\"
2016> names(x) <- 1
2017> x
2018        1
2019"\\abc\\"
2020> print(x, quote=FALSE)
2021      1
2022\\abc\\
2023> ## 1.6.2 had label misaligned
2024>
2025>
2026> ## summary on data frames containing data frames (PR#1891)
2027> x <- data.frame(1:10)
2028> x$z <- data.frame(x=1:10,yyy=11:20)
2029> summary(x)
2030     X1.10             z.x             z.yyy
2031 Min.   : 1.00   Min.   : 1.00    Min.   :11.00
2032 1st Qu.: 3.25   1st Qu.: 3.25    1st Qu.:13.25
2033 Median : 5.50   Median : 5.50    Median :15.50
2034 Mean   : 5.50   Mean   : 5.50    Mean   :15.50
2035 3rd Qu.: 7.75   3rd Qu.: 7.75    3rd Qu.:17.75
2036 Max.   :10.00   Max.   :10.00    Max.   :20.00
2037> ## 1.6.2 had NULL labels on output with z columns stacked.
2038>
2039>
2040> ## re-orderings in terms.formula (PR#2206)
2041> form <- formula(y ~ a + b:c + d + e + e:d)
2042> (tt <- terms(form))
2043y ~ a + b:c + d + e + e:d
2044attr(,"variables")
2045list(y, a, b, c, d, e)
2046attr(,"factors")
2047  a d e b:c d:e
2048y 0 0 0   0   0
2049a 1 0 0   0   0
2050b 0 0 0   2   0
2051c 0 0 0   2   0
2052d 0 1 0   0   1
2053e 0 0 1   0   1
2054attr(,"term.labels")
2055[1] "a"   "d"   "e"   "b:c" "d:e"
2056attr(,"order")
2057[1] 1 1 1 2 2
2058attr(,"intercept")
2059[1] 1
2060attr(,"response")
2061[1] 1
2062attr(,".Environment")
2063<environment: R_GlobalEnv>
2064> (tt2 <- terms(formula(tt)))
2065y ~ a + b:c + d + e + e:d
2066attr(,"variables")
2067list(y, a, b, c, d, e)
2068attr(,"factors")
2069  a d e b:c d:e
2070y 0 0 0   0   0
2071a 1 0 0   0   0
2072b 0 0 0   2   0
2073c 0 0 0   2   0
2074d 0 1 0   0   1
2075e 0 0 1   0   1
2076attr(,"term.labels")
2077[1] "a"   "d"   "e"   "b:c" "d:e"
2078attr(,"order")
2079[1] 1 1 1 2 2
2080attr(,"intercept")
2081[1] 1
2082attr(,"response")
2083[1] 1
2084attr(,".Environment")
2085<environment: R_GlobalEnv>
2086> stopifnot(identical(tt, tt2))
2087> terms(delete.response(tt))
2088~a + b:c + d + e + e:d
2089attr(,"variables")
2090list(a, b, c, d, e)
2091attr(,"factors")
2092  a d e b:c d:e
2093a 1 0 0   0   0
2094b 0 0 0   2   0
2095c 0 0 0   2   0
2096d 0 1 0   0   1
2097e 0 0 1   0   1
2098attr(,"term.labels")
2099[1] "a"   "d"   "e"   "b:c" "d:e"
2100attr(,"order")
2101[1] 1 1 1 2 2
2102attr(,"intercept")
2103[1] 1
2104attr(,"response")
2105[1] 0
2106attr(,".Environment")
2107<environment: R_GlobalEnv>
2108> ## both tt and tt2 re-ordered the formula < 1.7.0
2109> ## now try with a dot
2110> terms(breaks ~ ., data = warpbreaks)
2111breaks ~ wool + tension
2112attr(,"variables")
2113list(breaks, wool, tension)
2114attr(,"factors")
2115        wool tension
2116breaks     0       0
2117wool       1       0
2118tension    0       1
2119attr(,"term.labels")
2120[1] "wool"    "tension"
2121attr(,"order")
2122[1] 1 1
2123attr(,"intercept")
2124[1] 1
2125attr(,"response")
2126[1] 1
2127attr(,".Environment")
2128<environment: R_GlobalEnv>
2129> terms(breaks ~ . - tension, data = warpbreaks)
2130breaks ~ (wool + tension) - tension
2131attr(,"variables")
2132list(breaks, wool, tension)
2133attr(,"factors")
2134        wool
2135breaks     0
2136wool       1
2137tension    0
2138attr(,"term.labels")
2139[1] "wool"
2140attr(,"order")
2141[1] 1
2142attr(,"intercept")
2143[1] 1
2144attr(,"response")
2145[1] 1
2146attr(,".Environment")
2147<environment: R_GlobalEnv>
2148> terms(breaks ~ . - tension, data = warpbreaks, simplify = TRUE)
2149breaks ~ wool
2150attr(,"variables")
2151list(breaks, wool, tension)
2152attr(,"factors")
2153        wool
2154breaks     0
2155wool       1
2156tension    0
2157attr(,"term.labels")
2158[1] "wool"
2159attr(,"order")
2160[1] 1
2161attr(,"intercept")
2162[1] 1
2163attr(,"response")
2164[1] 1
2165attr(,".Environment")
2166<environment: R_GlobalEnv>
2167> terms(breaks ~ . ^2, data = warpbreaks)
2168breaks ~ (wool + tension)^2
2169attr(,"variables")
2170list(breaks, wool, tension)
2171attr(,"factors")
2172        wool tension wool:tension
2173breaks     0       0            0
2174wool       1       0            1
2175tension    0       1            1
2176attr(,"term.labels")
2177[1] "wool"         "tension"      "wool:tension"
2178attr(,"order")
2179[1] 1 1 2
2180attr(,"intercept")
2181[1] 1
2182attr(,"response")
2183[1] 1
2184attr(,".Environment")
2185<environment: R_GlobalEnv>
2186> terms(breaks ~ . ^2, data = warpbreaks, simplify = TRUE)
2187breaks ~ wool + tension + wool:tension
2188attr(,"variables")
2189list(breaks, wool, tension)
2190attr(,"factors")
2191        wool tension wool:tension
2192breaks     0       0            0
2193wool       1       0            1
2194tension    0       1            1
2195attr(,"term.labels")
2196[1] "wool"         "tension"      "wool:tension"
2197attr(,"order")
2198[1] 1 1 2
2199attr(,"intercept")
2200[1] 1
2201attr(,"response")
2202[1] 1
2203attr(,".Environment")
2204<environment: R_GlobalEnv>
2205> ## 1.6.2 expanded these formulae out as in simplify = TRUE
2206>
2207>
2208> ## printing attributes (PR#2506)
2209> (x <- structure(1:4, other=as.factor(LETTERS[1:3])))
2210[1] 1 2 3 4
2211attr(,"other")
2212[1] A B C
2213Levels: A B C
2214> ## < 1.7.0 printed the codes of the factor attribute
2215>
2216>
2217> ## add logical matrix replacement indexing for data frames
2218> TEMP <- data.frame(VAR1=c(1,2,3,4,5), VAR2=c(5,4,3,2,1), VAR3=c(1,1,1,1,NA))
2219> TEMP[,c(1,3)][TEMP[,c(1,3)]==1 & !is.na(TEMP[,c(1,3)])] < -10
2220[1] FALSE FALSE FALSE FALSE FALSE
2221> TEMP
2222  VAR1 VAR2 VAR3
22231    1    5    1
22242    2    4    1
22253    3    3    1
22264    4    2    1
22275    5    1   NA
2228> ##
2229>
2230> ## moved from reg-plot.R as exact output depends on rounding error
2231> ## PR 390 (axis for small ranges)
2232>
2233> relrange <- function(x) {
2234+     ## The relative range in EPS units
2235+     r <- range(x)
2236+     diff(r)/max(abs(r))/.Machine$double.eps
2237+ }
2238>
2239> x <- c(0.12345678912345678,
2240+        0.12345678912345679,
2241+        0.12345678912345676)
2242> # relrange(x) ## 1.0125, but depends on strtod
2243> plot(x) # `extra horizontal' ;  +- ok on Solaris; label off on Linux
2244>
2245> y <- c(0.9999563255363383973418,
2246+        0.9999563255363389524533,
2247+        0.9999563255363382863194)
2248> ## The relative range number:
2249> # relrange(y) ## 3.000131, but depends on strtod
2250> plot(y)# once gave infinite loop on Solaris [TL];  y-axis too long
2251>
2252> ## Comments: The whole issue was finally deferred to main/graphics.c l.1944
2253> ##    error("relative range of values is too small to compute accurately");
2254> ## which is not okay.
2255>
2256> set.seed(101)
2257> par(mfrow = c(3,3))
2258> for(j.fac in 1e-12* c(10, 1, .7, .3, .2, .1, .05, .03, .01)) {
2259+ ##           ====
2260+     #set.seed(101) # or don't
2261+     x <- pi + jitter(numeric(101), f = j.fac)
2262+     rrtxt <- paste("rel.range =", formatC(relrange(x), dig = 4),"* EPS")
2263+     cat("j.f = ", format(j.fac)," ;  ", rrtxt,"\n",sep="")
2264+     plot(x, type = "l", main = rrtxt)
2265+     cat("par(\"usr\")[3:4]:", formatC(par("usr")[3:4], wid = 10),"\n",
2266+         "par(\"yaxp\") :   ", formatC(par("yaxp"), wid = 10),"\n\n", sep="")
2267+ }
2268j.f = 1e-11 ;  rel.range = 553.9 * EPS
2269par("usr")[3:4]:     3.142     3.142
2270par("yaxp") :        3.142     3.142         3
2271
2272j.f = 1e-12 ;  rel.range = 56.02 * EPS
2273par("usr")[3:4]:     3.142     3.142
2274par("yaxp") :        3.142     3.142         1
2275
2276j.f = 7e-13 ;  rel.range = 39.47 * EPS
2277par("usr")[3:4]:     3.142     3.142
2278par("yaxp") :        3.142     3.142         1
2279
2280j.f = 3e-13 ;  rel.range = 16.55 * EPS
2281par("usr")[3:4]:     3.142     3.142
2282par("yaxp") :        3.142     3.142         1
2283
2284j.f = 2e-13 ;  rel.range = 11.46 * EPS
2285par("usr")[3:4]:     3.108     3.176
2286par("yaxp") :         3.11      3.17         6
2287
2288j.f = 1e-13 ;  rel.range = 5.093 * EPS
2289par("usr")[3:4]:     3.108     3.176
2290par("yaxp") :         3.11      3.17         6
2291
2292j.f = 5e-14 ;  rel.range = 2.546 * EPS
2293par("usr")[3:4]:     3.108     3.176
2294par("yaxp") :         3.11      3.17         6
2295
2296j.f = 3e-14 ;  rel.range = 1.273 * EPS
2297par("usr")[3:4]:     3.108     3.176
2298par("yaxp") :         3.11      3.17         6
2299
2300j.f = 1e-14 ;  rel.range =     0 * EPS
2301par("usr")[3:4]:     1.784     4.499
2302par("yaxp") :            2         4         4
2303
2304Warning messages:
23051: In plot.window(...) :
2306  relative range of values (  43 * EPS) is small (axis 2)
23072: In plot.window(...) :
2308  relative range of values (  36 * EPS) is small (axis 2)
23093: In plot.window(...) :
2310  relative range of values (   0 * EPS) is small (axis 2)
2311> par(mfrow = c(1,1))
2312> ## The warnings from inside GScale() will differ in their  relrange() ...
2313> ## >> do sloppy testing
2314> ## 2003-02-03 hopefully no more.  BDR
2315> ## end of PR 390
2316>
2317>
2318> ## scoping rules calling step inside a function
2319> "cement" <-
2320+     structure(list(x1 = c(7, 1, 11, 11, 7, 11, 3, 1, 2, 21, 1, 11, 10),
2321+                    x2 = c(26, 29, 56, 31, 52, 55, 71, 31, 54, 47, 40, 66, 68),
2322+                    x3 = c(6, 15, 8, 8, 6, 9, 17, 22, 18, 4, 23, 9, 8),
2323+                    x4 = c(60, 52, 20, 47, 33, 22, 6, 44, 22, 26, 34, 12, 12),
2324+                    y = c(78.5, 74.3, 104.3, 87.6, 95.9, 109.2, 102.7, 72.5,
2325+                    93.1, 115.9, 83.8, 113.3, 109.4)),
2326+               .Names = c("x1", "x2", "x3", "x4", "y"), class = "data.frame",
2327+               row.names = 1:13)
2328> teststep <- function(formula, data)
2329+ {
2330+     d2 <- data
2331+     fit <- lm(formula, data=d2)
2332+     step(fit)
2333+ }
2334> teststep(formula(y ~ .), cement)
2335Start:  AIC=26.94
2336y ~ x1 + x2 + x3 + x4
2337
2338       Df Sum of Sq    RSS    AIC
2339- x3    1    0.1091 47.973 24.974
2340- x4    1    0.2470 48.111 25.011
2341- x2    1    2.9725 50.836 25.728
2342<none>              47.864 26.944
2343- x1    1   25.9509 73.815 30.576
2344
2345Step:  AIC=24.97
2346y ~ x1 + x2 + x4
2347
2348       Df Sum of Sq    RSS    AIC
2349<none>               47.97 24.974
2350- x4    1      9.93  57.90 25.420
2351- x2    1     26.79  74.76 28.742
2352- x1    1    820.91 868.88 60.629
2353
2354Call:
2355lm(formula = y ~ x1 + x2 + x4, data = d2)
2356
2357Coefficients:
2358(Intercept)           x1           x2           x4
2359    71.6483       1.4519       0.4161      -0.2365
2360
2361> ## failed in 1.6.2
2362>
2363> str(array(1))# not a scalar
2364 num [1(1d)] 1
2365>
2366>
2367> ## na.print="" shouldn't apply to (dim)names!
2368> (tf <- table(ff <- factor(c(1:2,NA,2), exclude=NULL)))
2369
2370   1    2 <NA>
2371   1    2    1
2372> identical(levels(ff), dimnames(tf)[[1]])
2373[1] TRUE
2374> str(levels(ff))
2375 chr [1:3] "1" "2" NA
2376> ## not quite ok previous to 1.7.0
2377>
2378>
2379> ## PR#3058  printing with na.print and right=TRUE
2380> a <- matrix( c(NA, "a", "b", "10",
2381+                NA, NA,  "d", "12",
2382+                NA, NA,  NA,  "14"),
2383+             byrow=T, ncol=4 )
2384> print(a, right=TRUE, na.print=" ")
2385     [,1] [,2] [,3] [,4]
2386[1,]       "a"  "b" "10"
2387[2,]            "d" "12"
2388[3,]                "14"
2389> print(a, right=TRUE, na.print="----")
2390     [,1] [,2] [,3] [,4]
2391[1,] ----  "a"  "b" "10"
2392[2,] ---- ----  "d" "12"
2393[3,] ---- ---- ---- "14"
2394> ## misaligned in 1.7.0
2395>
2396>
2397> ## assigning factors to dimnames
2398> A <- matrix(1:4, 2)
2399> aa <- factor(letters[1:2])
2400> dimnames(A) <- list(aa, NULL)
2401> A
2402  [,1] [,2]
2403a    1    3
2404b    2    4
2405> dimnames(A)
2406[[1]]
2407[1] "a" "b"
2408
2409[[2]]
2410NULL
2411
2412> ## 1.7.0 gave internal codes as display and dimnames()
2413> ## 1.7.1beta gave NAs via dimnames()
2414> ## 1.8.0 converts factors to character
2415>
2416>
2417> ## wishlist PR#2776: aliased coefs in lm/glm
2418> set.seed(123)
2419> x2 <- x1 <- 1:10
2420> x3 <- 0.1*(1:10)^2
2421> y <- x1 + rnorm(10)
2422> (fit <- lm(y ~ x1 + x2 + x3))
2423
2424Call:
2425lm(formula = y ~ x1 + x2 + x3)
2426
2427Coefficients:
2428(Intercept)           x1           x2           x3
2429     1.4719       0.5867           NA       0.2587
2430
2431> summary(fit, cor = TRUE)
2432
2433Call:
2434lm(formula = y ~ x1 + x2 + x3)
2435
2436Residuals:
2437    Min      1Q  Median      3Q     Max
2438-1.0572 -0.4836  0.0799  0.4424  1.2699
2439
2440Coefficients: (1 not defined because of singularities)
2441            Estimate Std. Error t value Pr(>|t|)
2442(Intercept)   1.4719     0.9484   1.552    0.165
2443x1            0.5867     0.3961   1.481    0.182
2444x2                NA         NA      NA       NA
2445x3            0.2587     0.3509   0.737    0.485
2446
2447Residual standard error: 0.8063 on 7 degrees of freedom
2448Multiple R-squared:  0.9326,	Adjusted R-squared:  0.9134
2449F-statistic: 48.43 on 2 and 7 DF,  p-value: 7.946e-05
2450
2451Correlation of Coefficients:
2452   (Intercept) x1
2453x1 -0.91
2454x3  0.81       -0.97
2455
2456> (fit <- glm(y ~ x1 + x2 + x3))
2457
2458Call:  glm(formula = y ~ x1 + x2 + x3)
2459
2460Coefficients:
2461(Intercept)           x1           x2           x3
2462     1.4719       0.5867           NA       0.2587
2463
2464Degrees of Freedom: 9 Total (i.e. Null);  7 Residual
2465Null Deviance:	    67.53
2466Residual Deviance: 4.551 	AIC: 28.51
2467> summary(fit, cor = TRUE)
2468
2469Call:
2470glm(formula = y ~ x1 + x2 + x3)
2471
2472Deviance Residuals:
2473    Min       1Q   Median       3Q      Max
2474-1.0572  -0.4836   0.0799   0.4424   1.2699
2475
2476Coefficients: (1 not defined because of singularities)
2477            Estimate Std. Error t value Pr(>|t|)
2478(Intercept)   1.4719     0.9484   1.552    0.165
2479x1            0.5867     0.3961   1.481    0.182
2480x2                NA         NA      NA       NA
2481x3            0.2587     0.3509   0.737    0.485
2482
2483(Dispersion parameter for gaussian family taken to be 0.6501753)
2484
2485    Null deviance: 67.5316  on 9  degrees of freedom
2486Residual deviance:  4.5512  on 7  degrees of freedom
2487AIC: 28.507
2488
2489Number of Fisher Scoring iterations: 2
2490
2491Correlation of Coefficients:
2492   (Intercept) x1
2493x1 -0.91
2494x3  0.81       -0.97
2495
2496> ## omitted silently in summary.glm < 1.8.0
2497>
2498>
2499> ## list-like indexing of data frames with drop specified
2500> women["height"]
2501   height
25021      58
25032      59
25043      60
25054      61
25065      62
25076      63
25087      64
25098      65
25109      66
251110     67
251211     68
251312     69
251413     70
251514     71
251615     72
2517> women["height", drop = FALSE]  # same with a warning
2518   height
25191      58
25202      59
25213      60
25224      61
25235      62
25246      63
25257      64
25268      65
25279      66
252810     67
252911     68
253012     69
253113     70
253214     71
253315     72
2534Warning message:
2535In `[.data.frame`(women, "height", drop = FALSE) :
2536  'drop' argument will be ignored
2537> women["height", drop = TRUE]   # ditto
2538   height
25391      58
25402      59
25413      60
25424      61
25435      62
25446      63
25457      64
25468      65
25479      66
254810     67
254911     68
255012     69
255113     70
255214     71
255315     72
2554Warning message:
2555In `[.data.frame`(women, "height", drop = TRUE) :
2556  'drop' argument will be ignored
2557> women[,"height", drop = FALSE] # no warning
2558   height
25591      58
25602      59
25613      60
25624      61
25635      62
25646      63
25657      64
25668      65
25679      66
256810     67
256911     68
257012     69
257113     70
257214     71
257315     72
2574> women[,"height", drop = TRUE]  # a vector
2575 [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
2576> ## second and third were interpreted as women["height", , drop] in 1.7.x
2577>
2578>
2579> ## make.names
2580> make.names("")
2581[1] "X"
2582> make.names(".aa")
2583[1] ".aa"
2584> ## was "X.aa" in 1.7.1
2585> make.names(".2")
2586[1] "X.2"
2587> make.names(".2a") # not valid in R
2588[1] "X.2a"
2589> make.names(as.character(NA))
2590[1] "NA."
2591> ##
2592>
2593>
2594> ## strange names in data frames
2595> as.data.frame(list(row.names=17))  # 0 rows in 1.7.1
2596  row.names
25971        17
2598> aa <- data.frame(aa=1:3)
2599> aa[["row.names"]] <- 4:6
2600> aa # fine in 1.7.1
2601  aa row.names
26021  1         4
26032  2         5
26043  3         6
2605> A <- matrix(4:9, 3, 2)
2606> colnames(A) <- letters[1:2]
2607> aa[["row.names"]] <- A
2608> aa
2609  aa row.names.a row.names.b
26101  1           4           7
26112  2           5           8
26123  3           6           9
2613> ## wrong printed names in 1.7.1
2614>
2615> ## assigning to NULL --- now consistently behaves as if assigning to list() !
2616> a <- NULL
2617> a[["a"]] <- 1
2618> a
2619$a
2620[1] 1
2621
2622> a <- NULL
2623> a[["a"]] <- "something"
2624> a
2625$a
2626[1] "something"
2627
2628> a <- NULL
2629> a[["a"]] <- 1:3
2630> a
2631$a
2632[1] 1 2 3
2633
2634> ## Last was an error in 1.7.1
2635>
2636>
2637> ## examples of 0-rank models, some empty, some rank-deficient
2638> y <- rnorm(10)
2639> x <- rep(0, 10)
2640> (fit <- lm(y ~ 0))
2641
2642Call:
2643lm(formula = y ~ 0)
2644
2645No coefficients
2646
2647> summary(fit)
2648
2649Call:
2650lm(formula = y ~ 0)
2651
2652Residuals:
2653     Min       1Q   Median       3Q      Max
2654-1.36919 -0.21073  0.00840  0.08437  0.55292
2655
2656No Coefficients
2657
2658Residual standard error: 0.5235 on 10 degrees of freedom
2659
2660> anova(fit)
2661Analysis of Variance Table
2662
2663Response: y
2664          Df Sum Sq Mean Sq F value Pr(>F)
2665Residuals 10 2.7404 0.27404
2666> predict(fit)
2667 1  2  3  4  5  6  7  8  9 10
2668 0  0  0  0  0  0  0  0  0  0
2669> predict(fit, data.frame(x=x), se=TRUE)
2670$fit
2671 1  2  3  4  5  6  7  8  9 10
2672 0  0  0  0  0  0  0  0  0  0
2673
2674$se.fit
2675 [1] 0 0 0 0 0 0 0 0 0 0
2676
2677$df
2678[1] 10
2679
2680$residual.scale
2681[1] 0.5234843
2682
2683> predict(fit, type="terms", se=TRUE)
2684$fit
2685
2686 [1,]
2687 [2,]
2688 [3,]
2689 [4,]
2690 [5,]
2691 [6,]
2692 [7,]
2693 [8,]
2694 [9,]
2695[10,]
2696attr(,"constant")
2697[1] 0
2698
2699$se.fit
2700
2701 [1,]
2702 [2,]
2703 [3,]
2704 [4,]
2705 [5,]
2706 [6,]
2707 [7,]
2708 [8,]
2709 [9,]
2710[10,]
2711
2712$df
2713[1] 10
2714
2715$residual.scale
2716[1] 0.5234843
2717
2718> variable.names(fit) #should be empty
2719character(0)
2720> model.matrix(fit)
2721
27221
27232
27243
27254
27265
27276
27287
27298
27309
273110
2732attr(,"assign")
2733integer(0)
2734>
2735> (fit <- lm(y ~ x + 0))
2736
2737Call:
2738lm(formula = y ~ x + 0)
2739
2740Coefficients:
2741 x
2742NA
2743
2744> summary(fit)
2745
2746Call:
2747lm(formula = y ~ x + 0)
2748
2749Residuals:
2750     Min       1Q   Median       3Q      Max
2751-1.36919 -0.21073  0.00840  0.08437  0.55292
2752
2753Coefficients: (1 not defined because of singularities)
2754  Estimate Std. Error t value Pr(>|t|)
2755x       NA         NA      NA       NA
2756
2757Residual standard error: 0.5235 on 10 degrees of freedom
2758
2759> anova(fit)
2760Analysis of Variance Table
2761
2762Response: y
2763          Df Sum Sq Mean Sq F value Pr(>F)
2764Residuals 10 2.7404 0.27404
2765> predict(fit)
2766 1  2  3  4  5  6  7  8  9 10
2767 0  0  0  0  0  0  0  0  0  0
2768> predict(fit, data.frame(x=x), se=TRUE)
2769$fit
2770 1  2  3  4  5  6  7  8  9 10
2771 0  0  0  0  0  0  0  0  0  0
2772
2773$se.fit
2774 [1] 0 0 0 0 0 0 0 0 0 0
2775
2776$df
2777[1] 10
2778
2779$residual.scale
2780[1] 0.5234843
2781
2782Warning message:
2783In predict.lm(fit, data.frame(x = x), se = TRUE) :
2784  prediction from a rank-deficient fit may be misleading
2785> predict(fit, type="terms", se=TRUE)
2786$fit
2787   x
27881  0
27892  0
27903  0
27914  0
27925  0
27936  0
27947  0
27958  0
27969  0
279710 0
2798attr(,"constant")
2799[1] 0
2800
2801$se.fit
2802   x
28031  0
28042  0
28053  0
28064  0
28075  0
28086  0
28097  0
28108  0
28119  0
281210 0
2813
2814$df
2815[1] 10
2816
2817$residual.scale
2818[1] 0.5234843
2819
2820> variable.names(fit) #should be empty
2821character(0)
2822> model.matrix(fit)
2823   x
28241  0
28252  0
28263  0
28274  0
28285  0
28296  0
28307  0
28318  0
28329  0
283310 0
2834attr(,"assign")
2835[1] 1
2836>
2837> (fit <- glm(y ~ 0))
2838
2839Call:  glm(formula = y ~ 0)
2840
2841No coefficients
2842
2843
2844Degrees of Freedom: 10 Total (i.e. Null);  10 Residual
2845Null Deviance:	    2.74
2846Residual Deviance: 2.74 	AIC: 17.43
2847> summary(fit)
2848
2849Call:
2850glm(formula = y ~ 0)
2851
2852Deviance Residuals:
2853     Min        1Q    Median        3Q       Max
2854-1.36919  -0.21073   0.00840   0.08437   0.55292
2855
2856No Coefficients
2857
2858(Dispersion parameter for gaussian family taken to be 0.2740358)
2859
2860    Null deviance: 2.7404  on 10  degrees of freedom
2861Residual deviance: 2.7404  on 10  degrees of freedom
2862AIC: 17.434
2863
2864Number of Fisher Scoring iterations: 0
2865
2866> anova(fit)
2867Analysis of Deviance Table
2868
2869Model: gaussian, link: identity
2870
2871Response: y
2872
2873Terms added sequentially (first to last)
2874
2875
2876     Df Deviance Resid. Df Resid. Dev
2877NULL                    10     2.7404
2878> predict(fit)
2879 1  2  3  4  5  6  7  8  9 10
2880 0  0  0  0  0  0  0  0  0  0
2881> predict(fit, data.frame(x=x), se=TRUE)
2882$fit
2883 1  2  3  4  5  6  7  8  9 10
2884 0  0  0  0  0  0  0  0  0  0
2885
2886$se.fit
2887 [1] 0 0 0 0 0 0 0 0 0 0
2888
2889$residual.scale
2890[1] 0.5234843
2891
2892> predict(fit, type="terms", se=TRUE)
2893$fit
2894
2895 [1,]
2896 [2,]
2897 [3,]
2898 [4,]
2899 [5,]
2900 [6,]
2901 [7,]
2902 [8,]
2903 [9,]
2904[10,]
2905attr(,"constant")
2906[1] 0
2907
2908$se.fit
2909
2910 [1,]
2911 [2,]
2912 [3,]
2913 [4,]
2914 [5,]
2915 [6,]
2916 [7,]
2917 [8,]
2918 [9,]
2919[10,]
2920
2921$residual.scale
2922[1] 0.5234843
2923
2924>
2925> (fit <- glm(y ~ x + 0))
2926
2927Call:  glm(formula = y ~ x + 0)
2928
2929Coefficients:
2930 x
2931NA
2932
2933Degrees of Freedom: 10 Total (i.e. Null);  10 Residual
2934Null Deviance:	    2.74
2935Residual Deviance: 2.74 	AIC: 17.43
2936> summary(fit)
2937
2938Call:
2939glm(formula = y ~ x + 0)
2940
2941Deviance Residuals:
2942     Min        1Q    Median        3Q       Max
2943-1.36919  -0.21073   0.00840   0.08437   0.55292
2944
2945Coefficients: (1 not defined because of singularities)
2946  Estimate Std. Error t value Pr(>|t|)
2947x       NA         NA      NA       NA
2948
2949(Dispersion parameter for gaussian family taken to be 0.2740358)
2950
2951    Null deviance: 2.7404  on 10  degrees of freedom
2952Residual deviance: 2.7404  on 10  degrees of freedom
2953AIC: 17.434
2954
2955Number of Fisher Scoring iterations: 2
2956
2957> anova(fit)
2958Analysis of Deviance Table
2959
2960Model: gaussian, link: identity
2961
2962Response: y
2963
2964Terms added sequentially (first to last)
2965
2966
2967     Df Deviance Resid. Df Resid. Dev
2968NULL                    10     2.7404
2969x     0        0        10     2.7404
2970> predict(fit)
2971 1  2  3  4  5  6  7  8  9 10
2972 0  0  0  0  0  0  0  0  0  0
2973> predict(fit, data.frame(x=x), se=TRUE)
2974$fit
2975 1  2  3  4  5  6  7  8  9 10
2976 0  0  0  0  0  0  0  0  0  0
2977
2978$se.fit
2979 [1] 0 0 0 0 0 0 0 0 0 0
2980
2981$residual.scale
2982[1] 0.5234843
2983
2984Warning message:
2985In predict.lm(object, newdata, se.fit, scale = residual.scale, type = if (type ==  :
2986  prediction from a rank-deficient fit may be misleading
2987> predict(fit, type="terms", se=TRUE)
2988$fit
2989   x
29901  0
29912  0
29923  0
29934  0
29945  0
29956  0
29967  0
29978  0
29989  0
299910 0
3000attr(,"constant")
3001[1] 0
3002
3003$se.fit
3004   x
30051  0
30062  0
30073  0
30084  0
30095  0
30106  0
30117  0
30128  0
30139  0
301410 0
3015
3016$residual.scale
3017[1] 0.5234843
3018
3019> ## Lots of problems in 1.7.x
3020>
3021>
3022> ## lm.influence on deficient lm models
3023> dat <- data.frame(y=rnorm(10), x1=1:10, x2=1:10, x3 = 0, wt=c(0,rep(1, 9)),
3024+                   row.names=letters[1:10])
3025> dat[3, 1] <- dat[4, 2] <- NA
3026> lm.influence(lm(y ~ x1 + x2, data=dat, weights=wt, na.action=na.omit))
3027$hat
3028        b         e         f         g         h         i         j
30290.6546053 0.2105263 0.1546053 0.1447368 0.1809211 0.2631579 0.3914474
3030
3031$coefficients
3032  (Intercept)           x1
3033b  1.39138784 -0.173267165
3034e -0.70930972  0.068642877
3035f  0.12039809 -0.007818058
3036g  0.01971595  0.001314397
3037h  0.03272637 -0.017325726
3038i -0.36929526  0.092323814
3039j  0.33861311 -0.070163076
3040
3041$sigma
3042        b         e         f         g         h         i         j
30430.9641441 0.7434598 1.0496727 1.0681908 1.0389586 0.7633748 1.0093187
3044
3045$wt.res
3046         b          e          f          g          h          i          j
3047 0.5513046 -1.3728575  0.4018482  0.1708716 -0.4793451  1.2925334 -0.5643552
3048
3049> lm.influence(lm(y ~ x1 + x2, data=dat, weights=wt, na.action=na.exclude))
3050$hat
3051        b         e         c         d         f         g         h         i
30520.6546053 0.2105263 0.0000000 0.0000000 0.1546053 0.1447368 0.1809211 0.2631579
3053        j
30540.3914474
3055
3056$coefficients
3057  (Intercept)           x1
3058b  1.39138784 -0.173267165
3059e -0.70930972  0.068642877
3060c  0.00000000  0.000000000
3061d  0.00000000  0.000000000
3062f  0.12039809 -0.007818058
3063g  0.01971595  0.001314397
3064h  0.03272637 -0.017325726
3065i -0.36929526  0.092323814
3066j  0.33861311 -0.070163076
3067
3068$sigma
3069        b         e         c         d         f         g         h         i
30700.9641441 0.7434598 0.9589854 0.9589854 1.0496727 1.0681908 1.0389586 0.7633748
3071        j
30721.0093187
3073
3074$wt.res
3075         b          e          c          d          f          g          h
3076 0.5513046 -1.3728575         NA         NA  0.4018482  0.1708716 -0.4793451
3077         i          j
3078 1.2925334 -0.5643552
3079
3080> lm.influence(lm(y ~ 0, data=dat, weights=wt, na.action=na.omit))
3081$hat
3082b d e f g h i j
30830 0 0 0 0 0 0 0
3084
3085$coefficients
3086
3087b
3088d
3089e
3090f
3091g
3092h
3093i
3094j
3095
3096$sigma
3097        b         d         e         f         g         h         i         j
30980.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3099
3100$wt.res
3101         b          d          e          f          g          h          i
3102 0.3604547  0.1146812 -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918
3103         j
3104 0.3675473
3105
3106> print(width = 99,
3107+ lm.influence(lm(y ~ 0, data=dat, weights=wt, na.action=na.exclude))
3108+ ) ; stopifnot(getOption("width") == 80)
3109$hat
3110b d c e f g h i j
31110 0 0 0 0 0 0 0 0
3112
3113$coefficients
3114
3115b
3116d
3117c
3118e
3119f
3120g
3121h
3122i
3123j
3124
3125$sigma
3126        b         d         c         e         f         g         h         i         j
31270.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3128
3129$wt.res
3130         b          d          c          e          f          g          h          i          j
3131 0.3604547  0.1146812         NA -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918  0.3675473
3132
3133> lm.influence(lm(y ~ 0 + x3, data=dat, weights=wt, na.action=na.omit))
3134$hat
3135b d e f g h i j
31360 0 0 0 0 0 0 0
3137
3138$coefficients
3139
3140b
3141d
3142e
3143f
3144g
3145h
3146i
3147j
3148
3149$sigma
3150        b         d         e         f         g         h         i         j
31510.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3152
3153$wt.res
3154         b          d          e          f          g          h          i
3155 0.3604547  0.1146812 -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918
3156         j
3157 0.3675473
3158
3159> lm.influence(lm(y ~ 0 + x3, data=dat, weights=wt, na.action=na.exclude))
3160$hat
3161b d c e f g h i j
31620 0 0 0 0 0 0 0 0
3163
3164$coefficients
3165
3166b
3167d
3168c
3169e
3170f
3171g
3172h
3173i
3174j
3175
3176$sigma
3177        b         d         c         e         f         g         h         i
31780.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3179        j
31800.9366289
3181
3182$wt.res
3183         b          d          c          e          f          g          h
3184 0.3604547  0.1146812         NA -1.1426753  0.7723744  0.6817419  0.1718693
3185         i          j
3186 2.0840918  0.3675473
3187
3188> lm.influence(lm(y ~ 0, data=dat, na.action=na.exclude))
3189$hat
3190a b c d e f g h i j
31910 0 0 0 0 0 0 0 0 0
3192
3193$coefficients
3194
3195a
3196b
3197c
3198d
3199e
3200f
3201g
3202h
3203i
3204j
3205
3206$sigma
3207        a         b         c         d         e         f         g         h
32080.8860916 0.8860916 0.8860916 0.8860916 0.8860916 0.8860916 0.8860916 0.8860916
3209        i         j
32100.8860916 0.8860916
3211
3212$wt.res
3213         a          b          c          d          e          f          g
3214 0.2196280  0.3604547         NA  0.1146812 -1.1426753  0.7723744  0.6817419
3215         h          i          j
3216 0.1718693  2.0840918  0.3675473
3217
3218> ## last three misbehaved in 1.7.x, none had proper names.
3219>
3220>
3221> ## length of results in ARMAacf when lag.max is used
3222> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=1) # was 4 in 1.7.1
3223        0         1
32241.0000000 0.7644046
3225> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=2)
3226        0         1         2
32271.0000000 0.7644046 0.2676056
3228> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=3)
3229         0          1          2          3
3230 1.0000000  0.7644046  0.2676056 -0.2343150
3231> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=4)
3232         0          1          2          3          4
3233 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538
3234> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=5) # failed in 1.7.1
3235         0          1          2          3          4          5
3236 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538 -0.5099616
3237> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=6)
3238         0          1          2          3          4          5          6
3239 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538 -0.5099616 -0.2784942
3240> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=10)
3241         0          1          2          3          4          5          6
3242 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538 -0.5099616 -0.2784942
3243         7          8          9         10
3244 0.0241137  0.2486313  0.3134551  0.2256408
3245> ##
3246>
3247>
3248> ## Indexing non-existent columns in a data frame
3249> x <- data.frame(a = 1, b = 2)
3250> try(x[c("a", "c")])
3251Error in `[.data.frame`(x, c("a", "c")) : undefined columns selected
3252> try(x[, c("a", "c")])
3253Error in `[.data.frame`(x, , c("a", "c")) : undefined columns selected
3254> try(x[1, c("a", "c")])
3255Error in `[.data.frame`(x, 1, c("a", "c")) : undefined columns selected
3256> ## Second succeeded, third gave uniformative error message in 1.7.x.
3257>
3258>
3259> ## methods(class = ) with namespaces, .Primitives etc (many missing in 1.7.x):
3260> meth2gen <- function(cl)
3261+     noquote(sub(paste("\\.",cl,"$",sep=""),"", c(.S3methods(class = cl))))
3262> meth2gen("data.frame")
3263 [1] $<-           Math          Ops           Summary       [
3264 [6] [<-           [[            [[<-          aggregate     anyDuplicated
3265[11] anyNA         as.data.frame as.list       as.matrix     by
3266[16] cbind         dim           dimnames      dimnames<-    droplevels
3267[21] duplicated    edit          format        formula       head
3268[26] is.na         merge         na.exclude    na.omit       plot
3269[31] print         prompt        rbind         row.names     row.names<-
3270[36] rowsum        split         split<-       stack         str
3271[41] subset        summary       t             tail          transform
3272[46] type.convert  unique        unstack       within        xtfrm
3273> meth2gen("dendrogram")
3274 [1] [[            as.dendrogram as.hclust     cophenetic    cut
3275 [6] labels        merge         nobs          plot          print
3276[11] reorder       rev           str
3277> ## --> the output may need somewhat frequent updating..
3278>
3279>
3280> ## subsetting a 1D array lost the dimensions
3281> x <- array(1:5, dim=c(5))
3282> dim(x)
3283[1] 5
3284> dim(x[, drop=TRUE])
3285[1] 5
3286> dim(x[2:3])
3287[1] 2
3288> dim(x[2])
3289NULL
3290> dim(x[2, drop=FALSE])
3291[1] 1
3292> dimnames(x) <- list(some=letters[1:5])
3293> x[]
3294some
3295a b c d e
32961 2 3 4 5
3297> x[2:3]
3298some
3299b c
33002 3
3301> x[2]
3302b
33032
3304> x[2, drop=FALSE]
3305some
3306b
33072
3308> ## both dim and dimnames lost in 1.8.0
3309>
3310>
3311> ## print.dist() didn't show NA's prior to 1.8.1
3312> x <- cbind(c(1,NA,2,3), c(NA,2,NA,1))
3313> (d <- dist(x))
3314         1        2        3
33152       NA
33163 1.414214       NA
33174 2.828427 1.414214 1.414214
3318> print(d, diag = TRUE)
3319         1        2        3        4
33201 0.000000
33212       NA 0.000000
33223 1.414214       NA 0.000000
33234 2.828427 1.414214 1.414214 0.000000
3324> ##
3325>
3326>
3327> ## offsets in model terms where sometimes not deleted correctly
3328> attributes(terms(~ a + b + a:b + offset(c)))[c("offset", "term.labels")]
3329$offset
3330[1] 3
3331
3332$term.labels
3333[1] "a"   "b"   "a:b"
3334
3335> attributes(terms(y ~ a + b + a:b + offset(c)))[c("offset", "term.labels")]
3336$offset
3337[1] 4
3338
3339$term.labels
3340[1] "a"   "b"   "a:b"
3341
3342> attributes(terms(~ offset(c) + a + b + a:b))[c("offset", "term.labels")]
3343$offset
3344[1] 1
3345
3346$term.labels
3347[1] "a"   "b"   "a:b"
3348
3349> attributes(terms(y ~ offset(c) + a + b + a:b))[c("offset", "term.labels")]
3350$offset
3351[1] 2
3352
3353$term.labels
3354[1] "a"   "b"   "a:b"
3355
3356> ## errors prior to 1.8.1
3357>
3358>
3359> ## 0-level factors gave nonsensical answers in model.matrix
3360> m <- model.frame(~x, data.frame(x=NA), na.action=na.pass)
3361> model.matrix(~x, m)
3362  (Intercept) xTRUE
33631           1    NA
3364attr(,"assign")
3365[1] 0 1
3366attr(,"contrasts")
3367attr(,"contrasts")$x
3368[1] "contr.treatment"
3369
3370> lm.fit <- lm(y ~ x, data.frame(x=1:10, y=1:10))
3371> try(predict(lm.fit, data.frame(x=NA)))
3372Error : variable 'x' was fitted with type "numeric" but type "logical" was supplied
3373> ## wrong answers in 1.8.0, refused to run in 1.8.1
3374>
3375>
3376>
3377> ## failure to print data frame containing arrays
3378> ## raised by John Fox on R-devel on 2004-01-08
3379> y1 <- array(1:10, dim=10)
3380> y2 <- array(1:30, dim=c(10,3), dimnames=list(NULL, letters[1:3]))
3381> y3 <- array(1:40, dim=c(10,2,2),
3382+             dimnames=list(NULL, letters[1:2], NULL))
3383> data.frame(y=y1)
3384    y
33851   1
33862   2
33873   3
33884   4
33895   5
33906   6
33917   7
33928   8
33939   9
339410 10
3395> data.frame(y=y2)
3396   y.a y.b y.c
33971    1  11  21
33982    2  12  22
33993    3  13  23
34004    4  14  24
34015    5  15  25
34026    6  16  26
34037    7  17  27
34048    8  18  28
34059    9  19  29
340610  10  20  30
3407> data.frame(y=y3)
3408   y.a.1 y.b.1 y.a.2 y.b.2
34091      1    11    21    31
34102      2    12    22    32
34113      3    13    23    33
34124      4    14    24    34
34135      5    15    25    35
34146      6    16    26    36
34157      7    17    27    37
34168      8    18    28    38
34179      9    19    29    39
341810    10    20    30    40
3419>
3420> as.data.frame(y1)
3421   y1
34221   1
34232   2
34243   3
34254   4
34265   5
34276   6
34287   7
34298   8
34309   9
343110 10
3432> as.data.frame(y2)
3433    a  b  c
34341   1 11 21
34352   2 12 22
34363   3 13 23
34374   4 14 24
34385   5 15 25
34396   6 16 26
34407   7 17 27
34418   8 18 28
34429   9 19 29
344310 10 20 30
3444> as.data.frame(y3)
3445   a.1 b.1 a.2 b.2
34461    1  11  21  31
34472    2  12  22  32
34483    3  13  23  33
34494    4  14  24  34
34505    5  15  25  35
34516    6  16  26  36
34527    7  17  27  37
34538    8  18  28  38
34549    9  19  29  39
345510  10  20  30  40
3456>
3457> X <- data.frame(x=1:10)
3458> X$y <- y1
3459> X
3460    x  y
34611   1  1
34622   2  2
34633   3  3
34644   4  4
34655   5  5
34666   6  6
34677   7  7
34688   8  8
34699   9  9
347010 10 10
3471> sapply(X, dim)
3472$x
3473NULL
3474
3475$y
3476[1] 10
3477
3478>
3479> X$y <- y2
3480> X
3481    x y.a y.b y.c
34821   1   1  11  21
34832   2   2  12  22
34843   3   3  13  23
34854   4   4  14  24
34865   5   5  15  25
34876   6   6  16  26
34887   7   7  17  27
34898   8   8  18  28
34909   9   9  19  29
349110 10  10  20  30
3492> sapply(X, dim)
3493$x
3494NULL
3495
3496$y
3497[1] 10  3
3498
3499>
3500> X$y <- y3
3501> X
3502    x y.a.1 y.b.1 y.a.2 y.b.2
35031   1     1    11    21    31
35042   2     2    12    22    32
35053   3     3    13    23    33
35064   4     4    14    24    34
35075   5     5    15    25    35
35086   6     6    16    26    36
35097   7     7    17    27    37
35108   8     8    18    28    38
35119   9     9    19    29    39
351210 10    10    20    30    40
3513> sapply(X, dim)
3514$x
3515NULL
3516
3517$y
3518[1] 10  2  2
3519
3520> ## The last one fails in S.
3521>
3522> ## test of user hooks
3523> for(id in c("A", "B")) {
3524+     eval(substitute(
3525+     {
3526+ setHook(packageEvent("stats4", "onLoad"),
3527+         function(pkgname, ...) cat("onLoad", sQuote(pkgname), id, "\n"));
3528+ setHook(packageEvent("stats4", "attach"),
3529+         function(pkgname, ...) cat("attach", sQuote(pkgname), id, "\n"));
3530+ setHook(packageEvent("stats4", "detach"),
3531+         function(pkgname, ...) cat("detach", sQuote(pkgname), id, "\n"));
3532+ setHook(packageEvent("stats4", "onUnload"),
3533+         function(pkgname, ...) cat("onUnload", sQuote(pkgname), id, "\n"))
3534+     },
3535+                     list(id=id)))
3536+ }
3537> loadNamespace("stats4")
3538onLoad 'stats4' A
3539onLoad 'stats4' B
3540<environment: namespace:stats4>
3541> library("stats4")
3542attach 'stats4' A
3543attach 'stats4' B
3544> detach("package:stats4")
3545detach 'stats4' B
3546detach 'stats4' A
3547> unloadNamespace("stats4")
3548onUnload 'stats4' B
3549onUnload 'stats4' A
3550> ## Just tests
3551>
3552>
3553> ## rep(0-length-vector, length.out > 0)
3554> rep(integer(0), length.out=0)
3555integer(0)
3556> rep(integer(0), length.out=10)
3557 [1] NA NA NA NA NA NA NA NA NA NA
3558> typeof(.Last.value)
3559[1] "integer"
3560> rep(logical(0), length.out=0)
3561logical(0)
3562> rep(logical(0), length.out=10)
3563 [1] NA NA NA NA NA NA NA NA NA NA
3564> typeof(.Last.value)
3565[1] "logical"
3566> rep(numeric(0), length.out=0)
3567numeric(0)
3568> rep(numeric(0), length.out=10)
3569 [1] NA NA NA NA NA NA NA NA NA NA
3570> typeof(.Last.value)
3571[1] "double"
3572> rep(character(0), length.out=0)
3573character(0)
3574> rep(character(0), length.out=10)
3575 [1] NA NA NA NA NA NA NA NA NA NA
3576> typeof(.Last.value)
3577[1] "character"
3578> rep(complex(0), length.out=0)
3579complex(0)
3580> rep(complex(0), length.out=10)
3581 [1] NA NA NA NA NA NA NA NA NA NA
3582> typeof(.Last.value)
3583[1] "complex"
3584> rep(list(), length.out=0)
3585list()
3586> rep(list(), length.out=10)
3587[[1]]
3588NULL
3589
3590[[2]]
3591NULL
3592
3593[[3]]
3594NULL
3595
3596[[4]]
3597NULL
3598
3599[[5]]
3600NULL
3601
3602[[6]]
3603NULL
3604
3605[[7]]
3606NULL
3607
3608[[8]]
3609NULL
3610
3611[[9]]
3612NULL
3613
3614[[10]]
3615NULL
3616
3617> ## always 0-length before 1.9.0
3618>
3619>
3620> ## supplying 0-length data to array and matrix
3621> array(numeric(0), c(2, 2))
3622     [,1] [,2]
3623[1,]   NA   NA
3624[2,]   NA   NA
3625> array(list(), c(2,2))
3626     [,1] [,2]
3627[1,] NULL NULL
3628[2,] NULL NULL
3629> # worked < 1.8.0, error in 1.8.x
3630> matrix(character(0), 1, 2)
3631     [,1] [,2]
3632[1,] NA   NA
3633> matrix(integer(0), 1, 2)
3634     [,1] [,2]
3635[1,]   NA   NA
3636> matrix(logical(0), 1, 2)
3637     [,1] [,2]
3638[1,]   NA   NA
3639> matrix(numeric(0), 1, 2)
3640     [,1] [,2]
3641[1,]   NA   NA
3642> matrix(complex(0), 1, 2)
3643     [,1] [,2]
3644[1,]   NA   NA
3645> matrix(list(), 1, 2)
3646     [,1] [,2]
3647[1,] NULL NULL
3648> ## did not work < 1.9.0
3649>
3650>
3651> ## S compatibility change in 1.9.0
3652> rep(1:2, each=3, length=12)
3653 [1] 1 1 1 2 2 2 1 1 1 2 2 2
3654> ## used to pad with NAs.
3655>
3656>
3657> ## PR#6510: aov() with error and -1
3658> set.seed(1)
3659> test.df <- data.frame (y=rnorm(8), a=gl(2,1,8), b=gl(2,3,8),c=gl(2,4,8))
3660> aov(y ~ a + b + Error(c), data=test.df)
3661
3662Call:
3663aov(formula = y ~ a + b + Error(c), data = test.df)
3664
3665Grand Mean: 0.8066534
3666
3667Stratum 1: c
3668
3669Terms:
3670                        b
3671Sum of Squares  0.3176489
3672Deg. of Freedom         1
3673
3674Estimated effects are balanced
3675
3676Stratum 2: Within
3677
3678Terms:
3679                       a        b Residuals
3680Sum of Squares  1.389453 2.148149  5.048689
3681Deg. of Freedom        1        1         4
3682
3683Residual standard error: 1.123464
3684Estimated effects may be unbalanced
3685> aov(y ~ a + b - 1 + Error(c), data=test.df)
3686
3687Call:
3688aov(formula = y ~ a + b - 1 + Error(c), data = test.df)
3689
3690Stratum 1: c
3691
3692Terms:
3693                       a        b
3694Sum of Squares  5.205518 0.317649
3695Deg. of Freedom        1        1
3696
36971 out of 3 effects not estimable
3698Estimated effects may be unbalanced
3699
3700Stratum 2: Within
3701
3702Terms:
3703                       a        b Residuals
3704Sum of Squares  1.389453 2.148149  5.048689
3705Deg. of Freedom        1        1         4
3706
3707Residual standard error: 1.123464
37081 out of 3 effects not estimable
3709Estimated effects may be unbalanced
3710> ## wrong assignment to strata labels < 1.9.0
3711> ## Note this is unbalanced and not a good example
3712>
3713> binom.test(c(800,10))# p-value < epsilon
3714
3715	Exact binomial test
3716
3717data:  c(800, 10)
3718number of successes = 800, number of trials = 810, p-value < 2.2e-16
3719alternative hypothesis: true probability of success is not equal to 0.5
372095 percent confidence interval:
3721 0.9774134 0.9940643
3722sample estimates:
3723probability of success
3724             0.9876543
3725
3726>
3727>
3728> ## aov with a singular error model
3729> rd <- c(16.53, 12.12, 10.04, 15.32, 12.33, 10.1, 17.09, 11.69, 11.81, 14.75,
3730+         10.72, 8.79, 13.14, 9.79, 8.36, 15.62, 9.64, 8.72, 15.32,
3731+         11.35, 8.52, 13.27, 9.74, 8.78, 13.16, 10.16, 8.4, 13.08, 9.66,
3732+         8.16, 12.17, 9.13, 7.43, 13.28, 9.16, 7.92, 118.77, 78.83, 62.2,
3733+         107.29, 73.79, 58.59, 118.9, 66.35, 53.12, 372.62, 245.39, 223.72,
3734+         326.03, 232.67, 209.44, 297.55, 239.71, 223.8)
3735> sample.df <- data.frame(dep.variable=rd,
3736+                         subject=factor(rep(paste("subj",1:6, sep=""),each=9)),
3737+                         f1=factor(rep(rep(c("f1","f2","f3"),each=6),3)),
3738+                         f2=factor(rep(c("g1","g2","g3"),each=18))
3739+ )
3740> sample.aov <- aov(dep.variable ~ f1 * f2 + Error(subject/(f1+f2)), data=sample.df)
3741Warning message:
3742In aov(dep.variable ~ f1 * f2 + Error(subject/(f1 + f2)), data = sample.df) :
3743  Error() model is singular
3744> sample.aov
3745
3746Call:
3747aov(formula = dep.variable ~ f1 * f2 + Error(subject/(f1 + f2)),
3748    data = sample.df)
3749
3750Grand Mean: 65.07444
3751
3752Stratum 1: subject
3753
3754Terms:
3755                       f1        f2     f1:f2
3756Sum of Squares   47815.99 312824.49 100370.96
3757Deg. of Freedom         1         2         2
3758
37592 out of 7 effects not estimable
3760Estimated effects may be unbalanced
3761
3762Stratum 2: subject:f1
3763
3764Terms:
3765                      f1    f1:f2
3766Sum of Squares  483.9628 869.6876
3767Deg. of Freedom        2        4
3768
3769Estimated effects may be unbalanced
3770
3771Stratum 3: Within
3772
3773Terms:
3774                Residuals
3775Sum of Squares   29204.13
3776Deg. of Freedom        42
3777
3778Residual standard error: 26.36923
3779> summary(sample.aov)
3780
3781Error: subject
3782      Df Sum Sq Mean Sq
3783f1     1  47816   47816
3784f2     2 312824  156412
3785f1:f2  2 100371   50185
3786
3787Error: subject:f1
3788      Df Sum Sq Mean Sq
3789f1     2  484.0   242.0
3790f1:f2  4  869.7   217.4
3791
3792Error: Within
3793          Df Sum Sq Mean Sq F value Pr(>F)
3794Residuals 42  29204   695.3
3795> sample.aov <- aov(dep.variable ~ f1 * f2 + Error(subject/(f2+f1)), data=sample.df)
3796Warning message:
3797In aov(dep.variable ~ f1 * f2 + Error(subject/(f2 + f1)), data = sample.df) :
3798  Error() model is singular
3799> sample.aov
3800
3801Call:
3802aov(formula = dep.variable ~ f1 * f2 + Error(subject/(f2 + f1)),
3803    data = sample.df)
3804
3805Grand Mean: 65.07444
3806
3807Stratum 1: subject
3808
3809Terms:
3810                       f1        f2     f1:f2
3811Sum of Squares   47815.99 312824.49 100370.96
3812Deg. of Freedom         1         2         2
3813
38142 out of 7 effects not estimable
3815Estimated effects may be unbalanced
3816
3817Stratum 2: subject:f1
3818
3819Terms:
3820                      f1    f1:f2
3821Sum of Squares  483.9628 869.6876
3822Deg. of Freedom        2        4
3823
3824Estimated effects may be unbalanced
3825
3826Stratum 3: Within
3827
3828Terms:
3829                Residuals
3830Sum of Squares   29204.13
3831Deg. of Freedom        42
3832
3833Residual standard error: 26.36923
3834> summary(sample.aov)
3835
3836Error: subject
3837      Df Sum Sq Mean Sq
3838f1     1  47816   47816
3839f2     2 312824  156412
3840f1:f2  2 100371   50185
3841
3842Error: subject:f1
3843      Df Sum Sq Mean Sq
3844f1     2  484.0   242.0
3845f1:f2  4  869.7   217.4
3846
3847Error: Within
3848          Df Sum Sq Mean Sq F value Pr(>F)
3849Residuals 42  29204   695.3
3850> ## failed in 1.8.1
3851>
3852>
3853> ## PR#6645  stem() with near-constant values
3854> stem(rep(1, 100))
3855
3856  The decimal point is at the |
3857
3858  1 | 00000000000000000000000000000000000000000000000000000000000000000000+20
3859
3860> stem(rep(0.1, 10))
3861
3862  The decimal point is 1 digit(s) to the left of the |
3863
3864  1 | 0000000000
3865
3866> stem(c(rep(1, 10), 1+1.e-8))
3867
3868  The decimal point is 8 digit(s) to the left of the |
3869
3870  100000000 | 0000000000
3871  100000000 |
3872  100000001 | 0
3873
3874> stem(c(rep(1, 10), 1+1.e-9))
3875
3876  The decimal point is 8 digit(s) to the left of the |
3877
3878  100000000 | 00000000001
3879
3880> stem(c(rep(1, 10), 1+1.e-10), atom=0) # integer-overflow is avoided.
3881
3882  The decimal point is 8 digit(s) to the left of the |
3883
3884  100000000 | 00000000000
3885
3886> ##  had integer overflows in 1.8.1, and silly shifts of decimal point
3887>
3888>
3889> ## PR#6633 warnings with vector op matrix, and more
3890> set.seed(1)
3891> x1 <- rnorm(3)
3892> y1 <- rnorm(4)
3893> x1 * y1
3894[1]  0.5574682  0.1410502  0.1609194 -0.3641637
3895Warning message:
3896In x1 * y1 :
3897  longer object length is not a multiple of shorter object length
3898> x1 * as.matrix(y1) # no warning in 1.8.1
3899           [,1]
3900[1,]  0.5574682
3901[2,]  0.1410502
3902[3,]  0.1609194
3903[4,] -0.3641637
3904Warning message:
3905In x1 * as.matrix(y1) :
3906  longer object length is not a multiple of shorter object length
3907> x1 * matrix(y1,2,2)# ditto
3908          [,1]       [,2]
3909[1,] 0.5574682  0.1609194
3910[2,] 0.1410502 -0.3641637
3911Warning message:
3912In x1 * matrix(y1, 2, 2) :
3913  longer object length is not a multiple of shorter object length
3914> z1 <- x1 > 0
3915> z2 <- y1 > 0
3916> z1 & z2
3917[1]  TRUE  TRUE  TRUE FALSE
3918Warning message:
3919In z1 & z2 :
3920  longer object length is not a multiple of shorter object length
3921> z1 & as.matrix(z2) # no warning in 1.8.1
3922      [,1]
3923[1,]  TRUE
3924[2,]  TRUE
3925[3,]  TRUE
3926[4,] FALSE
3927Warning message:
3928In z1 & as.matrix(z2) :
3929  longer object length is not a multiple of shorter object length
3930> x1 < y1            # no warning in 1.8.1
3931[1] FALSE  TRUE FALSE FALSE
3932Warning message:
3933In x1 < y1 :
3934  longer object length is not a multiple of shorter object length
3935> x1 < as.matrix(y1) # ditto
3936      [,1]
3937[1,] FALSE
3938[2,]  TRUE
3939[3,] FALSE
3940[4,] FALSE
3941Warning message:
3942In x1 < as.matrix(y1) :
3943  longer object length is not a multiple of shorter object length
3944> ##
3945>
3946>
3947> ## summary method for mle
3948> library(stats4)
3949onLoad 'stats4' A
3950onLoad 'stats4' B
3951attach 'stats4' A
3952attach 'stats4' B
3953> N <- c(rep(3:6, 3), 7,7, rep(8,6), 9,9, 10,12)# sample from Pois(lam = 7)
3954> summary(mle(function(Lam = 1) -sum(dpois(N, Lam))))
3955Maximum likelihood estimation
3956
3957Call:
3958mle(minuslogl = function(Lam = 1) -sum(dpois(N, Lam)))
3959
3960Coefficients:
3961    Estimate Std. Error
3962Lam 6.063755   2.307546
3963
3964-2 log L: -5.437059
3965> ## "Coefficients" was "NULL" in 1.9.0's "devel"
3966>
3967>
3968> ## PR#6656 terms.formula(simplify = TRUE) was losing offset terms
3969> ## successive offsets caused problems
3970> df <- data.frame(x=1:4, y=sqrt( 1:4), z=c(2:4,1))
3971> fit1 <- glm(y ~ offset(x) + z, data=df)
3972> update(fit1, ". ~.")$call
3973glm(formula = y ~ z + offset(x), data = df)
3974> ## lost offset in 1.7.0 to 1.8.1
3975> terms(y ~ offset(x) + offset(log(x)) + z, data=df)
3976y ~ offset(x) + offset(log(x)) + z
3977attr(,"variables")
3978list(y, offset(x), offset(log(x)), z)
3979attr(,"offset")
3980[1] 2 3
3981attr(,"factors")
3982               z
3983y              0
3984offset(x)      0
3985offset(log(x)) 0
3986z              1
3987attr(,"term.labels")
3988[1] "z"
3989attr(,"order")
3990[1] 1
3991attr(,"intercept")
3992[1] 1
3993attr(,"response")
3994[1] 1
3995attr(,".Environment")
3996<environment: R_GlobalEnv>
3997> ## failed to remove second offset from formula in 1.8.1
3998> terms(y ~ offset(x) + z - z, data=df, simplify = TRUE)
3999y ~ offset(x)
4000attr(,"variables")
4001list(y, offset(x), z)
4002attr(,"offset")
4003[1] 2
4004attr(,"factors")
4005integer(0)
4006attr(,"term.labels")
4007character(0)
4008attr(,"order")
4009integer(0)
4010attr(,"intercept")
4011[1] 1
4012attr(,"response")
4013[1] 1
4014attr(,".Environment")
4015<environment: R_GlobalEnv>
4016> ## first fix failed for models with no non-offset terms.
4017>
4018>
4019> ## only the first two were wrong up to 1.8.1:
4020> 3:4 * 1e-100
4021[1] 3e-100 4e-100
4022> 8:11* 1e-100
4023[1] 8.0e-100 9.0e-100  1.0e-99  1.1e-99
4024> 1:2 * 1e-99
4025[1] 1e-99 2e-99
4026> 1:2 * 1e+99
4027[1] 1e+99 2e+99
4028> 8:11* 1e+99
4029[1]  8.0e+99  9.0e+99 1.0e+100 1.1e+100
4030> 3:4 * 1e+100
4031[1] 3e+100 4e+100
4032> ##
4033>
4034>
4035> ## negative subscripts could be mixed with NAs
4036> x <- 1:3
4037> try(x[-c(1, NA)])
4038Error in x[-c(1, NA)] : only 0's may be mixed with negative subscripts
4039> ## worked on some platforms, segfaulted on others in 1.8.1
4040>
4041>
4042> ## vector 'border' (and no 'pch', 'cex' nor 'bg'):
4043> boxplot(count ~ spray, data = InsectSprays, border=2:7)
4044> ## gave warnings in 1.9.0
4045>
4046> summary(as.Date(paste("2002-12", 26:31, sep="-")))
4047        Min.      1st Qu.       Median         Mean      3rd Qu.         Max.
4048"2002-12-26" "2002-12-27" "2002-12-28" "2002-12-28" "2002-12-29" "2002-12-31"
4049> ## printed all "2002.-12-29" in 1.9.1 {because digits was too small}
4050> as.matrix(data.frame(d = as.POSIXct("2004-07-20")))
4051     d
4052[1,] "2004-07-20"
4053> ## gave a warning in 1.9.1
4054>
4055>
4056> ## Dump should quote when necessary (PR#6857)
4057> x <- quote(b)
4058> dump("x", "")
4059x <-
4060quote(b)
4061> ## doesn't quote b in 1.9.0
4062>
4063>
4064> ## some checks of indexing by character, used to test hashing code
4065> x <- 1:26
4066> names(x) <- letters
4067> x[c("a", "aa", "aa")] <- 100:102
4068> x
4069  a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t
4070100   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
4071  u   v   w   x   y   z  aa
4072 21  22  23  24  25  26 102
4073>
4074> x <- 1:26
4075> names(x) <- rep("", 26)
4076> x[c("a", "aa", "aa")] <- 100:102
4077> x
4078
4079  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
4080                          a  aa
4081 21  22  23  24  25  26 100 102
4082> ##
4083>
4084>
4085> ## tests of raw type
4086> # tests of logic operators
4087> x <- "A test string"
4088> (y <- charToRaw(x))
4089 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67
4090> (xx <- c(y, as.raw(0), charToRaw("more")))
4091 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67 00 6d 6f 72 65
4092>
4093> !y
4094 [1] be df 8b 9a 8c 8b df 8c 8b 8d 96 91 98
4095> y & as.raw(15)
4096 [1] 01 00 04 05 03 04 00 03 04 02 09 0e 07
4097> y | as.raw(128)
4098 [1] c1 a0 f4 e5 f3 f4 a0 f3 f4 f2 e9 ee e7
4099>
4100> # tests of binary read/write
4101> zz <- file("testbin", "wb")
4102> writeBin(xx, zz)
4103> close(zz)
4104> zz <- file("testbin", "rb")
4105> (yy <- readBin(zz, "raw", 100))
4106 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67 00 6d 6f 72 65
4107> seek(zz, 0, "start")
4108[1] 18
4109> readBin(zz, "integer", n=100, size = 1) # read as small integers
4110 [1]  65  32 116 101 115 116  32 115 116 114 105 110 103   0 109 111 114 101
4111> seek(zz, 0, "start")
4112[1] 18
4113> readBin(zz, "character", 100)  # is confused by embedded nul.
4114[1] "A test string"
4115Warning message:
4116In readBin(zz, "character", 100) :
4117  incomplete string at end of file has been discarded
4118> seek(zz, 0, "start")
4119[1] 18
4120> readChar(zz, length(xx)) # truncates at embedded nul
4121[1] "A test string"
4122Warning message:
4123In readChar(zz, length(xx)) : truncating string with embedded nuls
4124> seek(zz) # make sure current position is reported properly
4125[1] 18
4126> close(zz)
4127> unlink("testbin")
4128>
4129> # tests of ASCII read/write.
4130> cat(xx, file="testascii")
4131> scan("testascii", what=raw(0))
4132Read 18 items
4133 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67 00 6d 6f 72 65
4134> unlink("testascii")
4135> ##
4136>
4137>
4138> ## Example of prediction not from newdata as intended.
4139> set.seed(1)
4140> y <- rnorm(10)
4141> x  <- cbind(1:10, sample(1:10)) # matrix
4142> xt <- cbind(1:2,  3:4)
4143> (lm1 <- lm(y ~ x))
4144
4145Call:
4146lm(formula = y ~ x)
4147
4148Coefficients:
4149(Intercept)           x1           x2
4150    1.88803     -0.15694     -0.09072
4151
4152> predict(lm1, newdata = data.frame(x= xt))
4153          1           2           3           4           5           6
4154 1.36820341  1.02982433  1.14505218  0.35306615  0.92190094  0.12991492
4155          7           8           9          10
4156 0.33586416 -0.09323631 -0.15945124  0.22794078
4157Warning message:
4158'newdata' had 2 rows but variables found have 10 rows
4159> ## warns as from 2.0.0
4160>
4161>
4162> ## eval could alter a data.frame/list second argument
4163> data(trees)
4164> a <- trees
4165> eval(quote({Girth[1]<-NA;Girth}),a)
4166 [1]   NA  8.6  8.8 10.5 10.7 10.8 11.0 11.0 11.1 11.2 11.3 11.4 11.4 11.7 12.0
4167[16] 12.9 12.9 13.3 13.7 13.8 14.0 14.2 14.5 16.0 16.3 17.3 17.5 17.9 18.0 18.0
4168[31] 20.6
4169> a[1, ]
4170  Girth Height Volume
41711   8.3     70   10.3
4172> trees[1, ]
4173  Girth Height Volume
41741   8.3     70   10.3
4175> ## both a and trees got altered in 1.9.1
4176>
4177>
4178> ## write.table did not apply qmethod to col.names (PR#7171)
4179> x <- data.frame("test string with \"" = c("a \" and a '"), check.names=FALSE)
4180> write.table(x)
4181"test string with \""
4182"1" "a \" and a '"
4183> write.table(x, qmethod = "double")
4184"test string with """
4185"1" "a "" and a '"
4186> ## Quote in col name was unescaped in 1.9.1.
4187>
4188>
4189> ## extensions to read.table
4190> Mat <- matrix(c(1:3, letters[1:3], 1:3, LETTERS[1:3],
4191+                 c("2004-01-01", "2004-02-01", "2004-03-01"),
4192+                 c("2004-01-01 12:00", "2004-02-01 12:00", "2004-03-01 12:00")),
4193+               3, 6)
4194> foo <- tempfile(tmpdir = getwd())
4195> write.table(Mat, foo, col.names = FALSE, row.names = FALSE)
4196> read.table(foo, colClasses = c(NA, NA, "NULL", "character", "Date", "POSIXct"),
4197+            stringsAsFactors=TRUE)
4198  V1 V2 V4         V5                  V6
41991  1  a  A 2004-01-01 2004-01-01 12:00:00
42002  2  b  B 2004-02-01 2004-02-01 12:00:00
42013  3  c  C 2004-03-01 2004-03-01 12:00:00
4202> unlist(sapply(.Last.value, class))
4203         V1          V2          V4          V5         V61         V62
4204  "integer"    "factor" "character"      "Date"   "POSIXct"    "POSIXt"
4205> read.table(foo, colClasses = c("factor",NA,"NULL","factor","Date","POSIXct"),
4206+            stringsAsFactors=TRUE)
4207  V1 V2 V4         V5                  V6
42081  1  a  A 2004-01-01 2004-01-01 12:00:00
42092  2  b  B 2004-02-01 2004-02-01 12:00:00
42103  3  c  C 2004-03-01 2004-03-01 12:00:00
4211> unlist(sapply(.Last.value, class))
4212       V1        V2        V4        V5       V61       V62
4213 "factor"  "factor"  "factor"    "Date" "POSIXct"  "POSIXt"
4214> read.table(foo, colClasses = c(V4="character"), stringsAsFactors=TRUE)
4215  V1 V2 V3 V4         V5               V6
42161  1  a  1  A 2004-01-01 2004-01-01 12:00
42172  2  b  2  B 2004-02-01 2004-02-01 12:00
42183  3  c  3  C 2004-03-01 2004-03-01 12:00
4219> unlist(sapply(.Last.value, class))
4220         V1          V2          V3          V4          V5          V6
4221  "integer"    "factor"   "integer" "character"    "factor"    "factor"
4222> unlink(foo)
4223> ## added in 2.0.0
4224>
4225>
4226> ## write.table with complex columns (PR#7260, in part)
4227> write.table(data.frame(x = 0.5+1:4, y = 1:4 + 1.5i), file = "")
4228"x" "y"
4229"1" 1.5 1+1.5i
4230"2" 2.5 2+1.5i
4231"3" 3.5 3+1.5i
4232"4" 4.5 4+1.5i
4233> # printed all as complex in 2.0.0.
4234> write.table(data.frame(x = 0.5+1:4, y = 1:4 + 1.5i), file = "", dec=",")
4235"x" "y"
4236"1" 1,5 1+1,5i
4237"2" 2,5 2+1,5i
4238"3" 3,5 3+1,5i
4239"4" 4,5 4+1,5i
4240> ## used '.' not ',' in 2.0.0
4241>
4242> ## splinefun() value test
4243> (x <- seq(0,6, length=25))
4244 [1] 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50
4245[16] 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5.50 5.75 6.00
4246> mx <- sapply(c("fmm", "nat", "per"),
4247+              function(m) splinefun(1:5, c(1,2,4,3,1), method = m)(x))
4248> cbind(x,mx)
4249         x       fmm         nat       per
4250 [1,] 0.00 5.3333333  0.46428571 3.0000000
4251 [2,] 0.25 3.5312500  0.59821429 2.4062500
4252 [3,] 0.50 2.2500000  0.73214286 1.8125000
4253 [4,] 0.75 1.4270833  0.86607143 1.3125000
4254 [5,] 1.00 1.0000000  1.00000000 1.0000000
4255 [6,] 1.25 0.9062500  1.14118304 0.9453125
4256 [7,] 1.50 1.0833333  1.32589286 1.1250000
4257 [8,] 1.75 1.4687500  1.59765625 1.4921875
4258 [9,] 2.00 2.0000000  2.00000000 2.0000000
4259[10,] 2.25 2.6093750  2.54854911 2.5937500
4260[11,] 2.50 3.2083333  3.14732143 3.1875000
4261[12,] 2.75 3.7031250  3.67243304 3.6875000
4262[13,] 3.00 4.0000000  4.00000000 4.0000000
4263[14,] 3.25 4.0312500  4.03962054 4.0546875
4264[15,] 3.50 3.8333333  3.83482143 3.8750000
4265[16,] 3.75 3.4687500  3.46261161 3.5078125
4266[17,] 4.00 3.0000000  3.00000000 3.0000000
4267[18,] 4.25 2.4843750  2.51171875 2.4062500
4268[19,] 4.50 1.9583333  2.01339286 1.8125000
4269[20,] 4.75 1.4531250  1.50837054 1.3125000
4270[21,] 5.00 1.0000000  1.00000000 1.0000000
4271[22,] 5.25 0.6302083  0.49107143 0.9453125
4272[23,] 5.50 0.3750000 -0.01785714 1.1250000
4273[24,] 5.75 0.2656250 -0.52678571 1.4921875
4274[25,] 6.00 0.3333333 -1.03571429 2.0000000
4275>
4276>
4277> ## infinite loop in read.fwf (PR#7350)
4278> cat(file="test.txt", sep = "\n", "# comment 1", "1234567   # comment 2",
4279+     "1 234567  # comment 3", "12345  67 # comment 4", "# comment 5")
4280> read.fwf("test.txt", width=c(2,2,3), skip=1, n=4) # looped
4281  V1 V2  V3
42821 12 34 567
42832  1 23 456
42843 12 34   5
4285> read.fwf("test.txt", width=c(2,2,3), skip=1)      # 1 line short
4286  V1 V2  V3
42871 12 34 567
42882  1 23 456
42893 12 34   5
4290> read.fwf("test.txt", width=c(2,2,3), skip=0)
4291  V1 V2  V3
42921 12 34 567
42932  1 23 456
42943 12 34   5
4295> unlink("test.txt")
4296> ##
4297>
4298>
4299> ## split was not handling lists and raws
4300> split(as.list(1:3), c(1,1,2))
4301$`1`
4302$`1`[[1]]
4303[1] 1
4304
4305$`1`[[2]]
4306[1] 2
4307
4308
4309$`2`
4310$`2`[[1]]
4311[1] 3
4312
4313
4314> (y <- charToRaw("A test string"))
4315 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67
4316> (z <- split(y, rep(1:5, times=c(1,1,4,1,6))))
4317$`1`
4318[1] 41
4319
4320$`2`
4321[1] 20
4322
4323$`3`
4324[1] 74 65 73 74
4325
4326$`4`
4327[1] 20
4328
4329$`5`
4330[1] 73 74 72 69 6e 67
4331
4332> sapply(z, rawToChar)
4333       1        2        3        4        5
4334     "A"      " "   "test"      " " "string"
4335> ## wrong results in 2.0.0
4336>
4337>
4338> ## tests of changed S3 implicit classes in 2.1.0
4339> foo <- function(x, ...) UseMethod("foo")
4340> foo.numeric <- function(x) cat("numeric arg\n")
4341> foo(1:10)
4342numeric arg
4343> foo(pi)
4344numeric arg
4345> foo(matrix(1:10, 2, 5))
4346numeric arg
4347> foo.integer <- function(x) cat("integer arg\n")
4348> foo.double <- function(x) cat("double arg\n")
4349> foo(1:10)
4350integer arg
4351> foo(pi)
4352double arg
4353> foo(matrix(1:10, 2, 5))
4354integer arg
4355> ##
4356>
4357>
4358> ## str() interpreted escape sequences prior to 2.1.0
4359> x <- "ab\bc\ndef"
4360> str(x)
4361 chr "ab\bc\ndef"
4362> str(x, vec.len=0)# failed in rev 32244
4363 chr  ...
4364> str(factor(x))
4365 Factor w/ 1 level "ab\bc\ndef": 1
4366>
4367> x <- c("a", NA, "b")
4368> factor(x)
4369[1] a    <NA> b
4370Levels: a b
4371> factor(x, exclude="")
4372[1] a    <NA> b
4373Levels: a b <NA>
4374> str(x)
4375 chr [1:3] "a" NA "b"
4376> str(factor(x))
4377 Factor w/ 2 levels "a","b": 1 NA 2
4378> str(factor(x, exclude=""))
4379 Factor w/ 3 levels "a","b",NA: 1 3 2
4380> ##
4381>
4382>
4383> ## print.factor(quote=TRUE) was not quoting levels
4384> x <- c("a", NA, "b", 'a " test') #" (comment for fontification)
4385> factor(x)
4386[1] a        <NA>     b        a " test
4387Levels: a a " test b
4388> factor(x, exclude="")
4389[1] a        <NA>     b        a " test
4390Levels: a a " test b <NA>
4391> print(factor(x), quote=TRUE)
4392[1] "a"         NA          "b"         "a \" test"
4393Levels: "a" "a \" test" "b"
4394> print(factor(x, exclude=""), quote=TRUE)
4395[1] "a"         NA          "b"         "a \" test"
4396Levels: "a" "a \" test" "b" NA
4397> ## last two printed levels differently from values in 2.0.1
4398>
4399>
4400> ## write.table in marginal cases
4401> x <- matrix(, 3, 0)
4402> write.table(x) # 3 rows
4403"1"
4404"2"
4405"3"
4406> write.table(x, row.names=FALSE)
4407
4408
4409
4410> # note: scan and read.table won't read this as they take empty fields as NA
4411> ## was 1 row in 2.0.1
4412>
4413>
4414> ## More tests of write.table
4415> x <- list(a=1, b=1:2, c=3:4, d=5)
4416> dim(x) <- c(2,2)
4417> x
4418     [,1]      [,2]
4419[1,] 1         integer,2
4420[2,] integer,2 5
4421> write.table(x)
4422"V1" "V2"
4423"1" 1 3:4
4424"2" 1:2 5
4425>
4426> x1 <- data.frame(a=1:2, b=I(matrix(LETTERS[1:4], 2, 2)), c = c("(i)", "(ii)"))
4427> x1
4428  a b.1 b.2    c
44291 1   A   C  (i)
44302 2   B   D (ii)
4431> write.table(x1) # In 2.0.1 had 3 headers, 4 cols
4432"a" "b.1" "b.2" "c"
4433"1" 1 A C "(i)"
4434"2" 2 B D "(ii)"
4435> write.table(x1, quote=c(2,3,4))
4436"a" "b.1" "b.2" "c"
4437"1" 1 "A" "C" "(i)"
4438"2" 2 "B" "D" "(ii)"
4439>
4440> x2 <- data.frame(a=1:2, b=I(list(a=1, b=2)))
4441> x2
4442  a b
4443a 1 1
4444b 2 2
4445> write.table(x2)
4446"a" "b"
4447"a" 1 1
4448"b" 2 2
4449>
4450> x3 <- seq(as.Date("2005-01-01"), len=6, by="day")
4451> x4 <- data.frame(x=1:6, y=x3)
4452> dim(x3) <- c(2,3)
4453> x3
4454[1] "2005-01-01" "2005-01-02" "2005-01-03" "2005-01-04" "2005-01-05"
4455[6] "2005-01-06"
4456> write.table(x3) # matrix, so loses class
4457"V1" "V2" "V3"
4458"1" 12784 12786 12788
4459"2" 12785 12787 12789
4460> x4
4461  x          y
44621 1 2005-01-01
44632 2 2005-01-02
44643 3 2005-01-03
44654 4 2005-01-04
44665 5 2005-01-05
44676 6 2005-01-06
4468> write.table(x4) # preserves class, does not quote
4469"x" "y"
4470"1" 1 2005-01-01
4471"2" 2 2005-01-02
4472"3" 3 2005-01-03
4473"4" 4 2005-01-04
4474"5" 5 2005-01-05
4475"6" 6 2005-01-06
4476> ##
4477>
4478>
4479> ## Problem with earlier regexp code spotted by KH
4480> grep("(.*s){2}", "Arkansas", v = TRUE)
4481[1] "Arkansas"
4482> grep("(.*s){3}", "Arkansas", v = TRUE)
4483character(0)
4484> grep("(.*s){3}", state.name, v = TRUE)
4485[1] "Massachusetts" "Mississippi"
4486> ## Thought Arkansas had 3 s's.
4487>
4488>
4489> ## Replacing part of a non-existent column could create a short column.
4490> xx<- data.frame(a=1:4, b=letters[1:4])
4491> xx[2:3, "c"] <- 2:3
4492> ## gave short column in R < 2.1.0.
4493>
4494>
4495> ## add1/drop1 could give misleading results if missing values were involved
4496> y <- rnorm(1:20)
4497> x <- 1:20; x[10] <- NA
4498> x2 <- runif(20); x2[20] <- NA
4499> fit <- lm(y ~ x)
4500> drop1(fit)
4501Single term deletions
4502
4503Model:
4504y ~ x
4505       Df Sum of Sq     RSS     AIC
4506<none>               9.1728 -9.8358
4507x       1    1.6593 10.8321 -8.6766
4508> res <-  try(stats:::drop1.default(fit))
4509Error in stats:::drop1.default(fit) :
4510  number of rows in use has changed: remove missing values?
4511> stopifnot(inherits(res, "try-error"))
4512> add1(fit, ~ . +x2)
4513Single term additions
4514
4515Model:
4516y ~ x
4517       Df Sum of Sq    RSS     AIC
4518<none>              8.8475 -8.7842
4519x2      1  0.030932 8.8166 -6.8473
4520Warning message:
4521In add1.lm(fit, ~. + x2) : using the 18/19 rows from a combined fit
4522> res <-  try(stats:::add1.default(fit, ~ . +x2))
4523Error in stats:::add1.default(fit, ~. + x2) :
4524  number of rows in use has changed: remove missing values?
4525> stopifnot(inherits(res, "try-error"))
4526> ## 2.0.1 ran and gave incorrect answers.
4527>
4528>
4529> ## (PR#7789) escaped quotes in the first five lines for read.table
4530> tf <- tempfile(tmpdir = getwd())
4531> x <- c("6 'TV2  Shortland Street'",
4532+        "2 'I don\\\'t watch TV at 7'",
4533+        "1 'I\\\'m not bothered, whatever that looks good'",
4534+        "2 'I channel surf'")
4535> writeLines(x, tf)
4536> read.table(tf)
4537  V1                                         V2
45381  6                      TV2  Shortland Street
45392  2                      I don't watch TV at 7
45403  1 I'm not bothered, whatever that looks good
45414  2                             I channel surf
4542> x <- c("6 'TV2  Shortland Street'",
4543+        "2 'I don''t watch TV at 7'",
4544+        "1 'I''m not bothered, whatever that looks good'",
4545+        "2 'I channel surf'")
4546> writeLines(x, tf)
4547> read.table(tf, sep=" ")
4548  V1                                         V2
45491  6                      TV2  Shortland Street
45502  2                      I don't watch TV at 7
45513  1 I'm not bothered, whatever that looks good
45524  2                             I channel surf
4553> unlink(tf)
4554> ## mangled in 2.0.1
4555>
4556>
4557> ## (PR#7802) printCoefmat(signif.legend =FALSE) failed
4558> set.seed(123)
4559> cmat <- cbind(rnorm(3, 10), sqrt(rchisq(3, 12)))
4560> cmat <- cbind(cmat, cmat[,1]/cmat[,2])
4561> cmat <- cbind(cmat, 2*pnorm(-cmat[,3]))
4562> colnames(cmat) <- c("Estimate", "Std.Err", "Z value", "Pr(>z)")
4563> printCoefmat(cmat, signif.stars = TRUE)
4564     Estimate Std.Err Z value    Pr(>z)
4565[1,]  11.3092  2.8636  3.9493 7.837e-05 ***
4566[2,]  11.2301  3.5301  3.1812  0.001467 **
4567[3,]   9.9161  3.0927  3.2063  0.001344 **
4568---
4569Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4570> printCoefmat(cmat, signif.stars = TRUE, signif.legend = FALSE)
4571     Estimate Std.Err Z value    Pr(>z)
4572[1,]  11.3092  2.8636  3.9493 7.837e-05 ***
4573[2,]  11.2301  3.5301  3.1812  0.001467 **
4574[3,]   9.9161  3.0927  3.2063  0.001344 **
4575> # no stars, so no legend
4576> printCoefmat(cmat, signif.stars = FALSE)
4577     Estimate Std.Err Z value    Pr(>z)
4578[1,]  11.3092  2.8636  3.9493 7.837e-05
4579[2,]  11.2301  3.5301  3.1812  0.001467
4580[3,]   9.9161  3.0927  3.2063  0.001344
4581> printCoefmat(cmat, signif.stars = TRUE, signif.legend = TRUE)
4582     Estimate Std.Err Z value    Pr(>z)
4583[1,]  11.3092  2.8636  3.9493 7.837e-05 ***
4584[2,]  11.2301  3.5301  3.1812  0.001467 **
4585[3,]   9.9161  3.0927  3.2063  0.001344 **
4586---
4587Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4588> ## did not work in 2.1.0
4589>
4590>
4591> ## PR#7824 subscripting an array by a matrix
4592> x <- matrix(1:6, ncol=2)
4593> x[rbind(c(1,1), c(2,2))]
4594[1] 1 5
4595> x[rbind(c(1,1), c(2,2), c(0,1))]
4596[1] 1 5
4597> x[rbind(c(1,1), c(2,2), c(0,0))]
4598[1] 1 5
4599> x[rbind(c(1,1), c(2,2), c(0,2))]
4600[1] 1 5
4601> x[rbind(c(1,1), c(2,2), c(0,3))]
4602[1] 1 5
4603> x[rbind(c(1,1), c(2,2), c(1,0))]
4604[1] 1 5
4605> x[rbind(c(1,1), c(2,2), c(2,0))]
4606[1] 1 5
4607> x[rbind(c(1,1), c(2,2), c(3,0))]
4608[1] 1 5
4609> x[rbind(c(1,0), c(0,2), c(3,0))]
4610integer(0)
4611> x[rbind(c(1,0), c(0,0), c(3,0))]
4612integer(0)
4613> x[rbind(c(1,1), c(2,2), c(1,2))]
4614[1] 1 5 4
4615> x[rbind(c(1,1), c(2,NA), c(1,2))]
4616[1]  1 NA  4
4617> x[rbind(c(1,0), c(2,NA), c(1,2))]
4618[1] NA  4
4619> try(x[rbind(c(1,1), c(2,2), c(-1,2))])
4620Error in x[rbind(c(1, 1), c(2, 2), c(-1, 2))] :
4621  negative values are not allowed in a matrix subscript
4622> try(x[rbind(c(1,1), c(2,2), c(-2,2))])
4623Error in x[rbind(c(1, 1), c(2, 2), c(-2, 2))] :
4624  negative values are not allowed in a matrix subscript
4625> try(x[rbind(c(1,1), c(2,2), c(-3,2))])
4626Error in x[rbind(c(1, 1), c(2, 2), c(-3, 2))] :
4627  negative values are not allowed in a matrix subscript
4628> try(x[rbind(c(1,1), c(2,2), c(-4,2))])
4629Error in x[rbind(c(1, 1), c(2, 2), c(-4, 2))] :
4630  negative values are not allowed in a matrix subscript
4631> try(x[rbind(c(1,1), c(2,2), c(-1,-1))])
4632Error in x[rbind(c(1, 1), c(2, 2), c(-1, -1))] :
4633  negative values are not allowed in a matrix subscript
4634> try(x[rbind(c(1,1,1), c(2,2,2))])
4635[1] 1 2 1 2 1 2
4636>
4637> # verify that range checks are applied to negative indices
4638> x <- matrix(1:6, ncol=3)
4639> try(x[rbind(c(1,1), c(2,2), c(-3,3))])
4640Error in x[rbind(c(1, 1), c(2, 2), c(-3, 3))] :
4641  negative values are not allowed in a matrix subscript
4642> try(x[rbind(c(1,1), c(2,2), c(-4,3))])
4643Error in x[rbind(c(1, 1), c(2, 2), c(-4, 3))] :
4644  negative values are not allowed in a matrix subscript
4645> ## generally allowed in 2.1.0.
4646>
4647>
4648> ## printing RAW matrices/arrays was not implemented
4649> s <- sapply(0:7, function(i) rawShift(charToRaw("my text"),i))
4650> s
4651     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
4652[1,]   6d   da   b4   68   d0   a0   40   80
4653[2,]   79   f2   e4   c8   90   20   40   80
4654[3,]   20   40   80   00   00   00   00   00
4655[4,]   74   e8   d0   a0   40   80   00   00
4656[5,]   65   ca   94   28   50   a0   40   80
4657[6,]   78   f0   e0   c0   80   00   00   00
4658[7,]   74   e8   d0   a0   40   80   00   00
4659> dim(s) <- c(7,4,2)
4660> s
4661, , 1
4662
4663     [,1] [,2] [,3] [,4]
4664[1,]   6d   da   b4   68
4665[2,]   79   f2   e4   c8
4666[3,]   20   40   80   00
4667[4,]   74   e8   d0   a0
4668[5,]   65   ca   94   28
4669[6,]   78   f0   e0   c0
4670[7,]   74   e8   d0   a0
4671
4672, , 2
4673
4674     [,1] [,2] [,3] [,4]
4675[1,]   d0   a0   40   80
4676[2,]   90   20   40   80
4677[3,]   00   00   00   00
4678[4,]   40   80   00   00
4679[5,]   50   a0   40   80
4680[6,]   80   00   00   00
4681[7,]   40   80   00   00
4682
4683> ## empty < 2.1.1
4684>
4685>
4686> ## interpretation of '.' directly by model.matrix
4687> dd <- data.frame(a = gl(3,4), b = gl(4,1,12))
4688> model.matrix(~ .^2, data = dd)
4689   (Intercept) a2 a3 b2 b3 b4 a2:b2 a3:b2 a2:b3 a3:b3 a2:b4 a3:b4
46901            1  0  0  0  0  0     0     0     0     0     0     0
46912            1  0  0  1  0  0     0     0     0     0     0     0
46923            1  0  0  0  1  0     0     0     0     0     0     0
46934            1  0  0  0  0  1     0     0     0     0     0     0
46945            1  1  0  0  0  0     0     0     0     0     0     0
46956            1  1  0  1  0  0     1     0     0     0     0     0
46967            1  1  0  0  1  0     0     0     1     0     0     0
46978            1  1  0  0  0  1     0     0     0     0     1     0
46989            1  0  1  0  0  0     0     0     0     0     0     0
469910           1  0  1  1  0  0     0     1     0     0     0     0
470011           1  0  1  0  1  0     0     0     0     1     0     0
470112           1  0  1  0  0  1     0     0     0     0     0     1
4702attr(,"assign")
4703 [1] 0 1 1 2 2 2 3 3 3 3 3 3
4704attr(,"contrasts")
4705attr(,"contrasts")$a
4706[1] "contr.treatment"
4707
4708attr(,"contrasts")$b
4709[1] "contr.treatment"
4710
4711> ## lost ^2 in 2.1.1
4712>
4713>
4714> ## add1.lm and drop.lm did not know about offsets (PR#8049)
4715> set.seed(2)
4716> y <- rnorm(10)
4717> z <- 1:10
4718> lm0 <- lm(y ~ 1)
4719> lm1 <- lm(y ~ 1, offset = 1:10)
4720> lm2 <- lm(y ~ z, offset = 1:10)
4721>
4722> add1(lm0, scope = ~ z)
4723Single term additions
4724
4725Model:
4726y ~ 1
4727       Df  Sum of Sq    RSS      AIC
4728<none>               6.3161 -2.59479
4729z       1 0.00029765 6.3158 -0.59526
4730> anova(lm1, lm2)
4731Analysis of Variance Table
4732
4733Model 1: y ~ 1
4734Model 2: y ~ z
4735  Res.Df    RSS Df Sum of Sq     F    Pr(>F)
47361      9 89.130
47372      8  6.316  1    82.814 104.9 7.099e-06 ***
4738---
4739Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4740> add1(lm1, scope = ~ z)
4741Single term additions
4742
4743Model:
4744y ~ 1
4745       Df Sum of Sq    RSS     AIC
4746<none>              89.130 23.8751
4747z       1    82.814  6.316 -0.5953
4748> drop1(lm2)
4749Single term deletions
4750
4751Model:
4752y ~ z
4753       Df Sum of Sq    RSS     AIC
4754<none>               6.316 -0.5953
4755z       1    82.814 89.130 23.8751
4756> ## Last two ignored the offset in 2.1.1
4757>
4758>
4759> ## tests of raw conversion
4760> as.raw(1234)
4761[1] 00
4762Warning message:
4763out-of-range values treated as 0 in coercion to raw
4764> as.raw(list(a=1234))
4765[1] 00
4766Warning message:
4767out-of-range values treated as 0 in coercion to raw
4768> ## 2.1.1: spurious and missing messages, wrong result for second.
4769>
4770>
4771> ### end of tests added in 2.1.1 patched ###
4772>
4773>
4774> ## Tests of logical matrix indexing with NAs
4775> df1 <- data.frame(a = c(NA, 0, 3, 4)); m1 <- as.matrix(df1)
4776> df2 <- data.frame(a = c(NA, 0, 0, 4)); m2 <- as.matrix(df2)
4777> df1[df1 == 0] <- 2; df1
4778   a
47791 NA
47802  2
47813  3
47824  4
4783> m1[m1 == 0] <- 2;   m1
4784      a
4785[1,] NA
4786[2,]  2
4787[3,]  3
4788[4,]  4
4789> df2[df2 == 0] <- 2; df2  # not allowed in 2.{0,1}.z
4790   a
47911 NA
47922  2
47933  2
47944  4
4795> m2[m2 == 0] <- 2;   m2
4796      a
4797[1,] NA
4798[2,]  2
4799[3,]  2
4800[4,]  4
4801> df1[df1 == 2] # this is first coerced to a matrix, and drops to a vector
4802[1] NA  2
4803> df3 <- data.frame(a=1:2, b=2:3)
4804> df3[df3 == 2]            # had spurious names
4805[1] 2 2
4806> # but not allowed
4807> ## (modified to make printed result the same whether numeric() is
4808> ##  compiled or interpreted)
4809> ## try(df2[df2 == 2] <- 1:2)
4810> ## try(m2[m2 == 2] <- 1:2)
4811> tryCatch(df2[df2 == 2] <- 1:2,
4812+          error = function(e) paste("Error:", conditionMessage(e)))
4813[1] "Error: NAs are not allowed in subscripted assignments"
4814> tryCatch(m2[m2 == 2] <- 1:2,
4815+          error = function(e) paste("Error:", conditionMessage(e)))
4816[1] "Error: NAs are not allowed in subscripted assignments"
4817> ##
4818>
4819>
4820> ## vector indexing of matrices: issue is when rownames are used
4821> # 1D array
4822> m1 <- c(0,1,2,0)
4823> dim(m1) <- 4
4824> dimnames(m1) <- list(1:4)
4825> m1[m1 == 0]                        # has rownames
48261 4
48270 0
4828> m1[which(m1 == 0)]                 # has rownames
48291 4
48300 0
4831> m1[which(m1 == 0, arr.ind = TRUE)] # no names < 2.2.0 (side effect of PR#937)
48321 4
48330 0
4834>
4835> # 2D array with 2 cols
4836> m2 <- as.matrix(data.frame(a=c(0,1,2,0), b=0:3))
4837> m2[m2 == 0]                        # a vector, had names < 2.2.0
4838[1] 0 0 0
4839> m2[which(m2 == 0)]                 # a vector, had names < 2.2.0
4840[1] 0 0 0
4841> m2[which(m2 == 0, arr.ind = TRUE)] # no names (PR#937)
4842[1] 0 0 0
4843>
4844> # 2D array with one col: could use rownames but do not.
4845> m21 <- m2[, 1, drop = FALSE]
4846> m21[m21 == 0]
4847[1] 0 0
4848> m21[which(m21 == 0)]
4849[1] 0 0
4850> m21[which(m21 == 0, arr.ind = TRUE)]
4851[1] 0 0
4852> ## not consistent < 2.2.0: S never gives names
4853>
4854>
4855> ## tests of indexing as quoted in Extract.Rd
4856> x <- NULL
4857> x$foo <- 2
4858> x # now, a list
4859$foo
4860[1] 2
4861
4862> x <- NULL
4863> x[[2]] <- pi
4864> x # now, a list, too
4865[[1]]
4866NULL
4867
4868[[2]]
4869[1] 3.141593
4870
4871> x <- NULL
4872> x[[1]] <- 1:3
4873> x # list
4874[[1]]
4875[1] 1 2 3
4876
4877> ##
4878>
4879>
4880> ## printing of a kernel:
4881> kernel(1)
4882unknown
4883coef[0] = 1
4884> ## printed wrongly in R <= 2.1.1
4885>
4886>
4887> ## using NULL as a replacement value
4888> DF <- data.frame(A=1:2, B=3:4)
4889> try(DF[2, 1:3] <- NULL)
4890Error in x[[jj]][iseq] <- vjj : replacement has length zero
4891> ## wrong error message in R < 2.2.0
4892>
4893>
4894> ## tests of signif
4895> ob <- 0:9 * 2000
4896> print(signif(ob, 3), digits=17) # had rounding error in 2.1.1
4897 [1]     0  2000  4000  6000  8000 10000 12000 14000 16000 18000
4898> signif(1.2347e-305, 4)
4899[1] 1.235e-305
4900> signif(1.2347e-306, 4)  # only 3 digits in 2.1.1
4901[1] 1.235e-306
4902> signif(1.2347e-307, 4)
4903[1] 1.235e-307
4904> ##
4905>
4906> ### end of tests added in 2.2.0 patched ###
4907>
4908>
4909> ## printing lists with NA names
4910> A <- list(1, 2)
4911> names(A) <- c("NA", NA)
4912> A
4913$`NA`
4914[1] 1
4915
4916$<NA>
4917[1] 2
4918
4919> ## both printed as "NA" in 2.2.0
4920>
4921>
4922> ## subscripting with both NA and "NA" names
4923> x <- 1:4
4924> names(x) <- c(NA, "NA", "a", "")
4925> x[names(x)]
4926<NA>   NA    a <NA>
4927  NA    2    3   NA
4928> ## 2.2.0 had the second matching the first.
4929> lx <- as.list(x)
4930> lx[[as.character(NA)]]
4931NULL
4932> lx[as.character(NA)]
4933$<NA>
4934NULL
4935
4936> ## 2.2.0 had both matching element 1
4937>
4938>
4939> ## data frame replacement subscripting
4940> # Charles C. Berry, R-devel, 2005-10-26
4941> a.frame <- data.frame( x=letters[1:5] )
4942> a.frame[ 2:5, "y" ] <- letters[2:5]
4943> a.frame  # added rows 1:4
4944  x    y
49451 a <NA>
49462 b    b
49473 c    c
49484 d    d
49495 e    e
4950> # and adding and replacing matrices failed
4951> a.frame[ ,"y" ] <- matrix(1:10, 5, 2)
4952> a.frame
4953  x y.1 y.2
49541 a   1   6
49552 b   2   7
49563 c   3   8
49574 d   4   9
49585 e   5  10
4959> a.frame[3:5 ,"y" ] <- matrix(1:6, 3, 2)
4960> a.frame
4961  x y.1 y.2
49621 a   1   6
49632 b   2   7
49643 c   1   4
49654 d   2   5
49665 e   3   6
4967> a.frame <- data.frame( x=letters[1:5] )
4968> a.frame[3:5 ,"y" ] <- matrix(1:6, 3, 2)
4969> a.frame
4970  x y.1 y.2
49711 a  NA  NA
49722 b  NA  NA
49733 c   1   4
49744 d   2   5
49755 e   3   6
4976> ## failed/wrong ans in 2.2.0
4977>
4978>
4979> ### end of tests added in 2.2.0 patched ###
4980>
4981>
4982> ## test of fix of trivial warning PR#8252
4983> pairs(iris[1:4], oma=rep(3,4))
4984> ## warned in 2.2.0 only
4985>
4986>
4987> ## str(<dendrogram>)
4988> dend <- as.dendrogram(hclust(dist(USArrests), "ave")) # "print()" method
4989> dend2 <- cut(dend, h=70)
4990> str(dend2$upper)
4991--[dendrogram w/ 2 branches and 4 members at h = 152]
4992  |--[dendrogram w/ 2 branches and 2 members at h = 77.6]
4993  |  |--leaf "Branch 1" (h= 38.5 midpoint = 0.5, x.member = 2 )
4994  |  `--leaf "Branch 2" (h= 44.3 midpoint = 5.03, x.member = 14 )
4995  `--[dendrogram w/ 2 branches and 2 members at h = 89.2]
4996     |--leaf "Branch 3" (h= 44.8 midpoint = 6.8, x.member = 14 )
4997     `--leaf "Branch 4" (h= 54.7 midpoint = 7.65, x.member = 20 )
4998> ## {{for Emacs: `}}  gave much too many spaces in 2.2.[01]
4999>
5000>
5001> ## formatC on Windows (PR#8337)
5002> xx  <- pi * 10^(-5:4)
5003> cbind(formatC(xx, wid = 9))
5004      [,1]
5005 [1,] "3.142e-05"
5006 [2,] "0.0003142"
5007 [3,] " 0.003142"
5008 [4,] "  0.03142"
5009 [5,] "   0.3142"
5010 [6,] "    3.142"
5011 [7,] "    31.42"
5012 [8,] "    314.2"
5013 [9,] "     3142"
5014[10,] "3.142e+04"
5015> cbind(formatC(xx, wid = 9, flag = "-"))
5016      [,1]
5017 [1,] "3.142e-05"
5018 [2,] "0.0003142"
5019 [3,] "0.003142 "
5020 [4,] "0.03142  "
5021 [5,] "0.3142   "
5022 [6,] "3.142    "
5023 [7,] "31.42    "
5024 [8,] "314.2    "
5025 [9,] "3142     "
5026[10,] "3.142e+04"
5027> cbind(formatC(xx, wid = 9, flag = "0"))
5028      [,1]
5029 [1,] "3.142e-05"
5030 [2,] "0.0003142"
5031 [3,] "00.003142"
5032 [4,] "000.03142"
5033 [5,] "0000.3142"
5034 [6,] "00003.142"
5035 [7,] "000031.42"
5036 [8,] "0000314.2"
5037 [9,] "000003142"
5038[10,] "3.142e+04"
5039> ## extra space on 2.2.1
5040>
5041>
5042> ## an impossible glm fit
5043> success <- c(13,12,11,14,14,11,13,11,12)
5044> failure <- c(0,0,0,0,0,0,0,2,2)
5045> predictor <- c(0, 5^(0:7))
5046> try(glm(cbind(success,failure) ~ 0+predictor, family = binomial(link="log")))
5047Error : no valid set of coefficients has been found: please supply starting values
5048> # no coefficient is possible as the first case will have mu = 1
5049> ## 2.2.1 gave a subscript out of range warning instead.
5050>
5051>
5052> ## error message from solve (PR#8494)
5053> temp <- diag(1, 5)[, 1:4]
5054> rownames(temp) <- as.character(1:5)
5055> colnames(temp) <- as.character(1:4)
5056> try(solve(temp))
5057Error in solve.default(temp) : 'a' (5 x 4) must be square
5058> # also complex
5059> try(solve(temp+0i))
5060Error in solve.default(temp + (0+0i)) : 'a' (5 x 4) must be square
5061> # and non-comformant systems
5062> try(solve(temp, diag(3)))
5063Error in solve.default(temp, diag(3)) : 'a' (5 x 4) must be square
5064> ## gave errors from rownames<- in 2.2.1
5065>
5066>
5067> ## PR#8462 terms.formula(simplify = TRUE) needs parentheses.
5068> update.formula (Reaction ~ Days + (Days | Subject), . ~ . + I(Days^2))
5069Reaction ~ Days + (Days | Subject) + I(Days^2)
5070> ## < 2.3.0 dropped parens on second term.
5071>
5072>
5073> ## PR#8528: errors in the post-2.1.0 pgamma
5074> pgamma(seq(0.75, 1.25, by=0.05)*1e100, shape = 1e100, log=TRUE)
5075 [1] -3.768207e+98 -2.314355e+98 -1.251893e+98 -5.360516e+97 -1.293294e+97
5076 [6] -6.931472e-01  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
5077[11]  0.000000e+00
5078> pgamma(seq(0.75, 1.25, by=0.05)*1e100, shape = 1e100, log=TRUE, lower=FALSE)
5079 [1]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
5080 [6] -6.931472e-01 -1.209836e+97 -4.689820e+97 -1.023806e+98 -1.767844e+98
5081[11] -2.685645e+98
5082> pgamma(c(1-1e-10, 1+1e-10)*1e100, shape = 1e100)
5083[1] 0 1
5084> pgamma(0.9*1e25, 1e25, log=TRUE)
5085[1] -5.360516e+22
5086> ## were NaN, -Inf etc in 2.2.1.
5087>
5088>
5089> ## + for POSIXt objects was non-commutative
5090> # SPSS-style dates
5091> c(10485849600,10477641600,10561104000,10562745600)+ISOdate(1582,10,14)
5092[1] "1915-01-26 12:00:00 GMT" "1914-10-23 12:00:00 GMT"
5093[3] "1917-06-15 12:00:00 GMT" "1917-07-04 12:00:00 GMT"
5094> ## was in the local time zone in 2.2.1.
5095>
5096>
5097> ## Limiting lines on deparse (wishlist PR#8638)
5098> op <- options(deparse.max.lines = 3)
5099> f <- function(...) browser()
5100> do.call(f, mtcars)
5101Called from: (function (...)
5102browser())(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4,
510322.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, 30.4,
5104  ...
5105Browse[1]> c
5106>
5107> op <- c(op, options(error = expression(NULL)))
5108> f <- function(...) stop()
5109> do.call(f, mtcars)
5110Error in (function (...)  :
5111Calls: do.call -> <Anonymous>
5112> traceback()
51133: stop()
51142: (function (...)
5115   stop())(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8,
5116   19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, 30.4, 33.9,
5117    ...
51181: do.call(f, mtcars)
5119>
5120> ## Debugger can handle a function that has a single function call as its body
5121> g <- function(fun) fun(1)
5122> debug(g)
5123> g(function(x) x+1)
5124debugging in: g(function(x) x + 1)
5125debug: fun(1)
5126Browse[2]>
5127exiting from: g(function(x) x + 1)
5128[1] 2
5129> options(op)
5130> ## unlimited < 2.3.0
5131>
5132>
5133> ## row names in as.table (PR#8652)
5134> as.table(matrix(1:60, ncol=2))
5135    A  B
5136A   1 31
5137B   2 32
5138C   3 33
5139D   4 34
5140E   5 35
5141F   6 36
5142G   7 37
5143H   8 38
5144I   9 39
5145J  10 40
5146K  11 41
5147L  12 42
5148M  13 43
5149N  14 44
5150O  15 45
5151P  16 46
5152Q  17 47
5153R  18 48
5154S  19 49
5155T  20 50
5156U  21 51
5157V  22 52
5158W  23 53
5159X  24 54
5160Y  25 55
5161Z  26 56
5162A1 27 57
5163B1 28 58
5164C1 29 59
5165D1 30 60
5166> ## rows past 26 had NA row names
5167>
5168>
5169> ## summary on a glm with zero weights and estimated dispersion (PR#8720)
5170> y <- rnorm(10)
5171> x <- 1:10
5172> w <- c(rep(1,9), 0)
5173> summary(glm(y ~ x, weights = w))
5174
5175Call:
5176glm(formula = y ~ x, weights = w)
5177
5178Deviance Residuals:
5179    Min       1Q   Median       3Q      Max
5180-1.7806  -0.1416   0.1863   0.5690   1.2057
5181
5182Coefficients:
5183            Estimate Std. Error t value Pr(>|t|)
5184(Intercept)  -0.7532     0.7862  -0.958    0.370
5185x             0.1311     0.1397   0.938    0.379
5186
5187(Dispersion parameter for gaussian family taken to be 1.17125)
5188
5189    Null deviance: 9.2298  on 8  degrees of freedom
5190Residual deviance: 8.1988  on 7  degrees of freedom
5191AIC: Inf
5192
5193Number of Fisher Scoring iterations: 2
5194
5195Warning message:
5196In summary.glm(glm(y ~ x, weights = w)) :
5197  observations with zero weight not used for calculating dispersion
5198> summary(glm(y ~ x, subset = w > 0))
5199
5200Call:
5201glm(formula = y ~ x, subset = w > 0)
5202
5203Deviance Residuals:
5204    Min       1Q   Median       3Q      Max
5205-1.7806  -0.1582   0.3726   0.5896   1.2057
5206
5207Coefficients:
5208            Estimate Std. Error t value Pr(>|t|)
5209(Intercept)  -0.7532     0.7862  -0.958    0.370
5210x             0.1311     0.1397   0.938    0.379
5211
5212(Dispersion parameter for gaussian family taken to be 1.17125)
5213
5214    Null deviance: 9.2298  on 8  degrees of freedom
5215Residual deviance: 8.1988  on 7  degrees of freedom
5216AIC: 30.702
5217
5218Number of Fisher Scoring iterations: 2
5219
5220> ## has NA dispersion in 2.2.1
5221>
5222>
5223> ## substitute was losing "..." after r37269
5224> yaa <- function(...) substitute(list(...))
5225> yaa(foo(...))
5226list(foo(...))
5227> ## and wasn't substituting after "..."
5228> substitute(list(..., x), list(x=1))
5229list(..., 1)
5230> ## fixed for 2.3.0
5231>
5232>
5233> ## uniroot never warned (PR#8750)
5234> ff <- function(x) (x-pi)^3
5235> uniroot(ff, c(-10,10), maxiter=10)
5236$root
5237[1] 3.291126
5238
5239$f.root
5240[1] 0.003343587
5241
5242$iter
5243[1] 10
5244
5245$init.it
5246[1] NA
5247
5248$estim.prec
5249[1] 0.8295023
5250
5251Warning message:
5252In uniroot(ff, c(-10, 10), maxiter = 10) : _NOT_ converged in 10 iterations
5253> ## should warn, did not < 2.3.0
5254>
5255>
5256> ### end of tests added in 2.3.0 ###
5257>
5258>
5259> ## prod etc on empty lists and raw vectors
5260> try(min(list()))
5261Error in min(list()) : invalid 'type' (list) of argument
5262> try(max(list()))
5263Error in max(list()) : invalid 'type' (list) of argument
5264> try(sum(list()))
5265Error in sum(list()) : invalid 'type' (list) of argument
5266> try(prod(list()))
5267Error in prod(list()) : invalid 'type' (list) of argument
5268> try(min(raw()))
5269Error in min(raw()) : invalid 'type' (raw) of argument
5270> try(max(raw()))
5271Error in max(raw()) : invalid 'type' (raw) of argument
5272> try(sum(raw()))
5273Error in sum(raw()) : invalid 'type' (raw) of argument
5274> try(prod(raw()))
5275Error in prod(raw()) : invalid 'type' (raw) of argument
5276> ## Inf, -Inf, list(NULL) etc in 2.2.1
5277>
5278> r <- hist(rnorm(100), plot = FALSE, breaks = 12,
5279+           ## arguments which don't make sense for plot=FALSE - give a warning:
5280+           xlab = "N(0,1)", col = "blue")
5281Warning message:
5282In hist.default(rnorm(100), plot = FALSE, breaks = 12, xlab = "N(0,1)",  :
5283  arguments 'col', 'xlab' are not made use of
5284> ## gave no warning in 2.3.0 and earlier
5285>
5286>
5287> ## rbind.data.frame on permuted cols (PR#8868)
5288> d1 <- data.frame(x=1:10, y=letters[1:10], z=1:10)
5289> d2 <- data.frame(y=LETTERS[1:5], z=5:1, x=7:11)
5290> rbind(d1, d2)
5291    x y  z
52921   1 a  1
52932   2 b  2
52943   3 c  3
52954   4 d  4
52965   5 e  5
52976   6 f  6
52987   7 g  7
52998   8 h  8
53009   9 i  9
530110 10 j 10
530211  7 A  5
530312  8 B  4
530413  9 C  3
530514 10 D  2
530615 11 E  1
5307> # got factor y  wrong in 2.3.0
5308> # and failed with duplicated col names.
5309> d1 <- data.frame(x=1:2, y=5:6, x=8:9, check.names=FALSE)
5310> d2 <- data.frame(x=3:4, x=-(1:2), y=8:9, check.names=FALSE)
5311> rbind(d1, d2)
5312  x y  x
53131 1 5  8
53142 2 6  9
53153 3 8 -1
53164 4 9 -2
5317> ## corrupt in 2.3.0
5318>
5319>
5320> ## sort.list on complex vectors was unimplemented prior to 2.4.0
5321> x <- rep(2:1, c(2, 2)) + 1i*c(4, 1, 2, 3)
5322> (o <- sort.list(x))
5323[1] 3 4 2 1
5324> x[o]
5325[1] 1+2i 1+3i 2+1i 2+4i
5326> sort(x)  # for a cross-check
5327[1] 1+2i 1+3i 2+1i 2+4i
5328> ##
5329>
5330>
5331> ## PR#9044 write.table(quote=TRUE, row.names=FALSE) did not quote column names
5332> m <- matrix(1:9, nrow=3, dimnames=list(c("A","B","C"),  c("I","II","III")))
5333> write.table(m)
5334"I" "II" "III"
5335"A" 1 4 7
5336"B" 2 5 8
5337"C" 3 6 9
5338> write.table(m, col.names=FALSE)
5339"A" 1 4 7
5340"B" 2 5 8
5341"C" 3 6 9
5342> write.table(m, row.names=FALSE)
5343"I" "II" "III"
53441 4 7
53452 5 8
53463 6 9
5347> # wrong < 2.3.1 patched.
5348> write.table(m, quote=FALSE)
5349I II III
5350A 1 4 7
5351B 2 5 8
5352C 3 6 9
5353> write.table(m, col.names=FALSE, quote=FALSE)
5354A 1 4 7
5355B 2 5 8
5356C 3 6 9
5357> write.table(m, row.names=FALSE, quote=FALSE)
5358I II III
53591 4 7
53602 5 8
53613 6 9
5362> d <- as.data.frame(m)
5363> write.table(d)
5364"I" "II" "III"
5365"A" 1 4 7
5366"B" 2 5 8
5367"C" 3 6 9
5368> write.table(d, col.names=FALSE)
5369"A" 1 4 7
5370"B" 2 5 8
5371"C" 3 6 9
5372> write.table(d, row.names=FALSE)
5373"I" "II" "III"
53741 4 7
53752 5 8
53763 6 9
5377> write.table(d, quote=FALSE)
5378I II III
5379A 1 4 7
5380B 2 5 8
5381C 3 6 9
5382> write.table(d, col.names=FALSE, quote=FALSE)
5383A 1 4 7
5384B 2 5 8
5385C 3 6 9
5386> write.table(d, row.names=FALSE, quote=FALSE)
5387I II III
53881 4 7
53892 5 8
53903 6 9
5391> write.table(m, quote=numeric(0)) # not the same as FALSE
5392"I" "II" "III"
5393"A" 1 4 7
5394"B" 2 5 8
5395"C" 3 6 9
5396> ##
5397>
5398>
5399> ## removing variable from baseenv
5400> try(remove("ls", envir=baseenv()))
5401Error in remove("ls", envir = baseenv()) :
5402  cannot remove variables from the base environment
5403> try(remove("ls", envir=asNamespace("base")))
5404Error in remove("ls", envir = asNamespace("base")) :
5405  cannot remove variables from base namespace
5406> ## no message in 2.3.1
5407>
5408>
5409> ## tests of behaviour of factors
5410> (x <- factor(LETTERS[1:5])[2:4])
5411[1] B C D
5412Levels: A B C D E
5413> x[2]
5414[1] C
5415Levels: A B C D E
5416> x[[2]]
5417[1] C
5418Levels: A B C D E
5419> stopifnot(identical(x[2], x[[2]]))
5420> as.list(x)
5421[[1]]
5422[1] B
5423Levels: A B C D E
5424
5425[[2]]
5426[1] C
5427Levels: A B C D E
5428
5429[[3]]
5430[1] D
5431Levels: A B C D E
5432
5433> (xx <- unlist(as.list(x)))
5434[1] B C D
5435Levels: A B C D E
5436> stopifnot(identical(x, xx))
5437> as.vector(x, "list")
5438[[1]]
5439[1] B
5440Levels: A B C D E
5441
5442[[2]]
5443[1] C
5444Levels: A B C D E
5445
5446[[3]]
5447[1] D
5448Levels: A B C D E
5449
5450> (sx <- sapply(x, function(.).))
5451[1] B C D
5452Levels: A B C D E
5453> stopifnot(identical(x, sx))
5454> ## changed in 2.4.0
5455>
5456>
5457> ## as.character on a factor with "NA" level
5458> as.character(as.factor(c("AB", "CD", NA)))
5459[1] "AB" "CD" NA
5460> as.character(as.factor(c("NA", "CD", NA)))  # use <NA> is 2.3.x
5461[1] "NA" "CD" NA
5462> as.vector(as.factor(c("NA", "CD", NA)))     # but this did not
5463[1] "NA" "CD" NA
5464> ## used <NA> before
5465>
5466>
5467> ## [ on a zero-column data frame, names of such
5468> data.frame()[FALSE]
5469data frame with 0 columns and 0 rows
5470> names(data.frame())
5471character(0)
5472> # gave NULL names and hence spurious warning.
5473>
5474>
5475> ## residuals from zero-weight glm fits
5476> d.AD <- data.frame(treatment = gl(3,3), outcome = gl(3,1,9),
5477+                    counts = c(18,17,15,20,10,20,25,13,12))
5478> fit <- glm(counts ~ outcome + treatment, family = poisson,
5479+            data = d.AD, weights = c(0, rep(1,8)))
5480> print(residuals(fit, type="working"),
5481+       width = 37) # first was NA < 2.4.0 //  using new 'width'
5482          1           2           3
5483-0.31250000  0.15546875 -0.13231383
5484          4           5           6
5485-0.11111111 -0.20909091  0.34622824
5486          7           8           9
5487 0.11111111  0.02818182 -0.19226306
5488> ## working residuals were NA for zero-weight cases.
5489> fit2 <- glm(counts ~ outcome + treatment, family = poisson,
5490+             data = d.AD, weights = c(0, rep(1,8)), y = FALSE)
5491> for(z in c("response", "working", "deviance", "pearson"))
5492+     stopifnot(all.equal(residuals(fit, type=z), residuals(fit2, type=z),
5493+                         scale = 1, tolerance = 1e-10))
5494>
5495> ## apply on arrays with zero extents
5496> ## Robin Hankin, R-help, 2006-02-13
5497> A <- array(0, c(3, 0, 4))
5498> dimnames(A) <- list(D1 = letters[1:3], D2 = NULL, D3 = LETTERS[1:4])
5499> f <- function(x) 5
5500> apply(A, 1:2, f)
5501   D2
5502D1
5503  a
5504  b
5505  c
5506> apply(A, 1, f)
5507a b c
55085 5 5
5509> apply(A, 2, f)
5510numeric(0)
5511> ## dropped dims in 2.3.1
5512>
5513>
5514> ## print a factor with names
5515> structure(factor(1:4), names = letters[1:4])
5516a b c d
55171 2 3 4
5518Levels: 1 2 3 4
5519> ## dropped names < 2.4.0
5520>
5521>
5522> ## some tests of factor matrices
5523> A <- factor(7:12)
5524> dim(A) <- c(2, 3)
5525> A
5526     [,1] [,2] [,3]
5527[1,] 7    9    11
5528[2,] 8    10   12
5529Levels: 7 8 9 10 11 12
5530> str(A)
5531 Factor[1:2, 1:3] w/ 6 levels "7","8","9","10",..: 1 2 3 4 5 6
5532> A[, 1:2]
5533     [,1] [,2]
5534[1,] 7    9
5535[2,] 8    10
5536Levels: 7 8 9 10 11 12
5537> A[, 1:2, drop=TRUE]
5538[1] 7  8  9  10
5539Levels: 7 8 9 10
5540> A[1,1] <- "9"
5541> A
5542     [,1] [,2] [,3]
5543[1,] 9    9    11
5544[2,] 8    10   12
5545Levels: 7 8 9 10 11 12
5546> ## misbehaved < 2.4.0
5547>
5548>
5549> ## [dpqr]t with vector ncp
5550> nc <- c(0, 0.0001, 1)
5551> dt(1.8, 10, nc)
5552[1] 0.08311639 0.08312972 0.26650393
5553> pt(1.8, 10, nc)
5554[1] 0.9489739 0.9489641 0.7584267
5555> qt(0.95, 10, nc)
5556[1] 1.812461 1.812579 3.041742
5557> ## gave warnings in 2.3.1, short answer for qt.
5558> dt(1.8, 10, -nc[-1])
5559[1] 0.08310306 0.01074629
5560> pt(1.8, 10, -nc[-1])
5561[1] 0.9489837 0.9949472
5562> qt(0.95, 10, -nc[-1])
5563[1] 1.8123429 0.6797902
5564> ## qt in 2.3.1 did not allow negative ncp.
5565>
5566>
5567> ## merge() used to insert row names as factor, not character, so
5568> ## sorting was unexpected.
5569> A <- data.frame(a = 1:4)
5570> row.names(A) <- c("2002-11-15", "2002-12-15", "2003-01-15", "2003-02-15")
5571> B <- data.frame(b = 1:4)
5572> row.names(B) <- c("2002-09-15", "2002-10-15", "2002-11-15", "2002-12-15")
5573> merge(A, B, by=0, all=TRUE)
5574   Row.names  a  b
55751 2002-09-15 NA  1
55762 2002-10-15 NA  2
55773 2002-11-15  1  3
55784 2002-12-15  2  4
55795 2003-01-15  3 NA
55806 2003-02-15  4 NA
5581>
5582>
5583> ## assigning to a list loop index could alter the index (PR#9216)
5584> L <- list(a = list(txt = "original value"))
5585> f <- function(LL) {
5586+     for (ll in LL) ll$txt <- "changed in f"
5587+     LL
5588+ }
5589> f(L)
5590$a
5591$a$txt
5592[1] "original value"
5593
5594
5595> L
5596$a
5597$a$txt
5598[1] "original value"
5599
5600
5601> ## both were changed < 2.4.0
5602>
5603>
5604> ## summary.mlm misbehaved with na.action = na.exclude
5605> n <- 50
5606> x <- runif(n=n)
5607> y1 <- 2 * x + rnorm(n=n)
5608> y2 <- 5 * x + rnorm(n=n)
5609> y2[sample(1:n, size=5)] <- NA
5610> y <- cbind(y1, y2)
5611> fit <- lm(y ~ 1, na.action="na.exclude")
5612> summary(fit)
5613Response y1 :
5614
5615Call:
5616lm(formula = y1 ~ 1, na.action = "na.exclude")
5617
5618Residuals:
5619    Min      1Q  Median      3Q     Max
5620-3.2359 -0.8766  0.2338  0.9944  2.5905
5621
5622Coefficients:
5623            Estimate Std. Error t value Pr(>|t|)
5624(Intercept)   1.1419     0.1966   5.808 6.47e-07 ***
5625---
5626Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
5627
5628Residual standard error: 1.319 on 44 degrees of freedom
5629  (5 observations deleted due to missingness)
5630
5631
5632Response y2 :
5633
5634Call:
5635lm(formula = y2 ~ 1, na.action = "na.exclude")
5636
5637Residuals:
5638    Min      1Q  Median      3Q     Max
5639-4.2822 -1.2548  0.4364  1.2185  3.8575
5640
5641Coefficients:
5642            Estimate Std. Error t value Pr(>|t|)
5643(Intercept)   2.7098     0.2798   9.685 1.77e-12 ***
5644---
5645Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
5646
5647Residual standard error: 1.877 on 44 degrees of freedom
5648  (5 observations deleted due to missingness)
5649
5650
5651> ## failed < 2.4.0
5652>
5653> RNGkind("default","default")## reset to default - ease  R core
5654>
5655> ## prettyNum lost attributes (PR#8695)
5656> format(matrix(1:16, 4), big.mark = ",")
5657     [,1] [,2] [,3] [,4]
5658[1,] " 1" " 5" " 9" "13"
5659[2,] " 2" " 6" "10" "14"
5660[3,] " 3" " 7" "11" "15"
5661[4,] " 4" " 8" "12" "16"
5662> ## was a vector < 2.4.0
5663>
5664>
5665> ## printing of complex numbers of very different magnitudes
5666> 1e100  + 1e44i
5667[1] 1e+100+0e+00i
5668> 1e100 + pi*1i*10^(c(-100,0,1,40,100))
5669[1] 1e+100+ 0.000000e+00i 1e+100+ 0.000000e+00i 1e+100+ 0.000000e+00i
5670[4] 1e+100+ 0.000000e+00i 1e+100+3.141593e+100i
5671> ## first was silly, second not rounded correctly in 2.2.0 - 2.3.1
5672> ## We don't get them lining up, but that is a printf issue
5673> ## that only happens for very large complex nos.
5674>
5675>
5676> ### end of tests added in 2.4.0 ###
5677>
5678>
5679> ## Platform-specific behaviour in lowess reported to R-help
5680> ## 2006-10-12 by Frank Harrell
5681> x <- c(0,7,8,14,15,120,242)
5682> y <- c(122,128,130,158,110,110,92)
5683> lowess(x, y, iter=0)
5684$x
5685[1]   0   7   8  14  15 120 242
5686
5687$y
5688[1] 121.95735 128.00000 131.06649 136.93673 126.76467 109.99903  92.00003
5689
5690> lowess(x, y)
5691$x
5692[1]   0   7   8  14  15 120 242
5693
5694$y
5695[1] 122 128 128 158 110 110  92
5696
5697> ## MAD of iterated residuals was zero, and result depended on the platform.
5698>
5699>
5700> ## PR#9263: problems with R_Visible
5701> a <- list(b=5)
5702> a[[(t<-'b')]]
5703[1] 5
5704> x <- matrix(5:-6, 3)
5705> x[2, invisible(3)]
5706[1] -2
5707> ## both invisible in 2.4.0
5708>
5709>
5710> ### end of tests added in 2.4.1 ###
5711>
5712>
5713> ## tests of deparsing
5714> x <-list(a = NA, b = as.integer(NA), c=0+NA, d=0i+NA,
5715+          e = 1, f = 1:1, g = 1:3, h = c(NA, 1:3),
5716+          i = as.character(NA), j = c("foo", NA, "bar")
5717+          )
5718> dput(x, control=NULL)
5719list(NA, NA, NA, NA, 1, 1, 1:3, c(NA, 1, 2, 3), NA, c("foo",
5720NA, "bar"))
5721> dput(x, control="keepInteger")
5722list(NA, NA_integer_, NA, NA, 1, 1L, 1:3, c(NA, 1L, 2L, 3L),
5723    NA, c("foo", NA, "bar"))
5724> dput(x, control="keepNA")
5725list(NA, NA_integer_, NA_real_, NA_complex_, 1, 1, 1:3, c(NA,
57261, 2, 3), NA_character_, c("foo", NA, "bar"))
5727> dput(x)
5728list(a = NA, b = NA_integer_, c = NA_real_, d = NA_complex_,
5729    e = 1, f = 1L, g = 1:3, h = c(NA, 1L, 2L, 3L), i = NA_character_,
5730    j = c("foo", NA, "bar"))
5731> dput(x, control="all")
5732list(a = NA, b = NA_integer_, c = NA_real_, d = NA_complex_,
5733    e = 1, f = 1L, g = 1:3, h = c(NA, 1L, 2L, 3L), i = NA_character_,
5734    j = c("foo", NA, "bar"))
5735> dput(x, control=c("all", "S_compatible"))
5736list(a = NA, b = as.integer(NA), c = as.double(NA), d = as.complex(NA),
5737    e = 1., f = as.integer(1), g = 1:3, h = as.integer(c(NA,
5738    1, 2, 3)), i = as.character(NA), j = c("foo", NA, "bar"))
5739> tmp <- tempfile(tmpdir = getwd())
5740> dput(x, tmp, control="all")
5741> stopifnot(identical(dget(tmp), x))
5742> dput(x, tmp, control=c("all", "S_compatible"))
5743> stopifnot(identical(dget(tmp), x))
5744> unlink(tmp)
5745> ## changes in 2.5.0
5746>
5747>
5748> ## give better error message for nls with no parameters
5749> ## Ivo Welch, R-help, 2006-12-23.
5750> d <- data.frame(y= runif(10), x=runif(10))
5751> try(nls(y ~ 1/(1+x), data = d, start=list(x=0.5,y=0.5), trace=TRUE))
5752Error in nls(y ~ 1/(1 + x), data = d, start = list(x = 0.5, y = 0.5),  :
5753  no parameters to fit
5754> ## changed in 2.4.1 patched
5755>
5756>
5757> ## cut(breaks="years"), in part PR#9433
5758> cut(as.Date(c("2000-01-17","2001-01-13","2001-01-20")), breaks="years")
5759[1] 2000-01-01 2001-01-01 2001-01-01
5760Levels: 2000-01-01 2001-01-01
5761> cut(as.POSIXct(c("2000-01-17","2001-01-13","2001-01-20")), breaks="years")
5762[1] 2000-01-01 2001-01-01 2001-01-01
5763Levels: 2000-01-01 2001-01-01
5764> ## did not get day 01 < 2.4.1 patched
5765>
5766>
5767> ## manipulating rownames: problems in pre-2.5.0
5768> A <- data.frame(a=character(0))
5769> try(row.names(A) <- 1:10) # succeeded in Dec 2006
5770Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length
5771> A <- list(a=1:3)
5772> class(A) <- "data.frame"
5773> row.names(A) <- letters[24:26] # failed at one point in Dec 2006
5774> A
5775  a
5776x 1
5777y 2
5778z 3
5779> ##
5780>
5781>
5782> ## extreme cases for subsetting of data frames
5783> w <- women[1, ]
5784> w[]
5785  height weight
57861     58    115
5787> w[,drop = TRUE]
5788  height weight
57891     58    115
5790Warning message:
5791In `[.data.frame`(w, , drop = TRUE) : 'drop' argument will be ignored
5792> w[1,]
5793  height weight
57941     58    115
5795> w[,]
5796  height weight
57971     58    115
5798> w[1, , drop = FALSE]
5799  height weight
58001     58    115
5801> w[, , drop = FALSE]
5802  height weight
58031     58    115
5804> w[1, , drop = TRUE]
5805$height
5806[1] 58
5807
5808$weight
5809[1] 115
5810
5811> w[, , drop = TRUE]
5812$height
5813[1] 58
5814
5815$weight
5816[1] 115
5817
5818> ## regression test: code changed for 2.5.0
5819>
5820>
5821> ## data.frame() with zero columns ignored 'row.names'
5822> (x <- data.frame(row.names=1:4))
5823data frame with 0 columns and 4 rows
5824> nrow(x)
5825[1] 4
5826> row.names(x)
5827[1] "1" "2" "3" "4"
5828> attr(x, "row.names")
5829[1] 1 2 3 4
5830> ## ignored prior to 2.5.0.
5831>
5832>
5833> ## identical on data.frames
5834> d0 <- d1 <- data.frame(1:4, row.names=1:4)
5835> row.names(d0) <- NULL
5836> dput(d0)
5837structure(list(X1.4 = 1:4), class = "data.frame", row.names = c(NA,
5838-4L))
5839> dput(d1)
5840structure(list(X1.4 = 1:4), class = "data.frame", row.names = c(NA,
58414L))
5842> identical(d0, d1)
5843[1] TRUE
5844> all.equal(d0, d1)
5845[1] TRUE
5846> row.names(d1) <- as.character(1:4)
5847> dput(d1)
5848structure(list(X1.4 = 1:4), class = "data.frame", row.names = c("1",
5849"2", "3", "4"))
5850> identical(d0, d1)
5851[1] FALSE
5852> all.equal(d0, d1)
5853[1] "Attributes: < Component \"row.names\": Modes: numeric, character >"
5854[2] "Attributes: < Component \"row.names\": target is numeric, current is character >"
5855> ## identical used internal representation prior to 2.5.0
5856>
5857>
5858> ## all.equal
5859> # ignored check.attributes in 2.4.1
5860> all.equal(data.frame(x=1:5, row.names=letters[1:5]),
5861+           data.frame(x=1:5,row.names=LETTERS[1:5]),
5862+           check.attributes=FALSE)
5863[1] TRUE
5864> # treated logicals as numeric
5865> all.equal(c(T, F, F), c(T, T, F))
5866[1] "1 element mismatch"
5867> all.equal(c(T, T, F), c(T, F, F))
5868[1] "1 element mismatch"
5869> # ignored raw:
5870> all.equal(as.raw(1:3), as.raw(1:3))
5871[1] TRUE
5872> all.equal(as.raw(1:3), as.raw(3:1))
5873[1] "2 element mismatches"
5874> ##
5875>
5876>
5877> ## tests of deparsing
5878> # if we run this from stdin, we will have no source, so fake it
5879> f <- function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5880> attr(f, "srcref") <- srcref(srcfilecopy("",
5881+     "function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}"),
5882+     c(1L, 1L, 1L, 56L))
5883> f # uses the source
5884function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5885> dput(f) # not source
5886function (x, xm = max(1L, x))
5887{
5888    xx <- 0L
5889    yy <- NA_real_
5890}
5891> dput(f, control="all") # uses the source
5892function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5893> cat(deparse(f), sep="\n")
5894function (x, xm = max(1L, x))
5895{
5896    xx <- 0L
5897    yy <- NA_real_
5898}
5899> dump("f", file="")
5900f <-
5901function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5902> # remove the source
5903> attr(f, "srcref") <- NULL
5904> f
5905function (x, xm = max(1L, x))
5906{
5907    xx <- 0L
5908    yy <- NA_real_
5909}
5910> dput(f, control="all")
5911function (x, xm = max(1L, x))
5912{
5913    xx <- 0L
5914    yy <- NA_real_
5915}
5916> dump("f", file="")
5917f <-
5918function (x, xm = max(1L, x))
5919{
5920    xx <- 0L
5921    yy <- NA_real_
5922}
5923>
5924> expression(bin <- bin + 1L)
5925expression(bin <- bin + 1L)
5926> ## did not preserve e.g. 1L at some point in pre-2.5.0
5927>
5928>
5929> ## NAs in substr were handled as large negative numbers
5930> x <- "abcde"
5931> substr(x, 1, 3)
5932[1] "abc"
5933> substr(x, NA, 1)
5934[1] NA
5935> substr(x, 1, NA)
5936[1] NA
5937> substr(x, NA, 3) <- "abc"; x
5938[1] NA
5939> substr(x, 1, NA) <- "AA"; x
5940[1] NA
5941> substr(x, 1, 2) <- NA_character_; x
5942[1] NA
5943> ## "" or no change in 2.4.1, except last
5944>
5945>
5946> ## regression tests for pmin/pmax, rewritten in C for 2.5.0
5947> # NULL == integer(0)
5948> pmin(NULL, integer(0))
5949integer(0)
5950> pmax(integer(0), NULL)
5951integer(0)
5952> pmin(NULL, 1:3)# now ok
5953integer(0)
5954> pmax(pi, NULL, 2:4)
5955numeric(0)
5956>
5957> x <- c(1, NA, NA, 4, 5)
5958> y <- c(2, NA, 4, NA, 3)
5959> pmin(x, y)
5960[1]  1 NA NA NA  3
5961> stopifnot(identical(pmin(x, y), pmin(y, x)))
5962> pmin(x, y, na.rm=TRUE)
5963[1]  1 NA  4  4  3
5964> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
5965> pmax(x, y)
5966[1]  2 NA NA NA  5
5967> stopifnot(identical(pmax(x, y), pmax(y, x)))
5968> pmax(x, y, na.rm=TRUE)
5969[1]  2 NA  4  4  5
5970> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
5971>
5972> x <- as.integer(x); y <- as.integer(y)
5973> pmin(x, y)
5974[1]  1 NA NA NA  3
5975> stopifnot(identical(pmin(x, y), pmin(y, x)))
5976> pmin(x, y, na.rm=TRUE)
5977[1]  1 NA  4  4  3
5978> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
5979> pmax(x, y)
5980[1]  2 NA NA NA  5
5981> stopifnot(identical(pmax(x, y), pmax(y, x)))
5982> pmax(x, y, na.rm=TRUE)
5983[1]  2 NA  4  4  5
5984> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
5985>
5986> x <- as.character(x); y <- as.character(y)
5987> pmin(x, y)
5988[1] "1" NA  NA  NA  "3"
5989> stopifnot(identical(pmin(x, y), pmin(y, x)))
5990> pmin(x, y, na.rm=TRUE)
5991[1] "1" NA  "4" "4" "3"
5992> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
5993> pmax(x, y)
5994[1] "2" NA  NA  NA  "5"
5995> stopifnot(identical(pmax(x, y), pmax(y, x)))
5996> pmax(x, y, na.rm=TRUE)
5997[1] "2" NA  "4" "4" "5"
5998> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
5999>
6000> # tests of classed quantities
6001> x <- .leap.seconds[1:23]; y <- rev(x)
6002> x[2] <- y[2] <- x[3] <- y[4] <- NA
6003> format(pmin(x, y), tz="GMT")  # TZ names differ by platform
6004 [1] "1972-07-01" NA           NA           NA           "1976-01-01"
6005 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6006[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6007[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6008[21] "1974-01-01" "1973-01-01" "1972-07-01"
6009> class(pmin(x, y))
6010[1] "POSIXct" "POSIXt"
6011> stopifnot(identical(pmin(x, y), pmin(y, x)))
6012> format(pmin(x, y, na.rm=TRUE), tz="GMT")
6013 [1] "1972-07-01" NA           "1997-07-01" "1975-01-01" "1976-01-01"
6014 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6015[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6016[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6017[21] "1974-01-01" "1973-01-01" "1972-07-01"
6018> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
6019> format(pmax(x, y), tz="GMT")
6020 [1] "2006-01-01" NA           NA           NA           "1994-07-01"
6021 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6022[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6023[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6024[21] "1997-07-01" "1999-01-01" "2006-01-01"
6025> stopifnot(identical(pmax(x, y), pmax(y, x)))
6026> format(pmax(x, y, na.rm=TRUE), tz="GMT")
6027 [1] "2006-01-01" NA           "1997-07-01" "1975-01-01" "1994-07-01"
6028 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6029[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6030[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6031[21] "1997-07-01" "1999-01-01" "2006-01-01"
6032> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
6033>
6034> x <- as.POSIXlt(x, tz="GMT"); y <- as.POSIXlt(y, tz="GMT")
6035> format(pmin(x, y), tz="GMT")
6036 [1] "1972-07-01" NA           NA           NA           "1976-01-01"
6037 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6038[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6039[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6040[21] "1974-01-01" "1973-01-01" "1972-07-01"
6041> class(pmin(x, y))
6042[1] "POSIXlt" "POSIXt"
6043> stopifnot(identical(pmin(x, y), pmin(y, x)))
6044> format(pmin(x, y, na.rm=TRUE), tz="GMT")
6045 [1] "1972-07-01" NA           "1997-07-01" "1975-01-01" "1976-01-01"
6046 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6047[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6048[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6049[21] "1974-01-01" "1973-01-01" "1972-07-01"
6050> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
6051> format(pmax(x, y), tz="GMT")
6052 [1] "2006-01-01" NA           NA           NA           "1994-07-01"
6053 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6054[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6055[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6056[21] "1997-07-01" "1999-01-01" "2006-01-01"
6057> stopifnot(identical(pmax(x, y), pmax(y, x)))
6058> format(pmax(x, y, na.rm=TRUE), tz="GMT")
6059 [1] "2006-01-01" NA           "1997-07-01" "1975-01-01" "1994-07-01"
6060 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6061[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6062[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6063[21] "1997-07-01" "1999-01-01" "2006-01-01"
6064> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
6065> ## regresion tests
6066>
6067>
6068> ## regression tests on names of 1D arrays
6069> x <- as.array(1:3)
6070> names(x) <- letters[x] # sets dimnames, really
6071> names(x)
6072[1] "a" "b" "c"
6073> dimnames(x)
6074[[1]]
6075[1] "a" "b" "c"
6076
6077> attributes(x)
6078$dim
6079[1] 3
6080
6081$dimnames
6082$dimnames[[1]]
6083[1] "a" "b" "c"
6084
6085
6086> names(x) <- NULL
6087> attr(x, "names") <- LETTERS[x] # sets dimnames, really
6088> names(x)
6089[1] "A" "B" "C"
6090> dimnames(x)
6091[[1]]
6092[1] "A" "B" "C"
6093
6094> attributes(x)
6095$dim
6096[1] 3
6097
6098$dimnames
6099$dimnames[[1]]
6100[1] "A" "B" "C"
6101
6102
6103> ## regression tests
6104>
6105>
6106> ## regression tests on NA attribute names
6107> x <- 1:3
6108> attr(x, "NA") <- 4
6109> attributes(x)
6110$`NA`
6111[1] 4
6112
6113> attr(x, "NA")
6114[1] 4
6115> attr(x, NA_character_)
6116NULL
6117> try(attr(x, NA_character_) <- 5)
6118Error in attr(x, NA_character_) <- 5 :
6119  'name' must be non-null character string
6120> ## prior to 2.5.0 NA was treated as "NA"
6121>
6122>
6123> ## qr with pivoting (PR#9623)
6124> A <- matrix(c(0,0,0, 1,1,1), nrow = 3,
6125+             dimnames = list(letters[1:3], c("zero","one")))
6126> y <- matrix(c(6,7,8), nrow = 3, dimnames = list(LETTERS[1:3], "y"))
6127> qr.coef(qr(A), y)
6128      y
6129zero NA
6130one   7
6131> qr.fitted(qr(A), y)
6132  y
6133A 7
6134B 7
6135C 7
6136>
6137> qr.coef(qr(matrix(0:1, 1, dimnames=list(NULL, c("zero","one")))), 5)
6138zero  one
6139  NA    5
6140> ## coef names were returned unpivoted <= 2.5.0
6141>
6142> ## readChar read extra items, terminated on zeros
6143> x <- as.raw(65:74)
6144> readChar(x, nchar=c(3,3,0,3,3,3))
6145[1] "ABC" "DEF" ""    "GHI" "J"
6146> f <- tempfile(tmpdir = getwd())
6147> writeChar("ABCDEFGHIJ", con=f, eos=NULL)
6148> readChar(f, nchar=c(3,3,0,3,3,3))
6149[1] "ABC" "DEF" ""    "GHI" "J"
6150> unlink(f)
6151> ##
6152>
6153>
6154> ## corner cases for cor
6155> set.seed(1)
6156> X <- cbind(NA, 1:3, rnorm(3))
6157> try(cor(X, use = "complete"))
6158Error in cor(X, use = "complete") : no complete element pairs
6159> try(cor(X, use = "complete", method="spearman"))
6160Error in cor(X, use = "complete", method = "spearman") :
6161  no complete element pairs
6162> try(cor(X, use = "complete", method="kendall"))
6163Error in cor(X, use = "complete", method = "kendall") :
6164  no complete element pairs
6165> cor(X, use = "pair")
6166     [,1]       [,2]       [,3]
6167[1,]   NA         NA         NA
6168[2,]   NA  1.0000000 -0.1942739
6169[3,]   NA -0.1942739  1.0000000
6170> cor(X, use = "pair", method="spearman")
6171     [,1] [,2] [,3]
6172[1,]   NA   NA   NA
6173[2,]   NA  1.0 -0.5
6174[3,]   NA -0.5  1.0
6175> cor(X, use = "pair", method="kendall")
6176     [,1]       [,2]       [,3]
6177[1,]   NA         NA         NA
6178[2,]   NA  1.0000000 -0.3333333
6179[3,]   NA -0.3333333  1.0000000
6180>
6181> X[1,1] <- 1
6182> cor(X, use = "complete")
6183     [,1] [,2] [,3]
6184[1,]   NA   NA   NA
6185[2,]   NA   NA   NA
6186[3,]   NA   NA   NA
6187> cor(X, use = "complete", method="spearman")
6188     [,1] [,2] [,3]
6189[1,]   NA   NA   NA
6190[2,]   NA   NA   NA
6191[3,]   NA   NA   NA
6192> cor(X, use = "complete", method="kendall")
6193     [,1] [,2] [,3]
6194[1,]   NA   NA   NA
6195[2,]   NA   NA   NA
6196[3,]   NA   NA   NA
6197> cor(X, use = "pair")
6198     [,1]       [,2]       [,3]
6199[1,]   NA         NA         NA
6200[2,]   NA  1.0000000 -0.1942739
6201[3,]   NA -0.1942739  1.0000000
6202> cor(X, use = "pair", method="spearman")
6203     [,1] [,2] [,3]
6204[1,]   NA   NA   NA
6205[2,]   NA  1.0 -0.5
6206[3,]   NA -0.5  1.0
6207> cor(X, use = "pair", method="kendall")
6208     [,1]       [,2]       [,3]
6209[1,]   NA         NA         NA
6210[2,]   NA  1.0000000 -0.3333333
6211[3,]   NA -0.3333333  1.0000000
6212> ## not consistent in 2.6.x
6213>
6214>
6215> ## confint on rank-deficient models (in part, PR#10494)
6216> junk <- data.frame(x = rep(1, 10L),
6217+                    u = factor(sample(c("Y", "N"), 10, replace=TRUE)),
6218+                    ans = rnorm(10))
6219> fit <-  lm(ans ~ x + u, data = junk)
6220> confint(fit)
6221                 2.5 %    97.5 %
6222(Intercept) -0.3224857 2.2194594
6223x                   NA        NA
6224uY          -2.6821240 0.3560815
6225> confint.default(fit)
6226                 2.5 %    97.5 %
6227(Intercept) -0.1317629 2.0287366
6228x                   NA        NA
6229uY          -2.4541666 0.1281242
6230> ## Mismatch gave NA for 'u' in 2.6.1
6231>
6232>
6233> ## corrupt data frame produced by subsetting (PR#10574)
6234> x <- data.frame(a=1:3, b=2:4)
6235> x[,3] <- x
6236Warning message:
6237In `[<-.data.frame`(`*tmp*`, , 3, value = list(a = 1:3, b = 2:4)) :
6238  provided 2 variables to replace 1 variables
6239> x
6240  a b a.1
62411 1 2   1
62422 2 3   2
62433 3 4   3
6244> ## warning during printing < 2.7.0
6245>
6246>
6247> ## format.factor used to lose dim[names] and names (PR#11512)
6248> x <- factor(c("aa", letters[-1]))
6249> dim(x) <- c(13,2)
6250> format(x, justify="right")
6251      [,1] [,2]
6252 [1,] "aa" " n"
6253 [2,] " b" " o"
6254 [3,] " c" " p"
6255 [4,] " d" " q"
6256 [5,] " e" " r"
6257 [6,] " f" " s"
6258 [7,] " g" " t"
6259 [8,] " h" " u"
6260 [9,] " i" " v"
6261[10,] " j" " w"
6262[11,] " k" " x"
6263[12,] " l" " y"
6264[13,] " m" " z"
6265> ##
6266>
6267>
6268> ## removing columns in within (PR#1131)
6269> abc <- data.frame(a=1:5, b=2:6, c=3:7)
6270> within(abc, b<-NULL)
6271  a c
62721 1 3
62732 2 4
62743 3 5
62754 4 6
62765 5 7
6277> within(abc,{d<-a+7;b<-NULL})
6278  a c  d
62791 1 3  8
62802 2 4  9
62813 3 5 10
62824 4 6 11
62835 5 7 12
6284> within(abc,{a<-a+7;b<-NULL})
6285   a c
62861  8 3
62872  9 4
62883 10 5
62894 11 6
62905 12 7
6291> ## Second produced corrupt data frame in 2.7.1
6292>
6293>
6294> ## aggregate on an empty data frame (PR#13167)
6295> z <- data.frame(a=integer(0), b=numeric(0))
6296> try(aggregate(z, by=z[1], FUN=sum))
6297Error in aggregate.data.frame(z, by = z[1], FUN = sum) :
6298  no rows to aggregate
6299> ## failed in unlist in 2.8.0, now gives explicit message.
6300> aggregate(data.frame(a=1:10)[F], list(rep(1:2, each=5)), sum)
6301  Group.1
63021       1
63032       2
6304> ## used to fail obscurely.
6305>
6306>
6307> ## subsetting data frames with duplicate rows
6308> z <- data.frame(a=1, a=2, b=3, check.names=FALSE)
6309> z[] # OK
6310  a a b
63111 1 2 3
6312> z[1, ]
6313  a a b
63141 1 2 3
6315> ## had row names a, a.1, b in 2.8.0.
6316>
6317>
6318> ## incorrect warning due to lack of fuzz.
6319> TS <-  ts(co2[1:192], freq=24)
6320> tmp2 <- window(TS, start(TS), end(TS))
6321> ## warned in 2.8.0
6322>
6323> ## failed to add tag
6324> Call <- call("foo", 1)
6325> Call[["bar"]] <- 2
6326> Call
6327foo(1, bar = 2)
6328> ## unnamed call in 2.8.1
6329>
6330> options(keep.source = TRUE)
6331> ## $<- on pairlists failed to duplicate (from Felix Andrews,
6332> ## https://stat.ethz.ch/pipermail/r-devel/2009-January/051698.html)
6333> foo <- function(given = NULL) {
6334+     callObj <- quote(callFunc())
6335+     if(!is.null(given)) callObj$given <- given
6336+     if (is.null(given)) callObj$default <- TRUE
6337+     callObj
6338+ }
6339>
6340> foo()
6341callFunc(default = TRUE)
6342> foo(given = TRUE)
6343callFunc(given = TRUE)
6344> foo("blah blah")
6345callFunc(given = "blah blah")
6346> foo(given = TRUE)
6347callFunc(given = TRUE)
6348> foo()
6349callFunc(default = TRUE)
6350> ## altered foo() in 2.8.1.
6351>
6352> ## Using  '#' flag in  sprintf():
6353> forms <- c("%#7.5g","%#5.f", "%#7x", "%#5d", "%#9.0e")
6354> nums <- list(-3.145, -31,   0xabc,  -123L, 123456)
6355> rbind(mapply(sprintf, forms,               nums),
6356+       mapply(sprintf, sub("#", '', forms), nums))
6357     %#7.5g    %#5.f   %#7x      %#5d    %#9.0e
6358[1,] "-3.1450" " -31." "  0xabc" " -123" "   1.e+05"
6359[2,] " -3.145" "  -31" "    abc" " -123" "    1e+05"
6360> ## gave an error in pre-release versions of 2.9.0
6361>
6362> ## (auto)printing of functions {with / without source attribute},
6363> ## including primitives
6364> sink(con <- textConnection("of", "w")) ; c ; sink(NULL); close(con)
6365> of2 <- capture.output(print(c))
6366> stopifnot(identical(of2, of),
6367+           identical(of2, "function (...)  .Primitive(\"c\")"))
6368> ## ^^ would have failed up to R 2.9.x
6369> foo
6370function(given = NULL) {
6371    callObj <- quote(callFunc())
6372    if(!is.null(given)) callObj$given <- given
6373    if (is.null(given)) callObj$default <- TRUE
6374    callObj
6375}
6376<bytecode: 0x16b2078>
6377> print(foo, useSource = FALSE)
6378function (given = NULL)
6379{
6380    callObj <- quote(callFunc())
6381    if (!is.null(given))
6382        callObj$given <- given
6383    if (is.null(given))
6384        callObj$default <- TRUE
6385    callObj
6386}
6387<bytecode: 0x16b2078>
6388> attr(foo, "srcref") <- NULL
6389> foo
6390function (given = NULL)
6391{
6392    callObj <- quote(callFunc())
6393    if (!is.null(given))
6394        callObj$given <- given
6395    if (is.null(given))
6396        callObj$default <- TRUE
6397    callObj
6398}
6399<bytecode: 0x16b2078>
6400> (f <- structure(function(){}, note = "just a note",
6401+                 yada = function() "not the same"))
6402function(){}
6403attr(,"note")
6404[1] "just a note"
6405attr(,"yada")
6406function() "not the same"
6407> print(f, useSource = TRUE)
6408function(){}
6409attr(,"note")
6410[1] "just a note"
6411attr(,"yada")
6412function() "not the same"
6413> print(f, useSource = FALSE) # must print attributes
6414function ()
6415{
6416}
6417attr(,"note")
6418[1] "just a note"
6419attr(,"yada")
6420function ()
6421"not the same"
6422> print.function <- function(x, ...) {
6423+     cat("my print(<function>): "); str(x, give.attr=FALSE); invisible(x) }
6424> print.function
6425my print(<function>): function (x, ...)
6426> print(print.function)
6427my print(<function>): function (x, ...)
6428> rm(print.function)
6429> ## auto-printing and printing differed up to R 2.9.x -- and then *AGAIN* in R 3.6.0
6430>
6431>
6432> ## Make sure deparsing does not reset parameters
6433> print(list(f, expression(foo), f, quote(foo), f, base::list, f),
6434+       useSource = FALSE)
6435[[1]]
6436function ()
6437{
6438}
6439attr(,"note")
6440[1] "just a note"
6441attr(,"yada")
6442function ()
6443"not the same"
6444
6445[[2]]
6446expression(foo)
6447
6448[[3]]
6449function ()
6450{
6451}
6452attr(,"note")
6453[1] "just a note"
6454attr(,"yada")
6455function ()
6456"not the same"
6457
6458[[4]]
6459foo
6460
6461[[5]]
6462function ()
6463{
6464}
6465attr(,"note")
6466[1] "just a note"
6467attr(,"yada")
6468function ()
6469"not the same"
6470
6471[[6]]
6472function (...)  .Primitive("list")
6473
6474[[7]]
6475function ()
6476{
6477}
6478attr(,"note")
6479[1] "just a note"
6480attr(,"yada")
6481function ()
6482"not the same"
6483
6484>
6485> printCoefmat(cbind(0,1))
6486     [,1] [,2]
6487[1,]    0    1
6488> ## would print NaN up to R 2.9.0
6489>
6490>
6491> ## continuity correction for Kendall's tau.  Improves this example.
6492> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "kendall",
6493+          exact = TRUE)
6494
6495	Kendall's rank correlation tau
6496
6497data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6498T = 1, p-value = 0.08333
6499alternative hypothesis: true tau is not equal to 0
6500sample estimates:
6501 tau
6502-0.8
6503
6504> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "kendall",
6505+          exact = FALSE)
6506
6507	Kendall's rank correlation tau
6508
6509data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6510z = -1.9596, p-value = 0.05004
6511alternative hypothesis: true tau is not equal to 0
6512sample estimates:
6513 tau
6514-0.8
6515
6516> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "kendall",
6517+          exact = FALSE, continuity = TRUE)
6518
6519	Kendall's rank correlation tau
6520
6521data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6522z = -1.7146, p-value = 0.08641
6523alternative hypothesis: true tau is not equal to 0
6524sample estimates:
6525 tau
6526-0.8
6527
6528> # and a little for Spearman's
6529> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "spearman",
6530+          exact = TRUE)
6531
6532	Spearman's rank correlation rho
6533
6534data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6535S = 38, p-value = 0.08333
6536alternative hypothesis: true rho is not equal to 0
6537sample estimates:
6538 rho
6539-0.9
6540
6541> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "spearman",
6542+          exact = FALSE)
6543
6544	Spearman's rank correlation rho
6545
6546data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6547S = 38, p-value = 0.03739
6548alternative hypothesis: true rho is not equal to 0
6549sample estimates:
6550 rho
6551-0.9
6552
6553> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "spearman",
6554+          exact = FALSE, continuity = TRUE)
6555
6556	Spearman's rank correlation rho
6557
6558data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6559S = 38, p-value = 0.09689
6560alternative hypothesis: true rho is not equal to 0
6561sample estimates:
6562 rho
6563-0.9
6564
6565> ## Kendall case is wish of PR#13691
6566>
6567>
6568> ## corrupt data frame, PR#13724
6569> foo <- matrix(1:12, nrow = 3)
6570> bar <- as.data.frame(foo)
6571> val <- integer(0)
6572> try(bar$NewCol <- val)
6573Error in `$<-.data.frame`(`*tmp*`, NewCol, value = integer(0)) :
6574  replacement has 0 rows, data has 3
6575> # similar, not in the report
6576> try(bar[["NewCol"]] <- val)
6577Error in `[[<-.data.frame`(`*tmp*`, "NewCol", value = integer(0)) :
6578  replacement has 0 rows, data has 3
6579> # [ ] is tricker, so just check the result is reasonable and prints
6580> bar["NewCol"] <- val
6581> bar[, "NewCol2"] <- val
6582> bar[FALSE, "NewCol3"] <- val
6583> bar
6584  V1 V2 V3 V4 NewCol NewCol2 NewCol3
65851  1  4  7 10     NA      NA      NA
65862  2  5  8 11     NA      NA      NA
65873  3  6  9 12     NA      NA      NA
6588> ## Succeeded but gave corrupt result in 2.9.0
6589>
6590>
6591> ## Printing NA_complex_
6592> m22 <- matrix(list(NA_complex_, 3, "A string", NA_complex_), 2,2)
6593> print(m22)
6594     [,1] [,2]
6595[1,] NA   "A string"
6596[2,] 3    NA
6597> print(m22, na.print="<missing value>")
6598     [,1]            [,2]
6599[1,] <missing value> "A string"
6600[2,] 3               <missing value>
6601> ## used uninitialized variable in C, noticably Windows, for R <= 2.9.0
6602>
6603>
6604> ## non-standard variable names in update etc
6605> ## never guaranteed to work, requested by Sundar Dorai-Raj in
6606> ## https://stat.ethz.ch/pipermail/r-devel/2009-July/054184.html
6607> update(`a: b` ~ x, ~ . + y)
6608`a: b` ~ x + y
6609> ## 2.9.1 dropped backticks
6610>
6611>
6612> ## print(ls.str(.)) did evaluate calls
6613> E <- new.env(); E$cl <- call("print", "Boo !")
6614> ls.str(E)
6615cl :  language print("Boo !")
6616> ## 2.10.0 did print..
6617>
6618>
6619> ## complete.cases with no input
6620> try(complete.cases())
6621Error in complete.cases() : no input has determined the number of cases
6622> try(complete.cases(list(), list()))
6623Error in complete.cases(list(), list()) :
6624  no input has determined the number of cases
6625> ## gave unhelpful messages in 2.10.0, silly results in pre-2.10.1
6626>
6627>
6628> ## error messages from (C-level) evalList
6629> tst <- function(y) { stopifnot(is.numeric(y)); y+ 1 }
6630> try(tst()) # even nicer since R 3.5.0's change to sequential stopifnot()
6631Error in stopifnot(is.numeric(y)) :
6632  argument "y" is missing, with no default
6633> try(c(1,,2))
6634Error in c(1, , 2) : argument 2 is empty
6635> ## change in 2.8.0 made these less clear
6636>
6637>
6638> ## empty levels from cut.Date (cosmetic, PR#14162)
6639> x <- as.Date(c("2009-03-21","2009-03-31"))
6640> cut(x, breaks= "quarter") # had two levels in 2.10.1
6641[1] 2009-01-01 2009-01-01
6642Levels: 2009-01-01
6643> cut(as.POSIXlt(x), breaks= "quarter")
6644[1] 2009-01-01 2009-01-01
6645Levels: 2009-01-01
6646> ## remove empty final level
6647>
6648>
6649> ## tests of error conditions in switch()
6650> switch("a", a=, b=, c=, 4)
6651[1] 4
6652> switch("a", a=, b=, c=, )
6653> .Last.value
6654NULL
6655> switch("a", a=, b=, c=, invisible(4))
6656> .Last.value
6657[1] 4
6658> ## visiblilty changed in 2.11.0
6659>
6660>
6661> ## rounding error in aggregate.ts
6662> ## https://stat.ethz.ch/pipermail/r-devel/2010-April/057225.html
6663> x <- rep(6:10, 1:5)
6664> aggregate(as.ts(x), FUN = mean, ndeltat = 5)
6665Time Series:
6666Start = 1
6667End = 11
6668Frequency = 0.2
6669[1]  7.2  8.8 10.0
6670> x <- rep(6:10, 1:5)
6671> aggregate(as.ts(x), FUN = mean, nfrequency = 0.2)
6672Time Series:
6673Start = 1
6674End = 11
6675Frequency = 0.2
6676[1]  7.2  8.8 10.0
6677> ## platform-dependent in 2.10.1
6678>
6679>
6680> ## wish of PR#9574
6681> a <- c(0.1, 0.3, 0.4, 0.5, 0.3, 0.0001)
6682> format.pval(a, eps=0.01)
6683[1] "0.1"   "0.3"   "0.4"   "0.5"   "0.3"   "<0.01"
6684> format.pval(a, eps=0.01, nsmall =2)
6685[1] "0.10"  "0.30"  "0.40"  "0.50"  "0.30"  "<0.01"
6686> ## granted in 2.12.0
6687>
6688>
6689> ## printing fractional dates
6690> as.Date(0.5, origin="1969-12-31")
6691[1] "1969-12-31"
6692> ## changed to round down in 2.12.1
6693>
6694>
6695> ## printing data frames with  ""  colnames
6696> dfr <- data.frame(x=1:6, CC=11:16, f = gl(3,2)); colnames(dfr)[2] <- ""
6697> dfr
6698  x    f
66991 1 11 1
67002 2 12 1
67013 3 13 2
67024 4 14 2
67035 5 15 3
67046 6 16 3
6705> ## now prints the same as data.matrix(dfr) does here
6706>
6707>
6708> ## format(., zero.print) --> prettyNum()
6709> set.seed(9); m <- matrix(local({x <- rnorm(40)
6710+                                 sign(x)*round(exp(2*x))/10}), 8,5)
6711> noquote(format(m, zero.print= "."))
6712     [,1] [,2] [,3] [,4] [,5]
6713[1,]  .   -0.1 -0.1  .    0.8
6714[2,]  .    .    .   21.4  0.1
6715[3,] -0.1  1.3  0.6  0.2  0.1
6716[4,] -0.1  .    .    .    .
6717[5,]  0.2  0.1  3.4  0.2  0.2
6718[6,]  .   -0.1  0.1  0.2  .
6719[7,]  1.1  4.0 -0.1  .    0.2
6720[8,] -0.1  .    0.6 -0.1  0.1
6721> ## used to print  ". 0" instead of ".  "
6722>
6723>
6724> ## tests of NA having precedence over NaN -- all must print "NA"
6725> min(c(NaN, NA))
6726[1] NA
6727> min(c(NA, NaN)) # NaN in 2.12.2
6728[1] NA
6729> min(NaN, NA_real_)  # NaN in 2.12.2
6730[1] NA
6731> min(NA_real_, NaN)
6732[1] NA
6733> max(c(NaN, NA))
6734[1] NA
6735> max(c(NA, NaN))  # NaN in 2.12.2
6736[1] NA
6737> max(NaN, NA_real_)  # NaN in 2.12.2
6738[1] NA
6739> max(NA_real_, NaN)
6740[1] NA
6741> ## might depend on compiler < 2.13.0
6742>
6743>
6744> ## PR#14514
6745> # Data are from Conover, "Nonparametric Statistics", 3rd Ed, p. 197,
6746> # re-arranged to make a lower-tail test the issue of relevance:  we
6747> # want to see if pregnant nurses exposed to nitrous oxide have higher
6748> # rates of miscarriage, stratifying on the type of nurse.
6749> Nitrous <- array(c(32,210,8,26,18,21,3,3,7,75,0,10), dim = c(2,2,3),
6750+                  dimnames = list(c("Exposed","NotExposed"),
6751+                  c("FullTerm","Miscarriage"),
6752+                  c("DentalAsst","OperRoomNurse","OutpatientNurse")))
6753> mantelhaen.test(Nitrous, exact=TRUE, alternative="less")
6754
6755	Exact conditional test of independence in 2 x 2 x k tables
6756
6757data:  Nitrous
6758S = 57, p-value = 0.1959
6759alternative hypothesis: true common odds ratio is less than 1
676095 percent confidence interval:
6761 0.000000 1.388197
6762sample estimates:
6763common odds ratio
6764        0.6652418
6765
6766> mantelhaen.test(Nitrous, exact=FALSE, alternative="less")
6767
6768	Mantel-Haenszel chi-squared test with continuity correction
6769
6770data:  Nitrous
6771Mantel-Haenszel X-squared = 0.71432, df = 1, p-value = 0.199
6772alternative hypothesis: true common odds ratio is less than 1
677395 percent confidence interval:
6774 0.000000 1.260053
6775sample estimates:
6776common odds ratio
6777        0.6645374
6778
6779> ## exact = FALSE gave the wrong tail in 2.12.2.
6780>
6781>
6782> ## scan(strip.white=TRUE) could strip trailing (but not leading) space
6783> ## inside quoted strings.
6784> writeLines(' "  A  "; "B" ;"C";" D ";"E ";  F  ;G  ', "foo")
6785> cat(readLines("foo"), sep = "\n")
6786 "  A  "; "B" ;"C";" D ";"E ";  F  ;G
6787> scan('foo', list(""), sep=";")[[1]]
6788Read 7 records
6789[1] "   A  " " B "    "C"      " D "    "E "     "  F  "  "G  "
6790> scan('foo', "", sep=";")
6791Read 7 items
6792[1] "   A  " " B "    "C"      " D "    "E "     "  F  "  "G  "
6793> scan('foo', list(""), sep=";", strip.white = TRUE)[[1]]
6794Read 7 records
6795[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6796> scan('foo', "", sep=";", strip.white = TRUE)
6797Read 7 items
6798[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6799> unlink('foo')
6800>
6801> writeLines(' "  A  "\n "B" \n"C"\n" D "\n"E "\n  F  \nG  ', "foo2")
6802> scan('foo2', "")
6803Read 7 items
6804[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6805> scan('foo2', "", strip.white=TRUE) # documented to be ignored ...
6806Read 7 items
6807[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6808> unlink('foo2')
6809> ## Changed for 2.13.0, found when investigating non-bug PR#14522.
6810>
6811>
6812> ## PR#14488: missing values in rank correlations
6813> set.seed(1)
6814> x <- runif(10)
6815> y <- runif(10)
6816> x[3] <- NA; y[5] <- NA
6817> xy <- cbind(x, y)
6818>
6819> cor(x, y, method = "spearman", use = "complete.obs")
6820[1] 0.2380952
6821> cor(x, y, method = "spearman", use = "pairwise.complete.obs")
6822[1] 0.2380952
6823> cor(na.omit(xy),  method = "spearman", use = "complete.obs")
6824          x         y
6825x 1.0000000 0.2380952
6826y 0.2380952 1.0000000
6827> cor(xy,  method = "spearman", use = "complete.obs")
6828          x         y
6829x 1.0000000 0.2380952
6830y 0.2380952 1.0000000
6831> cor(xy,  method = "spearman", use = "pairwise.complete.obs")
6832          x         y
6833x 1.0000000 0.2380952
6834y 0.2380952 1.0000000
6835> ## inconsistent in R < 2.13.0
6836>
6837>
6838> ## integer overflow in rowsum() went undetected
6839> # https://stat.ethz.ch/pipermail/r-devel/2011-March/060304.html
6840> x <- 2e9L
6841> rowsum(c(x, x), c("a", "a"))
6842  [,1]
6843a   NA
6844> rowsum(data.frame(z = c(x, x)), c("a", "a"))
6845   z
6846a NA
6847> ## overflow in R < 2.13.0.
6848>
6849>
6850> ## method dispatch in [[.data.frame:
6851> ## https://stat.ethz.ch/pipermail/r-devel/2011-April/060409.html
6852> d <- data.frame(num = 1:4,
6853+           fac = factor(letters[11:14], levels = letters[1:15]),
6854+           date = as.Date("2011-04-01") + (0:3),
6855+           pv = package_version(c("1.2-3", "4.5", "6.7", "8.9-10")))
6856> for (i in seq_along(d)) print(d[[1, i]])
6857[1] 1
6858[1] k
6859Levels: a b c d e f g h i j k l m n o
6860[1] "2011-04-01"
6861[1] '1.2.3'
6862> ## did not dispatch in R < 2.14.0
6863>
6864>
6865> ## some tests of 24:00 as midnight
6866> as.POSIXlt("2011-05-16 24:00:00", tz = "GMT")
6867[1] "2011-05-17 GMT"
6868> as.POSIXlt("2010-01-31 24:00:00", tz = "GMT")
6869[1] "2010-02-01 GMT"
6870> as.POSIXlt("2011-02-28 24:00:00", tz = "GMT")
6871[1] "2011-03-01 GMT"
6872> as.POSIXlt("2008-02-28 24:00:00", tz = "GMT")
6873[1] "2008-02-29 GMT"
6874> as.POSIXlt("2008-02-29 24:00:00", tz = "GMT")
6875[1] "2008-03-01 GMT"
6876> as.POSIXlt("2010-12-31 24:00:00", tz = "GMT")
6877[1] "2011-01-01 GMT"
6878> ## new in 2.14.0
6879>
6880>
6881> ## Unwarranted conversion of logical values
6882> try(double(FALSE))
6883Error in double(FALSE) : invalid 'length' argument
6884> x <- 1:3
6885> try(length(x) <- TRUE)
6886Error in length(x) <- TRUE : invalid value
6887> ## coerced to integer in 2.13.x
6888>
6889>
6890> ## filter(recursive = TRUE) on input with NAs
6891> # https://stat.ethz.ch/pipermail/r-devel/2011-July/061547.html
6892> x <- c(1:4, NA, 6:9)
6893> cbind(x, "1"=filter(x, 0.5, method="recursive"),
6894+          "2"=filter(x, c(0.5, 0.0), method="recursive"),
6895+          "3"=filter(x, c(0.5, 0.0, 0.0), method="recursive"))
6896Time Series:
6897Start = 1
6898End = 9
6899Frequency = 1
6900   x     1     2     3
69011  1 1.000 1.000 1.000
69022  2 2.500 2.500 2.500
69033  3 4.250 4.250 4.250
69044  4 6.125 6.125 6.125
69055 NA    NA    NA    NA
69066  6    NA    NA    NA
69077  7    NA    NA    NA
69088  8    NA    NA    NA
69099  9    NA    NA    NA
6910> ## NAs in wrong place in R <= 2.13.1.
6911>
6912>
6913> ## PR#14679.  Format depends if TZ is set.
6914> x <- as.POSIXlt(c("2010-02-27 22:30:33", "2009-08-09 06:01:03",
6915+                   "2010-07-23 17:29:59"))
6916> stopifnot(!is.na(trunc(x, units = "days")[1:3]))
6917> ## gave NAs after the first in R < 2.13.2
6918>
6919>
6920> ## explicit error message for silly input (tol = 0)
6921> aa <- c(1, 2, 3, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 13, 14)
6922> try(smooth.spline(aa, seq_along(aa)))
6923Error in smooth.spline(aa, seq_along(aa)) :
6924  'tol' must be strictly positive and finite
6925> fit <- smooth.spline(aa, seq_along(aa), tol = 0.1)
6926> # actual output is too unstable to diff.
6927> ## Better message from R 2.14.2
6928>
6929>
6930> ## PR#14840
6931> d <- data.frame(x = 1:9,
6932+                 y = 1:9 + 0.1*c(1, 2, -1, 0, 1, 1000, 0, 1, -1),
6933+                 w = c(1, 0.5, 2, 1, 2, 0, 1, 2, 1))
6934> fit <- lm(y ~ x, data=d, weights=w)
6935> summary(fit)
6936
6937Call:
6938lm(formula = y ~ x, data = d, weights = w)
6939
6940Weighted Residuals:
6941    Min      1Q  Median      3Q     Max
6942-0.1883 -0.0310  0.0000  0.1006  0.1165
6943
6944Coefficients:
6945            Estimate Std. Error t value Pr(>|t|)
6946(Intercept)  0.03949    0.08612   0.459    0.663
6947x            0.99788    0.01502  66.419 7.83e-10 ***
6948---
6949Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
6950
6951Residual standard error: 0.1232 on 6 degrees of freedom
6952Multiple R-squared:  0.9986,	Adjusted R-squared:  0.9984
6953F-statistic:  4412 on 1 and 6 DF,  p-value: 7.834e-10
6954
6955> ## issue is how the 5-number summary is labelled
6956> ## (also seen in example(case.names))
6957>
6958>
6959> ## is.unsorted got it backwards for dataframes of more than one column
6960> ## it is supposed to look for violations of x[2] > x[1], x[3] > x[2], etc.
6961> is.unsorted(data.frame(x=2:1))
6962[1] FALSE
6963> is.unsorted(data.frame(x=1:2, y=3:4))
6964[1] FALSE
6965> is.unsorted(data.frame(x=3:4, y=1:2))
6966[1] TRUE
6967> ## R < 2.15.1 got these as FALSE, TRUE, FALSE.
6968>
6969>
6970> library("methods")# (not needed here)
6971> assertError <- tools::assertError
6972> assertErrorV <- function(expr) assertError(expr, verbose=TRUE)
6973> assertErrorV( getMethod(ls, "bar", fdef=ls) )
6974Asserted error: no generic function found for 'ls'
6975> assertErrorV( getMethod(show, "bar") )
6976Asserted error: no method found for function 'show' and signature bar
6977> ## R < 2.15.1 gave
6978> ##   cannot coerce type 'closure' to vector of type 'character'
6979>
6980>
6981> ## corner cases for array
6982> # allowed, gave non-array in 2.15.x
6983> try(array(1, integer()))
6984Error in array(1, integer()) : 'dims' cannot be of length 0
6985> # if no dims, an error to supply dimnames
6986> try(array(1, integer(), list(1, 2)))
6987Error in array(1, integer(), list(1, 2)) : 'dims' cannot be of length 0
6988> ##
6989>
6990>
6991> ## is.na() on an empty dataframe (PR#14059)
6992> DF <- data.frame(row.names=1:3)
6993> is.na(DF); str(.Last.value)
6994
69951
69962
69973
6998 logi[1:3, 0 ]
6999 - attr(*, "dimnames")=List of 2
7000  ..$ : chr [1:3] "1" "2" "3"
7001  ..$ : NULL
7002> is.na(DF[FALSE, ]); str(.Last.value)
7003<0 x 0 matrix>
7004 logi[0 , 0 ]
7005> ## first failed in R 2.15.1, second gave NULL
7006>
7007>
7008> ## split() with dots in levels
7009> df <- data.frame(x = rep(c("a", "a.b"), 3L), y = rep(c("b.c", "c"), 3L),
7010+                  z = 1:6)
7011> df
7012    x   y z
70131   a b.c 1
70142 a.b   c 2
70153   a b.c 3
70164 a.b   c 4
70175   a b.c 5
70186 a.b   c 6
7019> split(df, df[, 1:2]) # default is sep = "."
7020$a.b.c
7021    x   y z
70221   a b.c 1
70232 a.b   c 2
70243   a b.c 3
70254 a.b   c 4
70265   a b.c 5
70276 a.b   c 6
7028
7029$a.b.b.c
7030[1] x y z
7031<0 rows> (or 0-length row.names)
7032
7033$a.c
7034[1] x y z
7035<0 rows> (or 0-length row.names)
7036
7037> split(df, df[, 1:2], sep = ":")
7038$`a:b.c`
7039  x   y z
70401 a b.c 1
70413 a b.c 3
70425 a b.c 5
7043
7044$`a.b:b.c`
7045[1] x y z
7046<0 rows> (or 0-length row.names)
7047
7048$`a:c`
7049[1] x y z
7050<0 rows> (or 0-length row.names)
7051
7052$`a.b:c`
7053    x y z
70542 a.b c 2
70554 a.b c 4
70566 a.b c 6
7057
7058> ##
7059>
7060>
7061> ## The difference between sort.list and order
7062> z <- c(4L, NA, 2L, 3L, NA, 1L)
7063> order(z, na.last = NA)
7064[1] 6 3 4 1
7065> sort.list(z, na.last = NA)
7066[1] 4 2 3 1
7067> sort.list(z, na.last = NA, method = "shell")
7068[1] 4 2 3 1
7069> sort.list(z, na.last = NA, method = "quick")
7070[1] 4 2 3 1
7071> sort.list(z, na.last = NA, method = "radix")
7072[1] 4 2 3 1
7073> ## Differences first documented in R 2.15.2
7074>
7075>
7076> ## PR#15028: names longer than cutoff NB (= 1000)
7077> NB <- 1000
7078> lns <- capture.output(
7079+     setNames(c(255, 1000, 30000),
7080+              c(paste(rep.int("a", NB+2), collapse=""),
7081+                paste(rep.int("b", NB+2), collapse=""),
7082+                paste(rep.int("c", NB+2), collapse=""))))
7083> sub("^ +", '', lns[2* 1:3])
7084[1] "255 "   "1000 "  "30000 "
7085> ## *values* were cutoff when printed
7086>
7087>
7088> ## allows deparse limits to be set
7089> form <- reallylongnamey ~ reallylongnamex0 + reallylongnamex1 + reallylongnamex2 + reallylongnamex3
7090> form
7091reallylongnamey ~ reallylongnamex0 + reallylongnamex1 + reallylongnamex2 +
7092    reallylongnamex3
7093> op <- options(deparse.cutoff=80)
7094> form
7095reallylongnamey ~ reallylongnamex0 + reallylongnamex1 + reallylongnamex2 + reallylongnamex3
7096> options(deparse.cutoff=50)
7097> form
7098reallylongnamey ~ reallylongnamex0 + reallylongnamex1 +
7099    reallylongnamex2 + reallylongnamex3
7100> options(op)
7101> ## fixed to 60 in R 2.15.x
7102>
7103>
7104> ## PR#15179: user defined binary ops were not deparsed properly
7105> quote( `%^%`(x, `%^%`(y,z)) )
7106x %^% (y %^% z)
7107> quote( `%^%`(x) )
7108`%^%`(x)
7109> ##
7110>
7111>
7112> ## Anonymous function calls were not deparsed properly
7113> substitute(f(x), list(f = function(x) x + 1))
7114(function(x) x + 1)(x)
7115> substitute(f(x), list(f = quote(function(x) x + 1)))
7116(function(x) x + 1)(x)
7117> substitute(f(x), list(f = quote(f+g)))
7118(f + g)(x)
7119> substitute(f(x), list(f = quote(base::mean)))
7120base::mean(x)
7121> substitute(f(x), list(f = quote(a[n])))
7122a[n](x)
7123> substitute(f(x), list(f = quote(g(y))))
7124g(y)(x)
7125> ## The first three need parens, the last three don't.
7126>
7127>
7128> ## PR#15247 : str() on invalid data frame names (where print() works):
7129> d <- data.frame(1:3, "B", 4, stringsAsFactors=TRUE)
7130> names(d) <- c("A", "B\xba","C\xabcd")
7131> str(d)
7132'data.frame':	3 obs. of  3 variables:
7133 $ A      : int  1 2 3
7134 $ B�  : Factor w/ 1 level "B": 1 1 1
7135 $ C�cd: num  4 4 4
7136> ## gave an error in R <= 3.0.0
7137>
7138>
7139> ## PR#15299 : adding a simple vector to a classed object produced a bad result:
7140> 1:2 + table(1:2)
7141
71421 2
71432 3
7144> ## Printed the class attribute in R <= 3.0.0
7145>
7146>
7147> ## PR#15311 : regmatches<- mishandled regexpr results.
7148>   x <- c('1', 'B', '3')
7149>   m <- regexpr('\\d', x)
7150>   regmatches(x, m) <- c('A', 'C')
7151>   print(x)
7152[1] "A" "B" "C"
7153> ## Gave a warning and a wrong result up to 3.0.1
7154>
7155>
7156> ## Bad warning found by Radford Neal
7157>   saveopt <- options(warnPartialMatchDollar=TRUE)
7158>   pl <- pairlist(abc=1, def=2)
7159>   pl$ab
7160[1] 1
7161Warning message:
7162In pl$ab : partial match of 'ab' to 'abc'
7163>   if (!is.null(saveopt[["warnPartialMatchDollar"]])) options(saveopt)
7164> ## 'abc' was just ''
7165>
7166>
7167> ## seq() with NaN etc inputs now gives explicit error messages
7168> try(seq(NaN))
7169Error in seq.default(NaN) : 'from' must be a finite number
7170> try(seq(to = NaN))
7171Error in seq.default(to = NaN) : 'to' must be a finite number
7172> try(seq(NaN, NaN))
7173Error in seq.default(NaN, NaN) : 'from' must be a finite number
7174> try(seq.int(NaN))
7175Error in seq.int(NaN) : 'from' must be a finite number
7176> try(seq.int(to = NaN))
7177Error in seq.int(to = NaN) : 'to' must be a finite number
7178> try(seq.int(NaN, NaN))
7179Error in seq.int(NaN, NaN) : 'from' must be a finite number
7180> ## R 3.0.1 gave messages from ':' or about negative-length vectors.
7181>
7182>
7183> ## Some dimnames were lost from 1D arrays: PR#15301
7184> x <- array(0:2, dim=3, dimnames=list(d1=LETTERS[1:3]))
7185> x
7186d1
7187A B C
71880 1 2
7189> x[]
7190d1
7191A B C
71920 1 2
7193> x[3:1]
7194d1
7195C B A
71962 1 0
7197> x <- array(0, dimnames=list(d1="A"))
7198> x
7199d1
7200A
72010
7202> x[]
7203d1
7204A
72050
7206> x[drop = FALSE]
7207d1
7208A
72090
7210> ## lost dimnames in 3.0.1
7211>
7212>
7213> ## PR#15396
7214> load(file.path(Sys.getenv('SRCDIR'), 'arima.rda'))
7215> (f1 <- arima(x, xreg = xreg, order = c(1,1,1), seasonal = c(1,0,1)))
7216
7217Call:
7218arima(x = x, order = c(1, 1, 1), seasonal = c(1, 0, 1), xreg = xreg)
7219
7220Coefficients:
7221          ar1     ma1    sar1     sma1    xreg
7222      -0.4791  0.3525  0.9877  -0.8295  0.3574
7223s.e.   0.4162  0.4420  0.0329   0.2209  0.7440
7224
7225sigma^2 estimated as 0.001499:  log likelihood = 163.79,  aic = -315.58
7226> (f2 <- arima(diff(x), xreg = diff(xreg), order = c(1,0,1), seasonal = c(1,0,1),
7227+              include.mean = FALSE))
7228
7229Call:
7230arima(x = diff(x), order = c(1, 0, 1), seasonal = c(1, 0, 1), xreg = diff(xreg),
7231    include.mean = FALSE)
7232
7233Coefficients:
7234          ar1     ma1    sar1     sma1  diff(xreg)
7235      -0.4791  0.3526  0.9877  -0.8295      0.3571
7236s.e.   0.4162  0.4420  0.0329   0.2210      0.7441
7237
7238sigma^2 estimated as 0.001499:  log likelihood = 163.79,  aic = -315.58
7239> stopifnot(all.equal(coef(f1), coef(f2), tolerance = 1e-3, check.names = FALSE))
7240> ## first gave local optim in 3.0.1
7241>
7242> ## all.equal always checked the names
7243> x <- c(a=1, b=2)
7244> y <- c(a=1, d=2)
7245> all.equal(x, y, check.names = FALSE)
7246[1] TRUE
7247> ## failed on mismatched attributes
7248>
7249>
7250> ## PR#15411, plus digits change
7251> format(9992, digits = 3)
7252[1] "9992"
7253> format(9996, digits = 3)
7254[1] "9996"
7255> format(0.0002, digits = 0, nsmall = 2)
7256[1] "0.00"
7257> format(pi*10, digits = 0, nsmall = 1)
7258[1] "31.4"
7259> ## second added an extra space; 3rd and 4th were not allowed.
7260>
7261> ## and one branch of this was wrong:
7262> xx <- c(-86870268, 107833358, 302536985, 481015309, 675718935, 854197259,
7263+         1016450281, 1178703303, 1324731023, 1454533441)
7264> xx
7265 [1]  -86870268  107833358  302536985  481015309  675718935  854197259
7266 [7] 1016450281 1178703303 1324731023 1454533441
7267> ## dropped spaces without long doubles
7268>
7269> ## and rounding was being detected improperly (PR#15583)
7270> 1000* ((10^(1/4)) ^ c(0:4))
7271[1]  1000.000  1778.279  3162.278  5623.413 10000.000
7272> 7/0.07
7273[1] 100
7274> ## Spacing was incorrect
7275>
7276>
7277> ## PR#15468
7278> M <- matrix(11:14, ncol=2, dimnames=list(paste0("Row", 1:2), paste0("Col",
7279+ 1:2)))
7280> L <- list(elem1=1, elem2=2)
7281> rbind(M, L)
7282     Col1 Col2
7283Row1 11   13
7284Row2 12   14
7285L    1    2
7286> rbind(L, M)
7287     elem1 elem2
7288L    1     2
7289Row1 11    13
7290Row2 12    14
7291> cbind(M, L)
7292     Col1 Col2 L
7293Row1 11   13   1
7294Row2 12   14   2
7295> cbind(L, M)
7296      L Col1 Col2
7297elem1 1 11   13
7298elem2 2 12   14
7299> ## lost the dim of M, so returned NULL entries
7300>
7301>
7302> ## NA_character_ was not handled properly in min and max (reported by Magnus Thor Torfason)
7303> str(min(NA, "bla"))
7304 chr NA
7305> str(min("bla", NA))
7306 chr NA
7307> str(min(NA_character_, "bla"))
7308 chr NA
7309> str(max(NA, "bla"))
7310 chr NA
7311> str(max("bla", NA))
7312 chr NA
7313> str(max(NA_character_, "bla"))
7314 chr NA
7315> ## NA_character_ could be treated as "NA"; depending on the locale, it would not necessarily
7316> ## be the min or max.
7317>
7318>
7319> ## When two entries needed to be cut to width, str() mixed up
7320> ## the values (reported by Gerrit Eichner)
7321> oldopts <- options(width=70)
7322> n <- 11      # number of rows of data frame
7323> M <- 10000   # order of magnitude of numerical values
7324> longer.char.string <- "zjtvorkmoydsepnxkabmeondrjaanutjmfxlgzmrbjp"
7325> X <- data.frame( A = 1:n * M,
7326+                  B = factor(rep(longer.char.string, n)))
7327> str( X, strict.width = "cut")
7328'data.frame':	11 obs. of  2 variables:
7329 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
7330 $ B: Factor w/ 1 level "zjtvorkmoydsepnxkabmeondrjaanutjmfxlgzmrbj"..
7331> options(oldopts)
7332> ## The first row of the str() result was duplicated.
7333>
7334>
7335> ## PR15624: rounding in extreme cases
7336> dpois(2^52,1,1)
7337[1] -1.578226e+17
7338> dpois(2^52+1,1,1)
7339[1] -1.578226e+17
7340> ## second warned in R 3.0.2.
7341>
7342>
7343> ## Example from PR15625
7344> f <- file.path(Sys.getenv('SRCDIR'), 'EmbeddedNuls.csv')
7345> ## This is a file with a UTF-8 BOM and some fields which are a single nul.
7346> ## The output does rely on this being run in a non-UTF-8 locale (C in tests).
7347> read.csv(f) # warns
7348  X...ColA ColB ColC
73491        a   NA   NA
73502        b   NA   NA
73513        c   NA   NA
73524        d   NA   NA
73535        e   NA    1
73546        f   NA    1
7355Warning messages:
73561: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7357  line 2 appears to contain embedded nulls
73582: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7359  line 3 appears to contain embedded nulls
73603: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7361  line 4 appears to contain embedded nulls
73624: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7363  line 5 appears to contain embedded nulls
73645: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
7365  embedded nul(s) found in input
7366> read.csv(f, skipNul = TRUE, fileEncoding = "UTF-8-BOM")
7367  ColA ColB ColC
73681    a   NA    1
73692    b   NA    1
73703    c   NA    1
73714    d   NA    1
73725    e   NA    1
73736    f   NA    1
7374> ## 'skipNul' is new in 3.1.0.  Should not warn on BOM, ignore in second.
7375>
7376>
7377> ## all.equal datetime method
7378> x <- Sys.time()
7379> all.equal(x,x)
7380[1] TRUE
7381>
7382> # FIXME: check.tzone = FALSE needed because since 79037, all.equal.POSIXt
7383> # strictly reports "" and the current time zone (even from TZ environment
7384> # variable) as different.  The conversion round-trip from Sys.time()
7385> # (POSIXct) via POSIXlt and back to POSIXct creates an object with the
7386> # current time zone, yet the original is with "" as time zone (and both
7387> # refer to the same time zone).
7388> all.equal(x, as.POSIXlt(x), check.tzone = FALSE)
7389[1] TRUE
7390>
7391> all.equal(x, as.numeric(x))  # errored in R <= 4.0.2
7392[1] "'current' is not a POSIXt"
7393> all.equal(x, as.POSIXlt(x, tz = "EST5EDT"))
7394[1] "'tzone' attributes are inconsistent ('' and 'EST5EDT')"
7395> all.equal(x, x+1e-4)
7396[1] TRUE
7397> isTRUE(all.equal(x, x+0.002)) # message will depend on representation error
7398[1] FALSE
7399> ## as.POSIXt method is new in 3.1.0.
7400>
7401>
7402>
7403> ## Misuse of PR#15633
7404> try(bartlett.test(yield ~ block*N, data = npk))
7405Error in bartlett.test.formula(yield ~ block * N, data = npk) :
7406  'formula' should be of the form response ~ group
7407> try(fligner.test (yield ~ block*N, data = npk))
7408Error in fligner.test.formula(yield ~ block * N, data = npk) :
7409  'formula' should be of the form response ~ group
7410> ## used the first factor with an incorrect description in R < 3.0.3
7411>
7412>
7413> ## Misguided expectation of PR#15687
7414> xx <- window(AirPassengers, start = 1960)
7415> cbind(xx, xx)
7416          xx  xx
7417Jan 1960 417 417
7418Feb 1960 391 391
7419Mar 1960 419 419
7420Apr 1960 461 461
7421May 1960 472 472
7422Jun 1960 535 535
7423Jul 1960 622 622
7424Aug 1960 606 606
7425Sep 1960 508 508
7426Oct 1960 461 461
7427Nov 1960 390 390
7428Dec 1960 432 432
7429> op <- options(digits = 2)
7430> cbind(xx, xx)
7431          xx  xx
7432Jan 1960 417 417
7433Feb 1960 391 391
7434Mar 1960 419 419
7435Apr 1960 461 461
7436May 1960 472 472
7437Jun 1960 535 535
7438Jul 1960 622 622
7439Aug 1960 606 606
7440Sep 1960 508 508
7441Oct 1960 461 461
7442Nov 1960 390 390
7443Dec 1960 432 432
7444> options(op)
7445> ## 'digits' was applied to the time.
7446>
7447>
7448> ## Related to PR#15190
7449> difftime(
7450+     as.POSIXct(c("1970-01-01 00:00:00", "1970-01-01 12:00:00"), tz="EST5EDT"),
7451+     as.POSIXct(c("1970-01-01 00:00:00", "1970-01-01 00:00:00"), tz="UTC"))
7452Time differences in hours
7453[1]  5 17
7454> ## kept tzone from first arg.
7455>
7456>
7457> ## PR#15706
7458> x1 <- as.dendrogram(hclust(dist(c(i=1,ii=2,iii=3,v=5,vi=6,vii=7))))
7459> attr(cophenetic(x1), "Labels")
7460[1] "iii" "i"   "ii"  "vii" "v"   "vi"
7461> ## gave a matrix in 3.0.3
7462>
7463>
7464> ## PR#15708
7465> aa <- anova( lm(sr ~ ., data = LifeCycleSavings) )
7466> op <- options(width = 50)
7467> aa
7468Analysis of Variance Table
7469
7470Response: sr
7471          Df Sum Sq Mean Sq F value    Pr(>F)
7472pop15      1 204.12 204.118 14.1157 0.0004922 ***
7473pop75      1  53.34  53.343  3.6889 0.0611255 .
7474dpi        1  12.40  12.401  0.8576 0.3593551
7475ddpi       1  63.05  63.054  4.3605 0.0424711 *
7476Residuals 45 650.71  14.460
7477---
7478Signif. codes:
74790 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
7480> options(width = 40)
7481> aa ; options(op)
7482Analysis of Variance Table
7483
7484Response: sr
7485          Df Sum Sq Mean Sq F value
7486pop15      1 204.12 204.118 14.1157
7487pop75      1  53.34  53.343  3.6889
7488dpi        1  12.40  12.401  0.8576
7489ddpi       1  63.05  63.054  4.3605
7490Residuals 45 650.71  14.460
7491             Pr(>F)
7492pop15     0.0004922 ***
7493pop75     0.0611255 .
7494dpi       0.3593551
7495ddpi      0.0424711 *
7496Residuals
7497---
7498Signif. codes:
7499  0 '***' 0.001 '**' 0.01 '*' 0.05
7500  '.' 0.1 ' ' 1
7501> ## did not line wrap "Signif. codes" previously
7502>
7503>
7504> ## PR#15718
7505> d <- data.frame(a=1)
7506> d[integer(), "a"] <- 2
7507> ## warned in 3.0.3.
7508>
7509>
7510> ## PR#15781
7511> options(foo = 1)
7512> print(options(foo = NULL))
7513$foo
7514[1] 1
7515
7516> ## printed wrong value in 3.1.0
7517>
7518>
7519> ## getParseData bug reported by Andrew Redd
7520> raw <- "
7521+ function( a   # parameter 1
7522+          , b=2 # parameter 2
7523+          ){a+b}"
7524> p <- parse(text = raw)
7525> getParseData(p)
7526   line1 col1 line2 col2 id parent          token terminal          text
752732     2    1     4   15 32      0           expr    FALSE
75283      2    1     2    8  3     32       FUNCTION     TRUE      function
75294      2    9     2    9  4     32            '('     TRUE             (
75305      2   11     2   11  5     32 SYMBOL_FORMALS     TRUE             a
75316      2   15     2   27  6     32        COMMENT     TRUE # parameter 1
75328      3   10     3   10  8     32            ','     TRUE             ,
753310     3   12     3   12 10     32 SYMBOL_FORMALS     TRUE             b
753411     3   13     3   13 11     32     EQ_FORMALS     TRUE             =
753512     3   14     3   14 12     13      NUM_CONST     TRUE             2
753613     3   14     3   14 13     32           expr    FALSE
753714     3   16     3   28 14     32        COMMENT     TRUE # parameter 2
753816     4   10     4   10 16     32            ')'     TRUE             )
753929     4   11     4   15 29     32           expr    FALSE
754019     4   11     4   11 19     29            '{'     TRUE             {
754126     4   12     4   14 26     29           expr    FALSE
754220     4   12     4   12 20     22         SYMBOL     TRUE             a
754322     4   12     4   12 22     26           expr    FALSE
754421     4   13     4   13 21     26            '+'     TRUE             +
754523     4   14     4   14 23     25         SYMBOL     TRUE             b
754625     4   14     4   14 25     26           expr    FALSE
754724     4   15     4   15 24     29            '}'     TRUE             }
7548> ## Got some parents wrong
7549>
7550>
7551> ## wish of PR#15819
7552> set.seed(123); x <- runif(10); y <- rnorm(10)
7553> op <- options(OutDec = ",")
7554> fit <- lm(y ~ x)
7555> summary(fit)
7556
7557Call:
7558lm(formula = y ~ x)
7559
7560Residuals:
7561     Min       1Q   Median       3Q      Max
7562-1,62155 -0,33471  0,05238  0,55227  1,19742
7563
7564Coefficients:
7565            Estimate Std. Error t value Pr(>|t|)
7566(Intercept)   0,8994     0,6282   1,432    0,190
7567x            -1,3275     0,9780  -1,357    0,212
7568
7569Residual standard error: 0,8648 on 8 degrees of freedom
7570Multiple R-squared:  0,1872,	Adjusted R-squared:  0,08557
7571F-statistic: 1,842 on 1 and 8 DF,  p-value: 0,2117
7572
7573> options(op)
7574> ## those parts using formatC still used a decimal point.
7575>
7576>
7577> ## Printing a list with "bad" component names
7578> L <- list(`a\\b` = 1, `a\\c` = 2, `a\bc` = "backspace")
7579> setClass("foo", representation(`\\C` = "numeric"))
7580> ## the next three all print correctly:
7581> names(L)
7582[1] "a\\b" "a\\c" "a\bc"
7583> unlist(L)
7584       a\\b        a\\c        a\bc
7585        "1"         "2" "backspace"
7586> as.pairlist(L)
7587$`a\\b`
7588[1] 1
7589
7590$`a\\c`
7591[1] 2
7592
7593$`a\bc`
7594[1] "backspace"
7595
7596> cat(names(L), "\n")# yes, backspace is backspace here
7597a\b a\c ac
7598> L
7599$`a\\b`
7600[1] 1
7601
7602$`a\\c`
7603[1] 2
7604
7605$`a\bc`
7606[1] "backspace"
7607
7608> new("foo")
7609An object of class "foo"
7610Slot "\\C":
7611numeric(0)
7612
7613> ## the last two lines printed wrongly in R <= 3.1.1
7614>
7615>
7616> ## Printing of arrays where last dim(.) == 0 :
7617> r <- matrix(,0,4, dimnames=list(Row=NULL, Col=paste0("c",1:4)))
7618> r
7619      Col
7620Row    c1 c2 c3 c4
7621> t(r) # did not print "Row", "Col"
7622    Row
7623Col
7624  c1
7625  c2
7626  c3
7627  c4
7628> A <- array(dim=3:0, dimnames=list(D1=c("a","b","c"), D2=c("X","Y"), D3="I", D4=NULL))
7629> A ## did not print *anything*
7630<3 x 2 x 1 x 0 array of logical>
7631   D2
7632D1  X Y
7633  a
7634  b
7635  c
7636
7637> A[,,"I",] # ditto
7638<3 x 2 x 0 array of logical>
7639   D2
7640D1  X Y
7641  a
7642  b
7643  c
7644
7645> A[,,0,]   # ditto
7646<3 x 2 x 0 x 0 array of logical>
7647   D2
7648D1  X Y
7649  a
7650  b
7651  c
7652
7653> aperm(A, c(3:1,4))   # ditto
7654<1 x 2 x 3 x 0 array of logical>
7655   D2
7656D3  X Y
7657  I
7658
7659> aperm(A, c(1:2, 4:3))# ditto
7660<3 x 2 x 0 x 1 array of logical>
7661   D2
7662D1  X Y
7663  a
7664  b
7665  c
7666
7667> unname(A)            # ditto
7668<3 x 2 x 1 x 0 array of logical>
7669     [,1] [,2]
7670[1,]
7671[2,]
7672[3,]
7673
7674> format(A[,,1,])	     # ditto
7675<3 x 2 x 0 array of character>
7676   D2
7677D1  X Y
7678  a
7679  b
7680  c
7681
7682> aperm(A, 4:1) # was ok, is unchanged
7683, , D2 = X, D1 = a
7684
7685      D3
7686D4     I
7687
7688, , D2 = Y, D1 = a
7689
7690      D3
7691D4     I
7692
7693, , D2 = X, D1 = b
7694
7695      D3
7696D4     I
7697
7698, , D2 = Y, D1 = b
7699
7700      D3
7701D4     I
7702
7703, , D2 = X, D1 = c
7704
7705      D3
7706D4     I
7707
7708, , D2 = Y, D1 = c
7709
7710      D3
7711D4     I
7712
7713> ## sometimes not printing anything in R <= 3.1.1
7714>
7715>
7716> ## Printing objects with very long names cut off literal values (PR#15999)
7717> make_long_name <- function(n)
7718+ {
7719+   paste0(rep("a", n), collapse = "")
7720+ }
7721> setNames(TRUE, make_long_name(1000))  # value printed as TRU
7722aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7723                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   TRUE
7724> setNames(TRUE, make_long_name(1002))  # value printed as T
7725aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7726                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   TRUE
7727> setNames(TRUE, make_long_name(1003))  # value not printed
7728aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7729                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   TRUE
7730> ##
7731>
7732>
7733> ## PR#16437
7734> dd <- data.frame(F = factor(rep(c("A","B","C"), each = 3)), num = 1:9)
7735> cs <- list(F = contr.sum(3, contrasts = FALSE))
7736> a1 <- aov(num ~ F, data = dd, contrasts = cs)
7737> model.tables(a1, "means")
7738Tables of means
7739Grand mean
7740
77415
7742
7743 F
7744F
7745A B C
77462 5 8
7747> t1 <- TukeyHSD(a1) ## don't print to avoid precision issues.
7748> a2 <- aov(num ~ 0+F, data = dd, contrasts = cs)
7749> model.tables(a2, "means")
7750Tables of means
7751
7752 F
7753F
7754A B C
77552 5 8
7756> t2 <- TukeyHSD(a2)
7757> attr(t1, "orig.call") <- attr(t2, "orig.call")
7758> stopifnot(all.equal(t1, t2))
7759> ## functions both failed on a2 in R <= 3.2.2.
7760>
7761>
7762> ## deparse() did not add parens before [
7763> substitute(a[1], list(a = quote(x * y)))
7764(x * y)[1]
7765> ## should be (x * y)[1], was x * y[1]
7766> # Check all levels of precedence
7767> # (Comment out illegal ones)
7768> quote(`$`(a :: b, c))
7769a::b$c
7770> # quote(`::`(a $ b, c $ d))
7771> quote(`[`(a $ b, c $ d))
7772a$b[c$d]
7773> quote(`$`(a[b], c))
7774a[b]$c
7775> quote(`^`(a[b], c[d]))
7776a[b]^c[d]
7777> quote(`[`(a ^ b, c ^ d))
7778(a^b)[c^d]
7779> quote(`-`(a ^ b))
7780-a^b
7781> quote(`^`(-b, -d))
7782(-b)^-d
7783> quote(`:`(-b, -d))
7784-b:-d
7785> quote(`-`(a : b))
7786-(a:b)
7787> quote(`%in%`(a : b, c : d))
7788a:b %in% c:d
7789> quote(`:`(a %in% b, c %in% d))
7790(a %in% b):(c %in% d)
7791> quote(`*`(a %in% b, c %in% d))
7792a %in% b * c %in% d
7793> quote(`%in%`(a * b, c * d))
7794(a * b) %in% (c * d)
7795> quote(`+`(a * b, c * d))
7796a * b + c * d
7797> quote(`*`(a + b, c + d))
7798(a + b) * (c + d)
7799> quote(`<`(a + b, c + d))
7800a + b < c + d
7801> quote(`+`(a < b, c < d))
7802(a < b) + (c < d)
7803> quote(`!`(a < b))
7804!a < b
7805> quote(`<`(!b, !d))
7806(!b) < !d
7807> quote(`&`(!b, !d))
7808!b & !d
7809> quote(`!`(a & b))
7810!(a & b)
7811> quote(`|`(a & b, c & d))
7812a & b | c & d
7813> quote(`&`(a | b, c | d))
7814(a | b) & (c | d)
7815> quote(`~`(a | b, c | d))
7816a | b ~ c | d
7817> quote(`|`(a ~ b, c ~ d))
7818(a ~ b) | (c ~ d)
7819> quote(`->`(a ~ b, d))
7820`->`(a ~ b, d)
7821> quote(`~`(a -> b, c -> d))
7822(b <- a) ~ (d <- c)
7823> quote(`<-`(a, c -> d))
7824a <- d <- c
7825> quote(`->`(a <- b, c))
7826`->`(a <- b, c)
7827> quote(`=`(a, c <- d))
7828a = c <- d
7829> quote(`<-`(a, `=`(c, d)))
7830a <- (c = d)
7831> quote(`?`(`=`(a, b), `=`(c, d)))
7832`?`((a = b), (c = d))
7833> quote(`=`(a, c ? d))
7834a = `?`(c, d)
7835> quote(`?`(a = b))
7836`?`(a = b)
7837> quote(`=`(b, ?d))
7838b = `?`(d)
7839>
7840> ## dput() quoted the empty symbol (PR#16686)
7841> a <- alist(one = 1, two = )
7842> dput(a)
7843list(one = 1, two = )
7844> ## deparsed two to quote()
7845>
7846> ## Deparsing of repeated unary operators; the first 3 were "always" ok:
7847> quote(~~x)
7848~~x
7849> quote(++x)
7850++x
7851> quote(--x)
7852--x
7853> quote(!!x) # was `!(!x)`
7854!!x
7855> quote(??x) # Suboptimal
7856`?`(`?`(x))
7857> quote(~+-!?x) # ditto: ....`?`(x)
7858~+-!`?`(x)
7859> ## `!` no longer produces parentheses now
7860>
7861>
7862> ## summary.data.frame() with NAs in columns of class "Date" -- PR#16709
7863> x <- c(18000000, 18810924, 19091227, 19027233, 19310526, 19691228, NA)
7864> x.Date <- as.Date(as.character(x), format = "%Y%m%d")
7865> summary(x.Date)
7866        Min.      1st Qu.       Median         Mean      3rd Qu.         Max.
7867"1881-09-24" "1902-12-04" "1920-09-10" "1923-04-12" "1941-01-17" "1969-12-28"
7868        NA's
7869         "3"
7870> DF.Dates <- data.frame(c1 = x.Date)
7871> summary(DF.Dates) ## NA's missing from output :
7872       c1
7873 Min.   :1881-09-24
7874 1st Qu.:1902-12-04
7875 Median :1920-09-10
7876 Mean   :1923-04-12
7877 3rd Qu.:1941-01-17
7878 Max.   :1969-12-28
7879 NA's   :3
7880> DF.Dates$x1 <- 1:7
7881> summary(DF.Dates) ## NA's still missing
7882       c1                   x1
7883 Min.   :1881-09-24   Min.   :1.0
7884 1st Qu.:1902-12-04   1st Qu.:2.5
7885 Median :1920-09-10   Median :4.0
7886 Mean   :1923-04-12   Mean   :4.0
7887 3rd Qu.:1941-01-17   3rd Qu.:5.5
7888 Max.   :1969-12-28   Max.   :7.0
7889 NA's   :3
7890> DF.Dates$x2 <- c(1:6, NA)
7891> ## now, NA's show fine:
7892> summary(DF.Dates)
7893       c1                   x1            x2
7894 Min.   :1881-09-24   Min.   :1.0   Min.   :1.00
7895 1st Qu.:1902-12-04   1st Qu.:2.5   1st Qu.:2.25
7896 Median :1920-09-10   Median :4.0   Median :3.50
7897 Mean   :1923-04-12   Mean   :4.0   Mean   :3.50
7898 3rd Qu.:1941-01-17   3rd Qu.:5.5   3rd Qu.:4.75
7899 Max.   :1969-12-28   Max.   :7.0   Max.   :6.00
7900 NA's   :3                          NA's   :1
7901> ## 2 of 4  summary(.) above did not show NA's  in R <= 3.2.3
7902>
7903>
7904> ## Printing complex matrix
7905> matrix(1i,2,13)
7906     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
7907[1,] 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i  0+1i  0+1i  0+1i  0+1i
7908[2,] 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i 0+1i  0+1i  0+1i  0+1i  0+1i
7909> ## Spacing was wrong in R <= 3.2.4
7910>
7911>
7912> E <- expression(poly = x^3 - 3 * x^2)
7913> str(E)
7914  expression(poly = x^3 - 3 * x^2)
7915> ## no longer shows "structure(...., .Names = ..)"
7916>
7917>
7918> ## summary(<logical>) working via table():
7919> logi <- c(NA, logical(3), NA, !logical(2), NA)
7920> summary(logi)
7921   Mode   FALSE    TRUE    NA's
7922logical       3       2       3
7923> summary(logi[!is.na(logi)])
7924   Mode   FALSE    TRUE
7925logical       3       2
7926> summary(TRUE)
7927   Mode    TRUE
7928logical       1
7929> ## was always showing counts for NA's even when 0 in  2.8.0 <= R <= 3.3.1
7930> ii <- as.integer(logi)
7931> summary(ii)
7932   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
7933    0.0     0.0     0.0     0.4     1.0     1.0       3
7934> summary(ii[!is.na(ii)])
7935   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
7936    0.0     0.0     0.0     0.4     1.0     1.0
7937> summary(1L)
7938   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
7939      1       1       1       1       1       1
7940>
7941>
7942> ## str.default() for "AsIs" arrays
7943> str(I(m <- matrix(pi*1:4, 2)))
7944 'AsIs' num [1:2, 1:2] 3.14 6.28 9.42 12.57
7945> ## did look ugly (because of toString() for numbers) in R <= 3.3.1
7946>
7947>
7948> ## check automatic coercions from double to integer
7949> ##
7950> ## these should work due to coercion
7951> sprintf("%d", 1)
7952[1] "1"
7953> sprintf("%d", NA_real_)
7954[1] "NA"
7955> sprintf("%d", c(1,2))
7956[1] "1" "2"
7957> sprintf("%d", c(1,NA))
7958[1] "1"  "NA"
7959> sprintf("%d", c(NA,1))
7960[1] "NA" "1"
7961> ##
7962> ## these should fail
7963> assertErrorV( sprintf("%d", 1.1) )
7964Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7965> assertErrorV( sprintf("%d", c(1.1,1)) )
7966Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7967> assertErrorV( sprintf("%d", c(1,1.1)) )
7968Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7969> assertErrorV( sprintf("%d", NaN) )
7970Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7971> assertErrorV( sprintf("%d", c(1,NaN)) )
7972Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7973>
7974>
7975> ## formatting of named raws:
7976> setNames(as.raw(1:3), c("a", "bbbb", "c"))
7977   a bbbb    c
7978  01   02   03
7979> ## was quite ugly for R <= 3.4.2
7980>
7981>
7982> ## str(x) when is.vector(x) is false :
7983> str(structure(c(a = 1, b = 2:7), color = "blue"))
7984 Named num [1:7] 1 2 3 4 5 6 7
7985 - attr(*, "names")= chr [1:7] "a" "b1" "b2" "b3" ...
7986 - attr(*, "color")= chr "blue"
7987> ## did print " atomic [1:7] ..." in R <= 3.4.x
7988>
7989>
7990> ## check stopifnot(exprs = ....)
7991> tryCatch(stopifnot(exprs = {
7992+   all.equal(pi, 3.1415927)
7993+   2 < 2
7994+   cat("Kilroy was here!\n")
7995+   all(1:10 < 12)
7996+   "a" < "b"
7997+ }), error = function(e) e$message) -> M ; cat("Error: ", M, "\n")
7998Error:  2 < 2 is not TRUE
7999>
8000> tryCatch(stopifnot(exprs = {
8001+   all.equal(pi, 3.1415927)
8002+   { cat("Kilroy was here!\n"); TRUE }
8003+   pi < 3
8004+   cat("whereas I won't be printed ...\n")
8005+   all(1:10 < 12)
8006+   "a" < "b"
8007+ }), error = function(e) e$message) -> M2 ; cat("Error: ", M2, "\n")
8008Kilroy was here!
8009Error:  pi < 3 is not TRUE
8010>
8011> stopifnot(exprs = {
8012+   all.equal(pi, 3.1415927)
8013+   { cat("\nKilroy was here! ... "); TRUE }
8014+   pi > 3
8015+   all(1:10 < 12)
8016+   "a" < "b"
8017+   { cat("and I'm printed as well ...\n"); TRUE}
8018+ })
8019
8020Kilroy was here! ... and I'm printed as well ...
8021> ## without "{ .. }" :
8022> stopifnot(exprs = 2 == 2)
8023> try(stopifnot(exprs = 1 > 2))
8024Error : 1 > 2 is not TRUE
8025> ## passing an expression object:
8026> stopifnot(exprObject = expression(2 == 2, pi < 4))
8027> tryCatch(stopifnot(exprObject = expression(
8028+                        2 == 2,
8029+                        { cat("\n Kilroy again .."); TRUE },
8030+                        pi < 4,
8031+                        0 == 1,
8032+                        { cat("\n no way..\n"); TRUE })),
8033+          error = function(e) e$message) -> M3
8034
8035 Kilroy again ..> cat("Error: ", M3, "\n")
8036Error:  0 == 1 is not TRUE
8037> ## was partly not ok for many weeks in R-devel, early 2018
8038>
8039>
8040> ## print.htest() with small 'digits'
8041> print(t.test(1:28), digits = 3)
8042
8043	One Sample t-test
8044
8045data:  1:28
8046t = 9, df = 27, p-value = 6e-10
8047alternative hypothesis: true mean is not equal to 0
804895 percent confidence interval:
8049 11.3 17.7
8050sample estimates:
8051mean of x
8052     14.5
8053
8054> ## showed 'df = 30' from signif(*, digits=1) and too many digits for CI, in R <= 3.5.1
8055>
8056>
8057> ## str(<d.frame w/ attrib>):
8058> treeA <- trees
8059> attr(treeA, "someA") <- 1:77
8060> str(treeA)
8061'data.frame':	31 obs. of  3 variables:
8062 $ Girth : num  8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
8063 $ Height: num  70 65 63 72 81 83 66 75 80 75 ...
8064 $ Volume: num  10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...
8065 - attr(*, "someA")= int [1:77] 1 2 3 4 5 6 7 8 9 10 ...
8066> ## now shows the *length* of "someA"
8067>
8068>
8069> ## summaryRprof() bug PR#15886  + "Rprof() not enabled" PR#17836
8070> if(capabilities("Rprof")) {
8071+     Rprof(tf <- tempfile("Rprof.out", tmpdir = getwd()), memory.profiling=TRUE, line.profiling=FALSE)
8072+     out <- lapply(1:10000, rnorm, n= 512)
8073+     Rprof(NULL)
8074+     if(interactive())
8075+         print(length(readLines(tf))) # ca. 10 .. 20 lines
8076+     op <- options(warn = 2) # no warnings, even !
8077+     for (cs in 1:21) s <- summaryRprof(tf, memory="tseries", chunksize=cs)
8078+     ## "always" triggered an error (or a warning) in R <= 3.6.3
8079+     options(op)
8080+     unlink(tf)
8081+ }
8082>
8083>
8084> ## printing *named* complex vectors (*not* arrays), PR#17868 (and PR#18019):
8085> a <- 1:12; (z <- a + a*1i); names(z) <- letters[seq_along(z)]; z
8086 [1]  1+ 1i  2+ 2i  3+ 3i  4+ 4i  5+ 5i  6+ 6i  7+ 7i  8+ 8i  9+ 9i 10+10i
8087[11] 11+11i 12+12i
8088     a      b      c      d      e      f      g      h      i      j      k
8089 1+ 1i  2+ 2i  3+ 3i  4+ 4i  5+ 5i  6+ 6i  7+ 7i  8+ 8i  9+ 9i 10+10i 11+11i
8090     l
809112+12i
8092> ## fixed in R-devel in July 2020;  R 4.0.3 patched on Dec 26, 2020
8093>
8094>
8095> ## identical(*) on "..." object
8096> (ddd <- (function(...) environment())(1)$...) # <...>
8097<...>
8098>  dd2 <- (function(...) environment())(1)$...
8099> stopifnot( identical(ddd, dd2) )
8100> ## In R <= 4.0.3,  printed to console (no warning, no message!):
8101> ## "Unknown Type: ... (11)"
8102>
8103>
8104> ## printCoefmat() should keep NaN values (PR#17336)
8105> ##cm <- summary(lm(c(0,0,0) ~ 1))$coefficients
8106> cm <- cbind(Estimate = 0, SE = 0, t = NaN, "Pr(>|t|)" = NaN)
8107> printCoefmat(cm)  # NaN's were replaced by NA in R < 4.1.0
8108     Estimate SE   t Pr(>|t|)
8109[1,]        0  0 NaN      NaN
8110>
8111