1
2R version 4.1.0 Patched (2021-06-24 r80564) -- "Camp Pontanezen"
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
1625> RNGkind(normal.kind = "Kinderman-Ramage")
1626> set.seed(123)
1627> RNGkind()
1628[1] "Knuth-TAOCP-2002" "Kinderman-Ramage" "Rejection"
1629> rnorm(4)
1630[1] -1.9699090 -2.2429340  0.5339321  0.2097153
1631> RNGkind(normal.kind = "Ahrens-Dieter")
1632> set.seed(123)
1633> RNGkind()
1634[1] "Knuth-TAOCP-2002" "Ahrens-Dieter"    "Rejection"
1635> rnorm(4)
1636[1]  0.06267229  0.12421568 -1.86653499 -0.14535921
1637> RNGkind(normal.kind = "Box-Muller")
1638> set.seed(123)
1639> RNGkind()
1640[1] "Knuth-TAOCP-2002" "Box-Muller"       "Rejection"
1641> rnorm(4)
1642[1]  2.26160990  0.59010303  0.30176045 -0.01346139
1643> set.seed(123)
1644> runif(4)
1645[1] 0.04062130 0.06511825 0.99290488 0.95540467
1646> set.seed(123, "default")
1647> set.seed(123, "Marsaglia-Multicarry") ## Careful, not the default anymore
1648> runif(4)
1649[1] 0.1200427 0.1991600 0.7292821 0.8115922
1650> ## last set.seed failed < 1.5.0.
1651>
1652>
1653> ## merging, ggrothendieck@yifan.net, 2002-03-16
1654> d.df <- data.frame(x = 1:3, y = c("A","D","E"), z = c(6,9,10))
1655> merge(d.df[1,], d.df)
1656  x y z
16571 1 A 6
1658> ## 1.4.1 got confused by inconsistencies in as.character
1659>
1660>
1661> ## PR#1394 (levels<-.factor)
1662> f <- factor(c("a","b"))
1663> levels(f) <- list(C="C", A="a", B="b")
1664> f
1665[1] A B
1666Levels: C A B
1667> ## was  [1] C A; Levels:  C A  in 1.4.1
1668>
1669>
1670> ## NA levels in factors
1671> (x <- factor(c("a", "NA", "b"), exclude=NULL))
1672[1] a  NA b
1673Levels: NA a b
1674> ## 1.4.1 had wrong order for levels
1675> is.na(x)[3] <- TRUE
1676> x
1677[1] a    NA   <NA>
1678Levels: NA a b
1679> ## missing entry prints as <NA>
1680>
1681>
1682> ## printing/formatting NA strings
1683> (x <- c("a", "NA", NA, "b"))
1684[1] "a"  "NA" NA   "b"
1685> print(x, quote = FALSE)
1686[1] a    NA   <NA> b
1687> paste(x)
1688[1] "a"  "NA" "NA" "b"
1689> format(x)
1690[1] "a " "NA" "NA" "b "
1691> format(x, justify = "right")
1692[1] " a" "NA" "NA" " b"
1693> format(x, justify = "none")
1694[1] "a"  "NA" "NA" "b"
1695> ## not ideal.
1696>
1697>
1698> ## print.ts problems  ggrothendieck@yifan.net on R-help, 2002-04-01
1699> x <- 1:20
1700> tt1 <- ts(x,start=c(1960,2), freq=12)
1701> tt2 <- ts(10+x,start=c(1960,2), freq=12)
1702> cbind(tt1, tt2)
1703         tt1 tt2
1704Feb 1960   1  11
1705Mar 1960   2  12
1706Apr 1960   3  13
1707May 1960   4  14
1708Jun 1960   5  15
1709Jul 1960   6  16
1710Aug 1960   7  17
1711Sep 1960   8  18
1712Oct 1960   9  19
1713Nov 1960  10  20
1714Dec 1960  11  21
1715Jan 1961  12  22
1716Feb 1961  13  23
1717Mar 1961  14  24
1718Apr 1961  15  25
1719May 1961  16  26
1720Jun 1961  17  27
1721Jul 1961  18  28
1722Aug 1961  19  29
1723Sep 1961  20  30
1724> ## 1.4.1 had `Jan 1961' as `NA 1961'
1725> ## ...and 1.9.1 had it as `Jan 1960'!!
1726>
1727> ## glm boundary bugs (related to PR#1331)
1728> x <- c(0.35, 0.64, 0.12, 1.66, 1.52, 0.23, -1.99, 0.42, 1.86, -0.02,
1729+        -1.64, -0.46, -0.1, 1.25, 0.37, 0.31, 1.11, 1.65, 0.33, 0.89,
1730+        -0.25, -0.87, -0.22, 0.71, -2.26, 0.77, -0.05, 0.32, -0.64, 0.39,
1731+        0.19, -1.62, 0.37, 0.02, 0.97, -2.62, 0.15, 1.55, -1.41, -2.35,
1732+        -0.43, 0.57, -0.66, -0.08, 0.02, 0.24, -0.33, -0.03, -1.13, 0.32,
1733+        1.55, 2.13, -0.1, -0.32, -0.67, 1.44, 0.04, -1.1, -0.95, -0.19,
1734+        -0.68, -0.43, -0.84, 0.69, -0.65, 0.71, 0.19, 0.45, 0.45, -1.19,
1735+        1.3, 0.14, -0.36, -0.5, -0.47, -1.31, -1.02, 1.17, 1.51, -0.33,
1736+        -0.01, -0.59, -0.28, -0.18, -1.07, 0.66, -0.71, 1.88, -0.14,
1737+        -0.19, 0.84, 0.44, 1.33, -0.2, -0.45, 1.46, 1, -1.02, 0.68, 0.84)
1738> y <- c(1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0,
1739+        0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1,
1740+        1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1741+        0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
1742+        1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0)
1743> try(glm(y ~ x, family = poisson(identity)))
1744Error : no valid set of coefficients has been found: please supply starting values
1745In addition: Warning message:
1746In log(y/mu) : NaNs produced
1747> ## failed because start = NULL in 1.4.1
1748> ## now gives useful error message
1749> glm(y ~ x, family = poisson(identity), start = c(1,0))
1750
1751Call:  glm(formula = y ~ x, family = poisson(identity), start = c(1,
1752    0))
1753
1754Coefficients:
1755(Intercept)            x
1756     0.5114       0.1690
1757
1758Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
1759Null Deviance:	    68.01
1760Residual Deviance: 60.66 	AIC: 168.7
1761Warning messages:
17621: step size truncated: out of bounds
17632: step size truncated: out of bounds
1764> ## step reduction failed in 1.4.1
1765> set.seed(123)
1766> y <- rpois(100, pmax(3*x, 0))
1767> glm(y ~ x, family = poisson(identity), start = c(1,0))
1768
1769Call:  glm(formula = y ~ x, family = poisson(identity), start = c(1,
1770    0))
1771
1772Coefficients:
1773(Intercept)            x
1774     1.1561       0.4413
1775
1776Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
1777Null Deviance:	    317.2
1778Residual Deviance: 228.5 	AIC: 344.7
1779There were 27 warnings (use warnings() to see them)
1780> warnings()
1781Warning messages:
17821: step size truncated: out of bounds
17832: step size truncated: out of bounds
17843: step size truncated: out of bounds
17854: step size truncated: out of bounds
17865: step size truncated: out of bounds
17876: step size truncated: out of bounds
17887: step size truncated: out of bounds
17898: step size truncated: out of bounds
17909: step size truncated: out of bounds
179110: step size truncated: out of bounds
179211: step size truncated: out of bounds
179312: step size truncated: out of bounds
179413: step size truncated: out of bounds
179514: step size truncated: out of bounds
179615: step size truncated: out of bounds
179716: step size truncated: out of bounds
179817: step size truncated: out of bounds
179918: step size truncated: out of bounds
180019: step size truncated: out of bounds
180120: step size truncated: out of bounds
180221: step size truncated: out of bounds
180322: step size truncated: out of bounds
180423: step size truncated: out of bounds
180524: step size truncated: out of bounds
180625: step size truncated: out of bounds
180726: glm.fit: algorithm did not converge
180827: glm.fit: algorithm stopped at boundary value
1809>
1810>
1811> ## extending char arrrays
1812> x <- y <- LETTERS[1:2]
1813> x[5] <- "C"
1814> length(y) <- 5
1815> x
1816[1] "A" "B" NA  NA  "C"
1817> y
1818[1] "A" "B" NA  NA  NA
1819> ## x was filled with "", y with NA in 1.5.0
1820>
1821>
1822> ## formula with no intercept, 2002-07-22
1823> oldcon <- options(contrasts = c("contr.helmert", "contr.poly"))
1824> U <- gl(3, 6, 18, labels=letters[1:3])
1825> V <- gl(3, 2, 18, labels=letters[1:3])
1826> A <- rep(c(0, 1), 9)
1827> B <- rep(c(1, 0), 9)
1828> set.seed(1); y <- rnorm(18)
1829> terms(y ~ A:U + A:V - 1)
1830y ~ A:U + A:V - 1
1831attr(,"variables")
1832list(y, A, U, V)
1833attr(,"factors")
1834  A:U A:V
1835y   0   0
1836A   2   2
1837U   2   0
1838V   0   1
1839attr(,"term.labels")
1840[1] "A:U" "A:V"
1841attr(,"order")
1842[1] 2 2
1843attr(,"intercept")
1844[1] 0
1845attr(,"response")
1846[1] 1
1847attr(,".Environment")
1848<environment: R_GlobalEnv>
1849> lm(y ~ A:U + A:V - 1)$coefficients  # 1.5.1 used dummies coding for V
1850       A:Ua        A:Ub        A:Uc        A:V1        A:V2
1851 0.25303884 -0.21875499 -0.71708528 -0.61467193 -0.09030436
1852> lm(y ~ (A + B) : (U + V) - 1) # 1.5.1 used dummies coding for A:V but not B:V
1853
1854Call:
1855lm(formula = y ~ (A + B):(U + V) - 1)
1856
1857Coefficients:
1858   A:Ua     A:Ub     A:Uc     A:V1     A:V2     B:Ua     B:Ub     B:Uc
1859 0.2530  -0.2188  -0.7171  -0.6147  -0.0903   1.7428   0.0613   0.7649
1860   B:V1     B:V2
1861-0.4420   0.5388
1862
1863> options(oldcon)
1864> ## 1.5.1 miscomputed the first factor in the formula.
1865>
1866>
1867> ## quantile extremes, MM 13 Apr 2000 and PR#1852
1868> (qq <- sapply(0:5, function(k) {
1869+     x <- c(rep(-Inf,k+1), 0:k, rep(Inf, k))
1870+     sapply(1:9, function(typ)
1871+            quantile(x, pr=(2:10)/10, type=typ))
1872+ }, simplify="array"))
1873, , 1
1874
1875     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
187620%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
187730%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
187840%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
187950%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
188060%     0    0 -Inf -Inf -Inf -Inf -Inf -Inf -Inf
188170%     0    0 -Inf -Inf -Inf    0 -Inf -Inf -Inf
188280%     0    0    0 -Inf    0    0 -Inf    0    0
188390%     0    0    0 -Inf    0    0 -Inf    0    0
1884100%    0    0    0    0    0    0    0    0    0
1885
1886, , 2
1887
1888     [,1] [,2] [,3] [,4] [,5] [,6] [,7]      [,8]  [,9]
188920%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
189030%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
189140%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
189250%     0  0.0 -Inf -Inf  0.0  0.0  0.0 0.0000000 0.000
189360%     0  0.5    0  0.0  0.5  0.6  0.4 0.5333333 0.525
189470%     1  1.0    1  0.5  1.0  Inf  0.8       Inf   Inf
189580%     1  Inf    1  1.0  Inf  Inf  Inf       Inf   Inf
189690%   Inf  Inf    1  Inf  Inf  Inf  Inf       Inf   Inf
1897100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
1898
1899, , 3
1900
1901     [,1] [,2] [,3] [,4] [,5] [,6] [,7]     [,8]  [,9]
190220%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
190330%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
190440%     0  0.0 -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
190550%     0  0.5    0  0.0  0.5  0.5  0.5 0.500000 0.500
190660%     1  1.0    1  0.8  1.3  1.4  1.2 1.333333 1.325
190770%     2  2.0    2  1.6  Inf  Inf  1.9      Inf   Inf
190880%   Inf  Inf    2  Inf  Inf  Inf  Inf      Inf   Inf
190990%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1910100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1911
1912, , 4
1913
1914     [,1] [,2] [,3] [,4] [,5] [,6] [,7]     [,8]  [,9]
191520%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
191630%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
191740%     0    0 -Inf -Inf -Inf -Inf    0     -Inf  -Inf
191850%     1    1    1  0.5  1.0  1.0    1 1.000000 1.000
191960%     2    2    2  1.6  2.1  2.2    2 2.133333 2.125
192070%     3    3    3  2.7  Inf  Inf    3      Inf   Inf
192180%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
192290%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1923100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
1924
1925, , 5
1926
1927     [,1] [,2] [,3] [,4] [,5] [,6] [,7]       [,8]  [,9]
192820%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf       -Inf  -Inf
192930%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf       -Inf  -Inf
193040%     0  0.0    0 -Inf  0.1  0.0  0.2 0.06666667 0.075
193150%     1  1.5    1  1.0  1.5  1.5  1.5 1.50000000 1.500
193260%     3  3.0    2  2.4  2.9  3.0  2.8 2.93333333 2.925
193370%     4  4.0    4  3.8  Inf  Inf  Inf        Inf   Inf
193480%   Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
193590%   Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
1936100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
1937
1938, , 6
1939
1940     [,1] [,2] [,3] [,4] [,5] [,6] [,7]      [,8]  [,9]
194120%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
194230%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
194340%     0    0    0 -Inf  0.3  0.2  0.4 0.2666667 0.275
194450%     2    2    1  1.5  2.0  2.0  2.0 2.0000000 2.000
194560%     4    4    3  3.2  3.7  3.8  3.6 3.7333333 3.725
194670%     5    5    5  4.9  Inf  Inf  Inf       Inf   Inf
194780%   Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
194890%   Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
1949100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
1950
1951> x <- c(-Inf, -Inf, Inf, Inf)
1952> median(x)
1953[1] NaN
1954> quantile(x)
1955  0%  25%  50%  75% 100%
1956-Inf -Inf  NaN  Inf  Inf
1957> ## 1.5.1 had -Inf not NaN in several places
1958>
1959>
1960> ## NAs in matrix dimnames
1961> z <- matrix(1:9, 3, 3)
1962> dimnames(z) <- list(c("x", "y", NA), c(1, NA, 3))
1963> z
1964     1 <NA> 3
1965x    1    4 7
1966y    2    5 8
1967<NA> 3    6 9
1968> ## NAs in dimnames misaligned when printing in 1.5.1
1969>
1970>
1971> ## weighted aov (PR#1930)
1972> r <- c(10,23,23,26,17,5,53,55,32,46,10,8,10,8,23,0,3,22,15,32,3)
1973> n <- c(39,62,81,51,39,6,74,72,51,79,13,16,30,28,45,4,12,41,30,51,7)
1974> trt <- factor(rep(1:4,c(5,6,5,5)))
1975> Y <- r/n
1976> z <- aov(Y ~ trt, weights=n)
1977> ## 1.5.1 gave unweighted RSS
1978>
1979>
1980> ## rbind (PR#2266)
1981> test <- as.data.frame(matrix(1:25, 5, 5))
1982> test1 <- matrix(-(1:10), 2, 5)
1983> rbind(test, test1)
1984  V1 V2 V3 V4  V5
19851  1  6 11 16  21
19862  2  7 12 17  22
19873  3  8 13 18  23
19884  4  9 14 19  24
19895  5 10 15 20  25
19906 -1 -3 -5 -7  -9
19917 -2 -4 -6 -8 -10
1992> rbind(test1, test)
1993  V1 V2 V3 V4  V5
19941 -1 -3 -5 -7  -9
19952 -2 -4 -6 -8 -10
19963  1  6 11 16  21
19974  2  7 12 17  22
19985  3  8 13 18  23
19996  4  9 14 19  24
20007  5 10 15 20  25
2001> ## 1.6.1 treated matrix as a vector.
2002>
2003>
2004> ## escapes in non-quoted printing
2005> x <- "\\abc\\"
2006> names(x) <- 1
2007> x
2008        1
2009"\\abc\\"
2010> print(x, quote=FALSE)
2011      1
2012\\abc\\
2013> ## 1.6.2 had label misaligned
2014>
2015>
2016> ## summary on data frames containing data frames (PR#1891)
2017> x <- data.frame(1:10)
2018> x$z <- data.frame(x=1:10,yyy=11:20)
2019> summary(x)
2020     X1.10             z.x             z.yyy
2021 Min.   : 1.00   Min.   : 1.00    Min.   :11.00
2022 1st Qu.: 3.25   1st Qu.: 3.25    1st Qu.:13.25
2023 Median : 5.50   Median : 5.50    Median :15.50
2024 Mean   : 5.50   Mean   : 5.50    Mean   :15.50
2025 3rd Qu.: 7.75   3rd Qu.: 7.75    3rd Qu.:17.75
2026 Max.   :10.00   Max.   :10.00    Max.   :20.00
2027> ## 1.6.2 had NULL labels on output with z columns stacked.
2028>
2029>
2030> ## re-orderings in terms.formula (PR#2206)
2031> form <- formula(y ~ a + b:c + d + e + e:d)
2032> (tt <- terms(form))
2033y ~ a + b:c + d + e + e:d
2034attr(,"variables")
2035list(y, a, b, c, d, e)
2036attr(,"factors")
2037  a d e b:c d:e
2038y 0 0 0   0   0
2039a 1 0 0   0   0
2040b 0 0 0   2   0
2041c 0 0 0   2   0
2042d 0 1 0   0   1
2043e 0 0 1   0   1
2044attr(,"term.labels")
2045[1] "a"   "d"   "e"   "b:c" "d:e"
2046attr(,"order")
2047[1] 1 1 1 2 2
2048attr(,"intercept")
2049[1] 1
2050attr(,"response")
2051[1] 1
2052attr(,".Environment")
2053<environment: R_GlobalEnv>
2054> (tt2 <- terms(formula(tt)))
2055y ~ a + b:c + d + e + e:d
2056attr(,"variables")
2057list(y, a, b, c, d, e)
2058attr(,"factors")
2059  a d e b:c d:e
2060y 0 0 0   0   0
2061a 1 0 0   0   0
2062b 0 0 0   2   0
2063c 0 0 0   2   0
2064d 0 1 0   0   1
2065e 0 0 1   0   1
2066attr(,"term.labels")
2067[1] "a"   "d"   "e"   "b:c" "d:e"
2068attr(,"order")
2069[1] 1 1 1 2 2
2070attr(,"intercept")
2071[1] 1
2072attr(,"response")
2073[1] 1
2074attr(,".Environment")
2075<environment: R_GlobalEnv>
2076> stopifnot(identical(tt, tt2))
2077> terms(delete.response(tt))
2078~a + b:c + d + e + e:d
2079attr(,"variables")
2080list(a, b, c, d, e)
2081attr(,"factors")
2082  a d e b:c d:e
2083a 1 0 0   0   0
2084b 0 0 0   2   0
2085c 0 0 0   2   0
2086d 0 1 0   0   1
2087e 0 0 1   0   1
2088attr(,"term.labels")
2089[1] "a"   "d"   "e"   "b:c" "d:e"
2090attr(,"order")
2091[1] 1 1 1 2 2
2092attr(,"intercept")
2093[1] 1
2094attr(,"response")
2095[1] 0
2096attr(,".Environment")
2097<environment: R_GlobalEnv>
2098> ## both tt and tt2 re-ordered the formula < 1.7.0
2099> ## now try with a dot
2100> terms(breaks ~ ., data = warpbreaks)
2101breaks ~ wool + tension
2102attr(,"variables")
2103list(breaks, wool, tension)
2104attr(,"factors")
2105        wool tension
2106breaks     0       0
2107wool       1       0
2108tension    0       1
2109attr(,"term.labels")
2110[1] "wool"    "tension"
2111attr(,"order")
2112[1] 1 1
2113attr(,"intercept")
2114[1] 1
2115attr(,"response")
2116[1] 1
2117attr(,".Environment")
2118<environment: R_GlobalEnv>
2119> terms(breaks ~ . - tension, data = warpbreaks)
2120breaks ~ (wool + tension) - tension
2121attr(,"variables")
2122list(breaks, wool, tension)
2123attr(,"factors")
2124        wool
2125breaks     0
2126wool       1
2127tension    0
2128attr(,"term.labels")
2129[1] "wool"
2130attr(,"order")
2131[1] 1
2132attr(,"intercept")
2133[1] 1
2134attr(,"response")
2135[1] 1
2136attr(,".Environment")
2137<environment: R_GlobalEnv>
2138> terms(breaks ~ . - tension, data = warpbreaks, simplify = TRUE)
2139breaks ~ wool
2140attr(,"variables")
2141list(breaks, wool, tension)
2142attr(,"factors")
2143        wool
2144breaks     0
2145wool       1
2146tension    0
2147attr(,"term.labels")
2148[1] "wool"
2149attr(,"order")
2150[1] 1
2151attr(,"intercept")
2152[1] 1
2153attr(,"response")
2154[1] 1
2155attr(,".Environment")
2156<environment: R_GlobalEnv>
2157> terms(breaks ~ . ^2, data = warpbreaks)
2158breaks ~ (wool + tension)^2
2159attr(,"variables")
2160list(breaks, wool, tension)
2161attr(,"factors")
2162        wool tension wool:tension
2163breaks     0       0            0
2164wool       1       0            1
2165tension    0       1            1
2166attr(,"term.labels")
2167[1] "wool"         "tension"      "wool:tension"
2168attr(,"order")
2169[1] 1 1 2
2170attr(,"intercept")
2171[1] 1
2172attr(,"response")
2173[1] 1
2174attr(,".Environment")
2175<environment: R_GlobalEnv>
2176> terms(breaks ~ . ^2, data = warpbreaks, simplify = TRUE)
2177breaks ~ wool + tension + wool:tension
2178attr(,"variables")
2179list(breaks, wool, tension)
2180attr(,"factors")
2181        wool tension wool:tension
2182breaks     0       0            0
2183wool       1       0            1
2184tension    0       1            1
2185attr(,"term.labels")
2186[1] "wool"         "tension"      "wool:tension"
2187attr(,"order")
2188[1] 1 1 2
2189attr(,"intercept")
2190[1] 1
2191attr(,"response")
2192[1] 1
2193attr(,".Environment")
2194<environment: R_GlobalEnv>
2195> ## 1.6.2 expanded these formulae out as in simplify = TRUE
2196>
2197>
2198> ## printing attributes (PR#2506)
2199> (x <- structure(1:4, other=as.factor(LETTERS[1:3])))
2200[1] 1 2 3 4
2201attr(,"other")
2202[1] A B C
2203Levels: A B C
2204> ## < 1.7.0 printed the codes of the factor attribute
2205>
2206>
2207> ## add logical matrix replacement indexing for data frames
2208> TEMP <- data.frame(VAR1=c(1,2,3,4,5), VAR2=c(5,4,3,2,1), VAR3=c(1,1,1,1,NA))
2209> TEMP[,c(1,3)][TEMP[,c(1,3)]==1 & !is.na(TEMP[,c(1,3)])] < -10
2210[1] FALSE FALSE FALSE FALSE FALSE
2211> TEMP
2212  VAR1 VAR2 VAR3
22131    1    5    1
22142    2    4    1
22153    3    3    1
22164    4    2    1
22175    5    1   NA
2218> ##
2219>
2220> ## moved from reg-plot.R as exact output depends on rounding error
2221> ## PR 390 (axis for small ranges)
2222>
2223> relrange <- function(x) {
2224+     ## The relative range in EPS units
2225+     r <- range(x)
2226+     diff(r)/max(abs(r))/.Machine$double.eps
2227+ }
2228>
2229> x <- c(0.12345678912345678,
2230+        0.12345678912345679,
2231+        0.12345678912345676)
2232> # relrange(x) ## 1.0125, but depends on strtod
2233> plot(x) # `extra horizontal' ;  +- ok on Solaris; label off on Linux
2234>
2235> y <- c(0.9999563255363383973418,
2236+        0.9999563255363389524533,
2237+        0.9999563255363382863194)
2238> ## The relative range number:
2239> # relrange(y) ## 3.000131, but depends on strtod
2240> plot(y)# once gave infinite loop on Solaris [TL];  y-axis too long
2241>
2242> ## Comments: The whole issue was finally deferred to main/graphics.c l.1944
2243> ##    error("relative range of values is too small to compute accurately");
2244> ## which is not okay.
2245>
2246> set.seed(101)
2247> par(mfrow = c(3,3))
2248> for(j.fac in 1e-12* c(10, 1, .7, .3, .2, .1, .05, .03, .01)) {
2249+ ##           ====
2250+     #set.seed(101) # or don't
2251+     x <- pi + jitter(numeric(101), f = j.fac)
2252+     rrtxt <- paste("rel.range =", formatC(relrange(x), dig = 4),"* EPS")
2253+     cat("j.f = ", format(j.fac)," ;  ", rrtxt,"\n",sep="")
2254+     plot(x, type = "l", main = rrtxt)
2255+     cat("par(\"usr\")[3:4]:", formatC(par("usr")[3:4], wid = 10),"\n",
2256+         "par(\"yaxp\") :   ", formatC(par("yaxp"), wid = 10),"\n\n", sep="")
2257+ }
2258j.f = 1e-11 ;  rel.range = 553.9 * EPS
2259par("usr")[3:4]:     3.142     3.142
2260par("yaxp") :        3.142     3.142         3
2261
2262j.f = 1e-12 ;  rel.range = 56.02 * EPS
2263par("usr")[3:4]:     3.142     3.142
2264par("yaxp") :        3.142     3.142         1
2265
2266j.f = 7e-13 ;  rel.range = 39.47 * EPS
2267par("usr")[3:4]:     3.142     3.142
2268par("yaxp") :        3.142     3.142         1
2269
2270j.f = 3e-13 ;  rel.range = 16.55 * EPS
2271par("usr")[3:4]:     3.142     3.142
2272par("yaxp") :        3.142     3.142         1
2273
2274j.f = 2e-13 ;  rel.range = 11.46 * EPS
2275par("usr")[3:4]:     3.108     3.176
2276par("yaxp") :         3.11      3.17         6
2277
2278j.f = 1e-13 ;  rel.range = 5.093 * EPS
2279par("usr")[3:4]:     3.108     3.176
2280par("yaxp") :         3.11      3.17         6
2281
2282j.f = 5e-14 ;  rel.range = 2.546 * EPS
2283par("usr")[3:4]:     3.108     3.176
2284par("yaxp") :         3.11      3.17         6
2285
2286j.f = 3e-14 ;  rel.range = 1.273 * EPS
2287par("usr")[3:4]:     3.108     3.176
2288par("yaxp") :         3.11      3.17         6
2289
2290j.f = 1e-14 ;  rel.range =     0 * EPS
2291par("usr")[3:4]:     1.784     4.499
2292par("yaxp") :            2         4         4
2293
2294Warning messages:
22951: In plot.window(...) :
2296  relative range of values (  43 * EPS) is small (axis 2)
22972: In plot.window(...) :
2298  relative range of values (  36 * EPS) is small (axis 2)
22993: In plot.window(...) :
2300  relative range of values (   0 * EPS) is small (axis 2)
2301> par(mfrow = c(1,1))
2302> ## The warnings from inside GScale() will differ in their  relrange() ...
2303> ## >> do sloppy testing
2304> ## 2003-02-03 hopefully no more.  BDR
2305> ## end of PR 390
2306>
2307>
2308> ## scoping rules calling step inside a function
2309> "cement" <-
2310+     structure(list(x1 = c(7, 1, 11, 11, 7, 11, 3, 1, 2, 21, 1, 11, 10),
2311+                    x2 = c(26, 29, 56, 31, 52, 55, 71, 31, 54, 47, 40, 66, 68),
2312+                    x3 = c(6, 15, 8, 8, 6, 9, 17, 22, 18, 4, 23, 9, 8),
2313+                    x4 = c(60, 52, 20, 47, 33, 22, 6, 44, 22, 26, 34, 12, 12),
2314+                    y = c(78.5, 74.3, 104.3, 87.6, 95.9, 109.2, 102.7, 72.5,
2315+                    93.1, 115.9, 83.8, 113.3, 109.4)),
2316+               .Names = c("x1", "x2", "x3", "x4", "y"), class = "data.frame",
2317+               row.names = 1:13)
2318> teststep <- function(formula, data)
2319+ {
2320+     d2 <- data
2321+     fit <- lm(formula, data=d2)
2322+     step(fit)
2323+ }
2324> teststep(formula(y ~ .), cement)
2325Start:  AIC=26.94
2326y ~ x1 + x2 + x3 + x4
2327
2328       Df Sum of Sq    RSS    AIC
2329- x3    1    0.1091 47.973 24.974
2330- x4    1    0.2470 48.111 25.011
2331- x2    1    2.9725 50.836 25.728
2332<none>              47.864 26.944
2333- x1    1   25.9509 73.815 30.576
2334
2335Step:  AIC=24.97
2336y ~ x1 + x2 + x4
2337
2338       Df Sum of Sq    RSS    AIC
2339<none>               47.97 24.974
2340- x4    1      9.93  57.90 25.420
2341- x2    1     26.79  74.76 28.742
2342- x1    1    820.91 868.88 60.629
2343
2344Call:
2345lm(formula = y ~ x1 + x2 + x4, data = d2)
2346
2347Coefficients:
2348(Intercept)           x1           x2           x4
2349    71.6483       1.4519       0.4161      -0.2365
2350
2351> ## failed in 1.6.2
2352>
2353> str(array(1))# not a scalar
2354 num [1(1d)] 1
2355>
2356>
2357> ## na.print="" shouldn't apply to (dim)names!
2358> (tf <- table(ff <- factor(c(1:2,NA,2), exclude=NULL)))
2359
2360   1    2 <NA>
2361   1    2    1
2362> identical(levels(ff), dimnames(tf)[[1]])
2363[1] TRUE
2364> str(levels(ff))
2365 chr [1:3] "1" "2" NA
2366> ## not quite ok previous to 1.7.0
2367>
2368>
2369> ## PR#3058  printing with na.print and right=TRUE
2370> a <- matrix( c(NA, "a", "b", "10",
2371+                NA, NA,  "d", "12",
2372+                NA, NA,  NA,  "14"),
2373+             byrow=T, ncol=4 )
2374> print(a, right=TRUE, na.print=" ")
2375     [,1] [,2] [,3] [,4]
2376[1,]       "a"  "b" "10"
2377[2,]            "d" "12"
2378[3,]                "14"
2379> print(a, right=TRUE, na.print="----")
2380     [,1] [,2] [,3] [,4]
2381[1,] ----  "a"  "b" "10"
2382[2,] ---- ----  "d" "12"
2383[3,] ---- ---- ---- "14"
2384> ## misaligned in 1.7.0
2385>
2386>
2387> ## assigning factors to dimnames
2388> A <- matrix(1:4, 2)
2389> aa <- factor(letters[1:2])
2390> dimnames(A) <- list(aa, NULL)
2391> A
2392  [,1] [,2]
2393a    1    3
2394b    2    4
2395> dimnames(A)
2396[[1]]
2397[1] "a" "b"
2398
2399[[2]]
2400NULL
2401
2402> ## 1.7.0 gave internal codes as display and dimnames()
2403> ## 1.7.1beta gave NAs via dimnames()
2404> ## 1.8.0 converts factors to character
2405>
2406>
2407> ## wishlist PR#2776: aliased coefs in lm/glm
2408> set.seed(123)
2409> x2 <- x1 <- 1:10
2410> x3 <- 0.1*(1:10)^2
2411> y <- x1 + rnorm(10)
2412> (fit <- lm(y ~ x1 + x2 + x3))
2413
2414Call:
2415lm(formula = y ~ x1 + x2 + x3)
2416
2417Coefficients:
2418(Intercept)           x1           x2           x3
2419     1.4719       0.5867           NA       0.2587
2420
2421> summary(fit, cor = TRUE)
2422
2423Call:
2424lm(formula = y ~ x1 + x2 + x3)
2425
2426Residuals:
2427    Min      1Q  Median      3Q     Max
2428-1.0572 -0.4836  0.0799  0.4424  1.2699
2429
2430Coefficients: (1 not defined because of singularities)
2431            Estimate Std. Error t value Pr(>|t|)
2432(Intercept)   1.4719     0.9484   1.552    0.165
2433x1            0.5867     0.3961   1.481    0.182
2434x2                NA         NA      NA       NA
2435x3            0.2587     0.3509   0.737    0.485
2436
2437Residual standard error: 0.8063 on 7 degrees of freedom
2438Multiple R-squared:  0.9326,	Adjusted R-squared:  0.9134
2439F-statistic: 48.43 on 2 and 7 DF,  p-value: 7.946e-05
2440
2441Correlation of Coefficients:
2442   (Intercept) x1
2443x1 -0.91
2444x3  0.81       -0.97
2445
2446> (fit <- glm(y ~ x1 + x2 + x3))
2447
2448Call:  glm(formula = y ~ x1 + x2 + x3)
2449
2450Coefficients:
2451(Intercept)           x1           x2           x3
2452     1.4719       0.5867           NA       0.2587
2453
2454Degrees of Freedom: 9 Total (i.e. Null);  7 Residual
2455Null Deviance:	    67.53
2456Residual Deviance: 4.551 	AIC: 28.51
2457> summary(fit, cor = TRUE)
2458
2459Call:
2460glm(formula = y ~ x1 + x2 + x3)
2461
2462Deviance Residuals:
2463    Min       1Q   Median       3Q      Max
2464-1.0572  -0.4836   0.0799   0.4424   1.2699
2465
2466Coefficients: (1 not defined because of singularities)
2467            Estimate Std. Error t value Pr(>|t|)
2468(Intercept)   1.4719     0.9484   1.552    0.165
2469x1            0.5867     0.3961   1.481    0.182
2470x2                NA         NA      NA       NA
2471x3            0.2587     0.3509   0.737    0.485
2472
2473(Dispersion parameter for gaussian family taken to be 0.6501753)
2474
2475    Null deviance: 67.5316  on 9  degrees of freedom
2476Residual deviance:  4.5512  on 7  degrees of freedom
2477AIC: 28.507
2478
2479Number of Fisher Scoring iterations: 2
2480
2481Correlation of Coefficients:
2482   (Intercept) x1
2483x1 -0.91
2484x3  0.81       -0.97
2485
2486> ## omitted silently in summary.glm < 1.8.0
2487>
2488>
2489> ## list-like indexing of data frames with drop specified
2490> women["height"]
2491   height
24921      58
24932      59
24943      60
24954      61
24965      62
24976      63
24987      64
24998      65
25009      66
250110     67
250211     68
250312     69
250413     70
250514     71
250615     72
2507> women["height", drop = FALSE]  # same with a warning
2508   height
25091      58
25102      59
25113      60
25124      61
25135      62
25146      63
25157      64
25168      65
25179      66
251810     67
251911     68
252012     69
252113     70
252214     71
252315     72
2524Warning message:
2525In `[.data.frame`(women, "height", drop = FALSE) :
2526  'drop' argument will be ignored
2527> women["height", drop = TRUE]   # ditto
2528   height
25291      58
25302      59
25313      60
25324      61
25335      62
25346      63
25357      64
25368      65
25379      66
253810     67
253911     68
254012     69
254113     70
254214     71
254315     72
2544Warning message:
2545In `[.data.frame`(women, "height", drop = TRUE) :
2546  'drop' argument will be ignored
2547> women[,"height", drop = FALSE] # no warning
2548   height
25491      58
25502      59
25513      60
25524      61
25535      62
25546      63
25557      64
25568      65
25579      66
255810     67
255911     68
256012     69
256113     70
256214     71
256315     72
2564> women[,"height", drop = TRUE]  # a vector
2565 [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
2566> ## second and third were interpreted as women["height", , drop] in 1.7.x
2567>
2568>
2569> ## make.names
2570> make.names("")
2571[1] "X"
2572> make.names(".aa")
2573[1] ".aa"
2574> ## was "X.aa" in 1.7.1
2575> make.names(".2")
2576[1] "X.2"
2577> make.names(".2a") # not valid in R
2578[1] "X.2a"
2579> make.names(as.character(NA))
2580[1] "NA."
2581> ##
2582>
2583>
2584> ## strange names in data frames
2585> as.data.frame(list(row.names=17))  # 0 rows in 1.7.1
2586  row.names
25871        17
2588> aa <- data.frame(aa=1:3)
2589> aa[["row.names"]] <- 4:6
2590> aa # fine in 1.7.1
2591  aa row.names
25921  1         4
25932  2         5
25943  3         6
2595> A <- matrix(4:9, 3, 2)
2596> colnames(A) <- letters[1:2]
2597> aa[["row.names"]] <- A
2598> aa
2599  aa row.names.a row.names.b
26001  1           4           7
26012  2           5           8
26023  3           6           9
2603> ## wrong printed names in 1.7.1
2604>
2605> ## assigning to NULL --- now consistently behaves as if assigning to list() !
2606> a <- NULL
2607> a[["a"]] <- 1
2608> a
2609$a
2610[1] 1
2611
2612> a <- NULL
2613> a[["a"]] <- "something"
2614> a
2615$a
2616[1] "something"
2617
2618> a <- NULL
2619> a[["a"]] <- 1:3
2620> a
2621$a
2622[1] 1 2 3
2623
2624> ## Last was an error in 1.7.1
2625>
2626>
2627> ## examples of 0-rank models, some empty, some rank-deficient
2628> y <- rnorm(10)
2629> x <- rep(0, 10)
2630> (fit <- lm(y ~ 0))
2631
2632Call:
2633lm(formula = y ~ 0)
2634
2635No coefficients
2636
2637> summary(fit)
2638
2639Call:
2640lm(formula = y ~ 0)
2641
2642Residuals:
2643     Min       1Q   Median       3Q      Max
2644-1.36919 -0.21073  0.00840  0.08437  0.55292
2645
2646No Coefficients
2647
2648Residual standard error: 0.5235 on 10 degrees of freedom
2649
2650> anova(fit)
2651Analysis of Variance Table
2652
2653Response: y
2654          Df Sum Sq Mean Sq F value Pr(>F)
2655Residuals 10 2.7404 0.27404
2656> predict(fit)
2657 1  2  3  4  5  6  7  8  9 10
2658 0  0  0  0  0  0  0  0  0  0
2659> predict(fit, data.frame(x=x), se=TRUE)
2660$fit
2661 1  2  3  4  5  6  7  8  9 10
2662 0  0  0  0  0  0  0  0  0  0
2663
2664$se.fit
2665 [1] 0 0 0 0 0 0 0 0 0 0
2666
2667$df
2668[1] 10
2669
2670$residual.scale
2671[1] 0.5234843
2672
2673> predict(fit, type="terms", se=TRUE)
2674$fit
2675
2676 [1,]
2677 [2,]
2678 [3,]
2679 [4,]
2680 [5,]
2681 [6,]
2682 [7,]
2683 [8,]
2684 [9,]
2685[10,]
2686attr(,"constant")
2687[1] 0
2688
2689$se.fit
2690
2691 [1,]
2692 [2,]
2693 [3,]
2694 [4,]
2695 [5,]
2696 [6,]
2697 [7,]
2698 [8,]
2699 [9,]
2700[10,]
2701
2702$df
2703[1] 10
2704
2705$residual.scale
2706[1] 0.5234843
2707
2708> variable.names(fit) #should be empty
2709character(0)
2710> model.matrix(fit)
2711
27121
27132
27143
27154
27165
27176
27187
27198
27209
272110
2722attr(,"assign")
2723integer(0)
2724>
2725> (fit <- lm(y ~ x + 0))
2726
2727Call:
2728lm(formula = y ~ x + 0)
2729
2730Coefficients:
2731 x
2732NA
2733
2734> summary(fit)
2735
2736Call:
2737lm(formula = y ~ x + 0)
2738
2739Residuals:
2740     Min       1Q   Median       3Q      Max
2741-1.36919 -0.21073  0.00840  0.08437  0.55292
2742
2743Coefficients: (1 not defined because of singularities)
2744  Estimate Std. Error t value Pr(>|t|)
2745x       NA         NA      NA       NA
2746
2747Residual standard error: 0.5235 on 10 degrees of freedom
2748
2749> anova(fit)
2750Analysis of Variance Table
2751
2752Response: y
2753          Df Sum Sq Mean Sq F value Pr(>F)
2754Residuals 10 2.7404 0.27404
2755> predict(fit)
2756 1  2  3  4  5  6  7  8  9 10
2757 0  0  0  0  0  0  0  0  0  0
2758> predict(fit, data.frame(x=x), se=TRUE)
2759$fit
2760 1  2  3  4  5  6  7  8  9 10
2761 0  0  0  0  0  0  0  0  0  0
2762
2763$se.fit
2764 [1] 0 0 0 0 0 0 0 0 0 0
2765
2766$df
2767[1] 10
2768
2769$residual.scale
2770[1] 0.5234843
2771
2772Warning message:
2773In predict.lm(fit, data.frame(x = x), se = TRUE) :
2774  prediction from a rank-deficient fit may be misleading
2775> predict(fit, type="terms", se=TRUE)
2776$fit
2777   x
27781  0
27792  0
27803  0
27814  0
27825  0
27836  0
27847  0
27858  0
27869  0
278710 0
2788attr(,"constant")
2789[1] 0
2790
2791$se.fit
2792   x
27931  0
27942  0
27953  0
27964  0
27975  0
27986  0
27997  0
28008  0
28019  0
280210 0
2803
2804$df
2805[1] 10
2806
2807$residual.scale
2808[1] 0.5234843
2809
2810> variable.names(fit) #should be empty
2811character(0)
2812> model.matrix(fit)
2813   x
28141  0
28152  0
28163  0
28174  0
28185  0
28196  0
28207  0
28218  0
28229  0
282310 0
2824attr(,"assign")
2825[1] 1
2826>
2827> (fit <- glm(y ~ 0))
2828
2829Call:  glm(formula = y ~ 0)
2830
2831No coefficients
2832
2833
2834Degrees of Freedom: 10 Total (i.e. Null);  10 Residual
2835Null Deviance:	    2.74
2836Residual Deviance: 2.74 	AIC: 17.43
2837> summary(fit)
2838
2839Call:
2840glm(formula = y ~ 0)
2841
2842Deviance Residuals:
2843     Min        1Q    Median        3Q       Max
2844-1.36919  -0.21073   0.00840   0.08437   0.55292
2845
2846No Coefficients
2847
2848(Dispersion parameter for gaussian family taken to be 0.2740358)
2849
2850    Null deviance: 2.7404  on 10  degrees of freedom
2851Residual deviance: 2.7404  on 10  degrees of freedom
2852AIC: 17.434
2853
2854Number of Fisher Scoring iterations: 0
2855
2856> anova(fit)
2857Analysis of Deviance Table
2858
2859Model: gaussian, link: identity
2860
2861Response: y
2862
2863Terms added sequentially (first to last)
2864
2865
2866     Df Deviance Resid. Df Resid. Dev
2867NULL                    10     2.7404
2868> predict(fit)
2869 1  2  3  4  5  6  7  8  9 10
2870 0  0  0  0  0  0  0  0  0  0
2871> predict(fit, data.frame(x=x), se=TRUE)
2872$fit
2873 1  2  3  4  5  6  7  8  9 10
2874 0  0  0  0  0  0  0  0  0  0
2875
2876$se.fit
2877 [1] 0 0 0 0 0 0 0 0 0 0
2878
2879$residual.scale
2880[1] 0.5234843
2881
2882> predict(fit, type="terms", se=TRUE)
2883$fit
2884
2885 [1,]
2886 [2,]
2887 [3,]
2888 [4,]
2889 [5,]
2890 [6,]
2891 [7,]
2892 [8,]
2893 [9,]
2894[10,]
2895attr(,"constant")
2896[1] 0
2897
2898$se.fit
2899
2900 [1,]
2901 [2,]
2902 [3,]
2903 [4,]
2904 [5,]
2905 [6,]
2906 [7,]
2907 [8,]
2908 [9,]
2909[10,]
2910
2911$residual.scale
2912[1] 0.5234843
2913
2914>
2915> (fit <- glm(y ~ x + 0))
2916
2917Call:  glm(formula = y ~ x + 0)
2918
2919Coefficients:
2920 x
2921NA
2922
2923Degrees of Freedom: 10 Total (i.e. Null);  10 Residual
2924Null Deviance:	    2.74
2925Residual Deviance: 2.74 	AIC: 17.43
2926> summary(fit)
2927
2928Call:
2929glm(formula = y ~ x + 0)
2930
2931Deviance Residuals:
2932     Min        1Q    Median        3Q       Max
2933-1.36919  -0.21073   0.00840   0.08437   0.55292
2934
2935Coefficients: (1 not defined because of singularities)
2936  Estimate Std. Error t value Pr(>|t|)
2937x       NA         NA      NA       NA
2938
2939(Dispersion parameter for gaussian family taken to be 0.2740358)
2940
2941    Null deviance: 2.7404  on 10  degrees of freedom
2942Residual deviance: 2.7404  on 10  degrees of freedom
2943AIC: 17.434
2944
2945Number of Fisher Scoring iterations: 2
2946
2947> anova(fit)
2948Analysis of Deviance Table
2949
2950Model: gaussian, link: identity
2951
2952Response: y
2953
2954Terms added sequentially (first to last)
2955
2956
2957     Df Deviance Resid. Df Resid. Dev
2958NULL                    10     2.7404
2959x     0        0        10     2.7404
2960> predict(fit)
2961 1  2  3  4  5  6  7  8  9 10
2962 0  0  0  0  0  0  0  0  0  0
2963> predict(fit, data.frame(x=x), se=TRUE)
2964$fit
2965 1  2  3  4  5  6  7  8  9 10
2966 0  0  0  0  0  0  0  0  0  0
2967
2968$se.fit
2969 [1] 0 0 0 0 0 0 0 0 0 0
2970
2971$residual.scale
2972[1] 0.5234843
2973
2974Warning message:
2975In predict.lm(object, newdata, se.fit, scale = residual.scale, type = if (type ==  :
2976  prediction from a rank-deficient fit may be misleading
2977> predict(fit, type="terms", se=TRUE)
2978$fit
2979   x
29801  0
29812  0
29823  0
29834  0
29845  0
29856  0
29867  0
29878  0
29889  0
298910 0
2990attr(,"constant")
2991[1] 0
2992
2993$se.fit
2994   x
29951  0
29962  0
29973  0
29984  0
29995  0
30006  0
30017  0
30028  0
30039  0
300410 0
3005
3006$residual.scale
3007[1] 0.5234843
3008
3009> ## Lots of problems in 1.7.x
3010>
3011>
3012> ## lm.influence on deficient lm models
3013> dat <- data.frame(y=rnorm(10), x1=1:10, x2=1:10, x3 = 0, wt=c(0,rep(1, 9)),
3014+                   row.names=letters[1:10])
3015> dat[3, 1] <- dat[4, 2] <- NA
3016> lm.influence(lm(y ~ x1 + x2, data=dat, weights=wt, na.action=na.omit))
3017$hat
3018        b         e         f         g         h         i         j
30190.6546053 0.2105263 0.1546053 0.1447368 0.1809211 0.2631579 0.3914474
3020
3021$coefficients
3022  (Intercept)           x1
3023b  1.39138784 -0.173267165
3024e -0.70930972  0.068642877
3025f  0.12039809 -0.007818058
3026g  0.01971595  0.001314397
3027h  0.03272637 -0.017325726
3028i -0.36929526  0.092323814
3029j  0.33861311 -0.070163076
3030
3031$sigma
3032        b         e         f         g         h         i         j
30330.9641441 0.7434598 1.0496727 1.0681908 1.0389586 0.7633748 1.0093187
3034
3035$wt.res
3036         b          e          f          g          h          i          j
3037 0.5513046 -1.3728575  0.4018482  0.1708716 -0.4793451  1.2925334 -0.5643552
3038
3039> lm.influence(lm(y ~ x1 + x2, data=dat, weights=wt, na.action=na.exclude))
3040$hat
3041        b         e         c         d         f         g         h         i
30420.6546053 0.2105263 0.0000000 0.0000000 0.1546053 0.1447368 0.1809211 0.2631579
3043        j
30440.3914474
3045
3046$coefficients
3047  (Intercept)           x1
3048b  1.39138784 -0.173267165
3049e -0.70930972  0.068642877
3050c  0.00000000  0.000000000
3051d  0.00000000  0.000000000
3052f  0.12039809 -0.007818058
3053g  0.01971595  0.001314397
3054h  0.03272637 -0.017325726
3055i -0.36929526  0.092323814
3056j  0.33861311 -0.070163076
3057
3058$sigma
3059        b         e         c         d         f         g         h         i
30600.9641441 0.7434598 0.9589854 0.9589854 1.0496727 1.0681908 1.0389586 0.7633748
3061        j
30621.0093187
3063
3064$wt.res
3065         b          e          c          d          f          g          h
3066 0.5513046 -1.3728575         NA         NA  0.4018482  0.1708716 -0.4793451
3067         i          j
3068 1.2925334 -0.5643552
3069
3070> lm.influence(lm(y ~ 0, data=dat, weights=wt, na.action=na.omit))
3071$hat
3072b d e f g h i j
30730 0 0 0 0 0 0 0
3074
3075$coefficients
3076
3077b
3078d
3079e
3080f
3081g
3082h
3083i
3084j
3085
3086$sigma
3087        b         d         e         f         g         h         i         j
30880.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3089
3090$wt.res
3091         b          d          e          f          g          h          i
3092 0.3604547  0.1146812 -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918
3093         j
3094 0.3675473
3095
3096> print(width = 99,
3097+ lm.influence(lm(y ~ 0, data=dat, weights=wt, na.action=na.exclude))
3098+ ) ; stopifnot(getOption("width") == 80)
3099$hat
3100b d c e f g h i j
31010 0 0 0 0 0 0 0 0
3102
3103$coefficients
3104
3105b
3106d
3107c
3108e
3109f
3110g
3111h
3112i
3113j
3114
3115$sigma
3116        b         d         c         e         f         g         h         i         j
31170.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3118
3119$wt.res
3120         b          d          c          e          f          g          h          i          j
3121 0.3604547  0.1146812         NA -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918  0.3675473
3122
3123> lm.influence(lm(y ~ 0 + x3, data=dat, weights=wt, na.action=na.omit))
3124$hat
3125b d e f g h i j
31260 0 0 0 0 0 0 0
3127
3128$coefficients
3129
3130b
3131d
3132e
3133f
3134g
3135h
3136i
3137j
3138
3139$sigma
3140        b         d         e         f         g         h         i         j
31410.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3142
3143$wt.res
3144         b          d          e          f          g          h          i
3145 0.3604547  0.1146812 -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918
3146         j
3147 0.3675473
3148
3149> lm.influence(lm(y ~ 0 + x3, data=dat, weights=wt, na.action=na.exclude))
3150$hat
3151b d c e f g h i j
31520 0 0 0 0 0 0 0 0
3153
3154$coefficients
3155
3156b
3157d
3158c
3159e
3160f
3161g
3162h
3163i
3164j
3165
3166$sigma
3167        b         d         c         e         f         g         h         i
31680.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289
3169        j
31700.9366289
3171
3172$wt.res
3173         b          d          c          e          f          g          h
3174 0.3604547  0.1146812         NA -1.1426753  0.7723744  0.6817419  0.1718693
3175         i          j
3176 2.0840918  0.3675473
3177
3178> lm.influence(lm(y ~ 0, data=dat, na.action=na.exclude))
3179$hat
3180a b c d e f g h i j
31810 0 0 0 0 0 0 0 0 0
3182
3183$coefficients
3184
3185a
3186b
3187c
3188d
3189e
3190f
3191g
3192h
3193i
3194j
3195
3196$sigma
3197        a         b         c         d         e         f         g         h
31980.8860916 0.8860916 0.8860916 0.8860916 0.8860916 0.8860916 0.8860916 0.8860916
3199        i         j
32000.8860916 0.8860916
3201
3202$wt.res
3203         a          b          c          d          e          f          g
3204 0.2196280  0.3604547         NA  0.1146812 -1.1426753  0.7723744  0.6817419
3205         h          i          j
3206 0.1718693  2.0840918  0.3675473
3207
3208> ## last three misbehaved in 1.7.x, none had proper names.
3209>
3210>
3211> ## length of results in ARMAacf when lag.max is used
3212> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=1) # was 4 in 1.7.1
3213        0         1
32141.0000000 0.7644046
3215> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=2)
3216        0         1         2
32171.0000000 0.7644046 0.2676056
3218> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=3)
3219         0          1          2          3
3220 1.0000000  0.7644046  0.2676056 -0.2343150
3221> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=4)
3222         0          1          2          3          4
3223 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538
3224> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=5) # failed in 1.7.1
3225         0          1          2          3          4          5
3226 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538 -0.5099616
3227> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=6)
3228         0          1          2          3          4          5          6
3229 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538 -0.5099616 -0.2784942
3230> ARMAacf(ar=c(1.3,-0.6, -0.2, 0.1),lag.max=10)
3231         0          1          2          3          4          5          6
3232 1.0000000  0.7644046  0.2676056 -0.2343150 -0.5180538 -0.5099616 -0.2784942
3233         7          8          9         10
3234 0.0241137  0.2486313  0.3134551  0.2256408
3235> ##
3236>
3237>
3238> ## Indexing non-existent columns in a data frame
3239> x <- data.frame(a = 1, b = 2)
3240> try(x[c("a", "c")])
3241Error in `[.data.frame`(x, c("a", "c")) : undefined columns selected
3242> try(x[, c("a", "c")])
3243Error in `[.data.frame`(x, , c("a", "c")) : undefined columns selected
3244> try(x[1, c("a", "c")])
3245Error in `[.data.frame`(x, 1, c("a", "c")) : undefined columns selected
3246> ## Second succeeded, third gave uniformative error message in 1.7.x.
3247>
3248>
3249> ## methods(class = ) with namespaces, .Primitives etc (many missing in 1.7.x):
3250> meth2gen <- function(cl)
3251+     noquote(sub(paste("\\.",cl,"$",sep=""),"", c(.S3methods(class = cl))))
3252> meth2gen("data.frame")
3253 [1] $<-           Math          Ops           Summary       [
3254 [6] [<-           [[            [[<-          aggregate     anyDuplicated
3255[11] anyNA         as.data.frame as.list       as.matrix     by
3256[16] cbind         dim           dimnames      dimnames<-    droplevels
3257[21] duplicated    edit          format        formula       head
3258[26] is.na         merge         na.exclude    na.omit       plot
3259[31] print         prompt        rbind         row.names     row.names<-
3260[36] rowsum        split         split<-       stack         str
3261[41] subset        summary       t             tail          transform
3262[46] type.convert  unique        unstack       within        xtfrm
3263> meth2gen("dendrogram")
3264 [1] [[            as.dendrogram as.hclust     cophenetic    cut
3265 [6] labels        merge         nobs          plot          print
3266[11] reorder       rev           str
3267> ## --> the output may need somewhat frequent updating..
3268>
3269>
3270> ## subsetting a 1D array lost the dimensions
3271> x <- array(1:5, dim=c(5))
3272> dim(x)
3273[1] 5
3274> dim(x[, drop=TRUE])
3275[1] 5
3276> dim(x[2:3])
3277[1] 2
3278> dim(x[2])
3279NULL
3280> dim(x[2, drop=FALSE])
3281[1] 1
3282> dimnames(x) <- list(some=letters[1:5])
3283> x[]
3284some
3285a b c d e
32861 2 3 4 5
3287> x[2:3]
3288some
3289b c
32902 3
3291> x[2]
3292b
32932
3294> x[2, drop=FALSE]
3295some
3296b
32972
3298> ## both dim and dimnames lost in 1.8.0
3299>
3300>
3301> ## print.dist() didn't show NA's prior to 1.8.1
3302> x <- cbind(c(1,NA,2,3), c(NA,2,NA,1))
3303> (d <- dist(x))
3304         1        2        3
33052       NA
33063 1.414214       NA
33074 2.828427 1.414214 1.414214
3308> print(d, diag = TRUE)
3309         1        2        3        4
33101 0.000000
33112       NA 0.000000
33123 1.414214       NA 0.000000
33134 2.828427 1.414214 1.414214 0.000000
3314> ##
3315>
3316>
3317> ## offsets in model terms where sometimes not deleted correctly
3318> attributes(terms(~ a + b + a:b + offset(c)))[c("offset", "term.labels")]
3319$offset
3320[1] 3
3321
3322$term.labels
3323[1] "a"   "b"   "a:b"
3324
3325> attributes(terms(y ~ a + b + a:b + offset(c)))[c("offset", "term.labels")]
3326$offset
3327[1] 4
3328
3329$term.labels
3330[1] "a"   "b"   "a:b"
3331
3332> attributes(terms(~ offset(c) + a + b + a:b))[c("offset", "term.labels")]
3333$offset
3334[1] 1
3335
3336$term.labels
3337[1] "a"   "b"   "a:b"
3338
3339> attributes(terms(y ~ offset(c) + a + b + a:b))[c("offset", "term.labels")]
3340$offset
3341[1] 2
3342
3343$term.labels
3344[1] "a"   "b"   "a:b"
3345
3346> ## errors prior to 1.8.1
3347>
3348>
3349> ## 0-level factors gave nonsensical answers in model.matrix
3350> m <- model.frame(~x, data.frame(x=NA), na.action=na.pass)
3351> model.matrix(~x, m)
3352  (Intercept) xTRUE
33531           1    NA
3354attr(,"assign")
3355[1] 0 1
3356attr(,"contrasts")
3357attr(,"contrasts")$x
3358[1] "contr.treatment"
3359
3360> lm.fit <- lm(y ~ x, data.frame(x=1:10, y=1:10))
3361> try(predict(lm.fit, data.frame(x=NA)))
3362Error : variable 'x' was fitted with type "numeric" but type "logical" was supplied
3363> ## wrong answers in 1.8.0, refused to run in 1.8.1
3364>
3365>
3366>
3367> ## failure to print data frame containing arrays
3368> ## raised by John Fox on R-devel on 2004-01-08
3369> y1 <- array(1:10, dim=10)
3370> y2 <- array(1:30, dim=c(10,3), dimnames=list(NULL, letters[1:3]))
3371> y3 <- array(1:40, dim=c(10,2,2),
3372+             dimnames=list(NULL, letters[1:2], NULL))
3373> data.frame(y=y1)
3374    y
33751   1
33762   2
33773   3
33784   4
33795   5
33806   6
33817   7
33828   8
33839   9
338410 10
3385> data.frame(y=y2)
3386   y.a y.b y.c
33871    1  11  21
33882    2  12  22
33893    3  13  23
33904    4  14  24
33915    5  15  25
33926    6  16  26
33937    7  17  27
33948    8  18  28
33959    9  19  29
339610  10  20  30
3397> data.frame(y=y3)
3398   y.a.1 y.b.1 y.a.2 y.b.2
33991      1    11    21    31
34002      2    12    22    32
34013      3    13    23    33
34024      4    14    24    34
34035      5    15    25    35
34046      6    16    26    36
34057      7    17    27    37
34068      8    18    28    38
34079      9    19    29    39
340810    10    20    30    40
3409>
3410> as.data.frame(y1)
3411   y1
34121   1
34132   2
34143   3
34154   4
34165   5
34176   6
34187   7
34198   8
34209   9
342110 10
3422> as.data.frame(y2)
3423    a  b  c
34241   1 11 21
34252   2 12 22
34263   3 13 23
34274   4 14 24
34285   5 15 25
34296   6 16 26
34307   7 17 27
34318   8 18 28
34329   9 19 29
343310 10 20 30
3434> as.data.frame(y3)
3435   a.1 b.1 a.2 b.2
34361    1  11  21  31
34372    2  12  22  32
34383    3  13  23  33
34394    4  14  24  34
34405    5  15  25  35
34416    6  16  26  36
34427    7  17  27  37
34438    8  18  28  38
34449    9  19  29  39
344510  10  20  30  40
3446>
3447> X <- data.frame(x=1:10)
3448> X$y <- y1
3449> X
3450    x  y
34511   1  1
34522   2  2
34533   3  3
34544   4  4
34555   5  5
34566   6  6
34577   7  7
34588   8  8
34599   9  9
346010 10 10
3461> sapply(X, dim)
3462$x
3463NULL
3464
3465$y
3466[1] 10
3467
3468>
3469> X$y <- y2
3470> X
3471    x y.a y.b y.c
34721   1   1  11  21
34732   2   2  12  22
34743   3   3  13  23
34754   4   4  14  24
34765   5   5  15  25
34776   6   6  16  26
34787   7   7  17  27
34798   8   8  18  28
34809   9   9  19  29
348110 10  10  20  30
3482> sapply(X, dim)
3483$x
3484NULL
3485
3486$y
3487[1] 10  3
3488
3489>
3490> X$y <- y3
3491> X
3492    x y.a.1 y.b.1 y.a.2 y.b.2
34931   1     1    11    21    31
34942   2     2    12    22    32
34953   3     3    13    23    33
34964   4     4    14    24    34
34975   5     5    15    25    35
34986   6     6    16    26    36
34997   7     7    17    27    37
35008   8     8    18    28    38
35019   9     9    19    29    39
350210 10    10    20    30    40
3503> sapply(X, dim)
3504$x
3505NULL
3506
3507$y
3508[1] 10  2  2
3509
3510> ## The last one fails in S.
3511>
3512> ## test of user hooks
3513> for(id in c("A", "B")) {
3514+     eval(substitute(
3515+     {
3516+ setHook(packageEvent("stats4", "onLoad"),
3517+         function(pkgname, ...) cat("onLoad", sQuote(pkgname), id, "\n"));
3518+ setHook(packageEvent("stats4", "attach"),
3519+         function(pkgname, ...) cat("attach", sQuote(pkgname), id, "\n"));
3520+ setHook(packageEvent("stats4", "detach"),
3521+         function(pkgname, ...) cat("detach", sQuote(pkgname), id, "\n"));
3522+ setHook(packageEvent("stats4", "onUnload"),
3523+         function(pkgname, ...) cat("onUnload", sQuote(pkgname), id, "\n"))
3524+     },
3525+                     list(id=id)))
3526+ }
3527> loadNamespace("stats4")
3528onLoad 'stats4' A
3529onLoad 'stats4' B
3530<environment: namespace:stats4>
3531> library("stats4")
3532attach 'stats4' A
3533attach 'stats4' B
3534> detach("package:stats4")
3535detach 'stats4' B
3536detach 'stats4' A
3537> unloadNamespace("stats4")
3538onUnload 'stats4' B
3539onUnload 'stats4' A
3540> ## Just tests
3541>
3542>
3543> ## rep(0-length-vector, length.out > 0)
3544> rep(integer(0), length.out=0)
3545integer(0)
3546> rep(integer(0), length.out=10)
3547 [1] NA NA NA NA NA NA NA NA NA NA
3548> typeof(.Last.value)
3549[1] "integer"
3550> rep(logical(0), length.out=0)
3551logical(0)
3552> rep(logical(0), length.out=10)
3553 [1] NA NA NA NA NA NA NA NA NA NA
3554> typeof(.Last.value)
3555[1] "logical"
3556> rep(numeric(0), length.out=0)
3557numeric(0)
3558> rep(numeric(0), length.out=10)
3559 [1] NA NA NA NA NA NA NA NA NA NA
3560> typeof(.Last.value)
3561[1] "double"
3562> rep(character(0), length.out=0)
3563character(0)
3564> rep(character(0), length.out=10)
3565 [1] NA NA NA NA NA NA NA NA NA NA
3566> typeof(.Last.value)
3567[1] "character"
3568> rep(complex(0), length.out=0)
3569complex(0)
3570> rep(complex(0), length.out=10)
3571 [1] NA NA NA NA NA NA NA NA NA NA
3572> typeof(.Last.value)
3573[1] "complex"
3574> rep(list(), length.out=0)
3575list()
3576> rep(list(), length.out=10)
3577[[1]]
3578NULL
3579
3580[[2]]
3581NULL
3582
3583[[3]]
3584NULL
3585
3586[[4]]
3587NULL
3588
3589[[5]]
3590NULL
3591
3592[[6]]
3593NULL
3594
3595[[7]]
3596NULL
3597
3598[[8]]
3599NULL
3600
3601[[9]]
3602NULL
3603
3604[[10]]
3605NULL
3606
3607> ## always 0-length before 1.9.0
3608>
3609>
3610> ## supplying 0-length data to array and matrix
3611> array(numeric(0), c(2, 2))
3612     [,1] [,2]
3613[1,]   NA   NA
3614[2,]   NA   NA
3615> array(list(), c(2,2))
3616     [,1] [,2]
3617[1,] NULL NULL
3618[2,] NULL NULL
3619> # worked < 1.8.0, error in 1.8.x
3620> matrix(character(0), 1, 2)
3621     [,1] [,2]
3622[1,] NA   NA
3623> matrix(integer(0), 1, 2)
3624     [,1] [,2]
3625[1,]   NA   NA
3626> matrix(logical(0), 1, 2)
3627     [,1] [,2]
3628[1,]   NA   NA
3629> matrix(numeric(0), 1, 2)
3630     [,1] [,2]
3631[1,]   NA   NA
3632> matrix(complex(0), 1, 2)
3633     [,1] [,2]
3634[1,]   NA   NA
3635> matrix(list(), 1, 2)
3636     [,1] [,2]
3637[1,] NULL NULL
3638> ## did not work < 1.9.0
3639>
3640>
3641> ## S compatibility change in 1.9.0
3642> rep(1:2, each=3, length=12)
3643 [1] 1 1 1 2 2 2 1 1 1 2 2 2
3644> ## used to pad with NAs.
3645>
3646>
3647> ## PR#6510: aov() with error and -1
3648> set.seed(1)
3649> test.df <- data.frame (y=rnorm(8), a=gl(2,1,8), b=gl(2,3,8),c=gl(2,4,8))
3650> aov(y ~ a + b + Error(c), data=test.df)
3651
3652Call:
3653aov(formula = y ~ a + b + Error(c), data = test.df)
3654
3655Grand Mean: 0.8066534
3656
3657Stratum 1: c
3658
3659Terms:
3660                        b
3661Sum of Squares  0.3176489
3662Deg. of Freedom         1
3663
3664Estimated effects are balanced
3665
3666Stratum 2: Within
3667
3668Terms:
3669                       a        b Residuals
3670Sum of Squares  1.389453 2.148149  5.048689
3671Deg. of Freedom        1        1         4
3672
3673Residual standard error: 1.123464
3674Estimated effects may be unbalanced
3675> aov(y ~ a + b - 1 + Error(c), data=test.df)
3676
3677Call:
3678aov(formula = y ~ a + b - 1 + Error(c), data = test.df)
3679
3680Stratum 1: c
3681
3682Terms:
3683                       a        b
3684Sum of Squares  5.205518 0.317649
3685Deg. of Freedom        1        1
3686
36871 out of 3 effects not estimable
3688Estimated effects may be unbalanced
3689
3690Stratum 2: Within
3691
3692Terms:
3693                       a        b Residuals
3694Sum of Squares  1.389453 2.148149  5.048689
3695Deg. of Freedom        1        1         4
3696
3697Residual standard error: 1.123464
36981 out of 3 effects not estimable
3699Estimated effects may be unbalanced
3700> ## wrong assignment to strata labels < 1.9.0
3701> ## Note this is unbalanced and not a good example
3702>
3703> binom.test(c(800,10))# p-value < epsilon
3704
3705	Exact binomial test
3706
3707data:  c(800, 10)
3708number of successes = 800, number of trials = 810, p-value < 2.2e-16
3709alternative hypothesis: true probability of success is not equal to 0.5
371095 percent confidence interval:
3711 0.9774134 0.9940643
3712sample estimates:
3713probability of success
3714             0.9876543
3715
3716>
3717>
3718> ## aov with a singular error model
3719> rd <- c(16.53, 12.12, 10.04, 15.32, 12.33, 10.1, 17.09, 11.69, 11.81, 14.75,
3720+         10.72, 8.79, 13.14, 9.79, 8.36, 15.62, 9.64, 8.72, 15.32,
3721+         11.35, 8.52, 13.27, 9.74, 8.78, 13.16, 10.16, 8.4, 13.08, 9.66,
3722+         8.16, 12.17, 9.13, 7.43, 13.28, 9.16, 7.92, 118.77, 78.83, 62.2,
3723+         107.29, 73.79, 58.59, 118.9, 66.35, 53.12, 372.62, 245.39, 223.72,
3724+         326.03, 232.67, 209.44, 297.55, 239.71, 223.8)
3725> sample.df <- data.frame(dep.variable=rd,
3726+                         subject=factor(rep(paste("subj",1:6, sep=""),each=9)),
3727+                         f1=factor(rep(rep(c("f1","f2","f3"),each=6),3)),
3728+                         f2=factor(rep(c("g1","g2","g3"),each=18))
3729+ )
3730> sample.aov <- aov(dep.variable ~ f1 * f2 + Error(subject/(f1+f2)), data=sample.df)
3731Warning message:
3732In aov(dep.variable ~ f1 * f2 + Error(subject/(f1 + f2)), data = sample.df) :
3733  Error() model is singular
3734> sample.aov
3735
3736Call:
3737aov(formula = dep.variable ~ f1 * f2 + Error(subject/(f1 + f2)),
3738    data = sample.df)
3739
3740Grand Mean: 65.07444
3741
3742Stratum 1: subject
3743
3744Terms:
3745                       f1        f2     f1:f2
3746Sum of Squares   47815.99 312824.49 100370.96
3747Deg. of Freedom         1         2         2
3748
37492 out of 7 effects not estimable
3750Estimated effects may be unbalanced
3751
3752Stratum 2: subject:f1
3753
3754Terms:
3755                      f1    f1:f2
3756Sum of Squares  483.9628 869.6876
3757Deg. of Freedom        2        4
3758
3759Estimated effects may be unbalanced
3760
3761Stratum 3: Within
3762
3763Terms:
3764                Residuals
3765Sum of Squares   29204.13
3766Deg. of Freedom        42
3767
3768Residual standard error: 26.36923
3769> summary(sample.aov)
3770
3771Error: subject
3772      Df Sum Sq Mean Sq
3773f1     1  47816   47816
3774f2     2 312824  156412
3775f1:f2  2 100371   50185
3776
3777Error: subject:f1
3778      Df Sum Sq Mean Sq
3779f1     2  484.0   242.0
3780f1:f2  4  869.7   217.4
3781
3782Error: Within
3783          Df Sum Sq Mean Sq F value Pr(>F)
3784Residuals 42  29204   695.3
3785> sample.aov <- aov(dep.variable ~ f1 * f2 + Error(subject/(f2+f1)), data=sample.df)
3786Warning message:
3787In aov(dep.variable ~ f1 * f2 + Error(subject/(f2 + f1)), data = sample.df) :
3788  Error() model is singular
3789> sample.aov
3790
3791Call:
3792aov(formula = dep.variable ~ f1 * f2 + Error(subject/(f2 + f1)),
3793    data = sample.df)
3794
3795Grand Mean: 65.07444
3796
3797Stratum 1: subject
3798
3799Terms:
3800                       f1        f2     f1:f2
3801Sum of Squares   47815.99 312824.49 100370.96
3802Deg. of Freedom         1         2         2
3803
38042 out of 7 effects not estimable
3805Estimated effects may be unbalanced
3806
3807Stratum 2: subject:f1
3808
3809Terms:
3810                      f1    f1:f2
3811Sum of Squares  483.9628 869.6876
3812Deg. of Freedom        2        4
3813
3814Estimated effects may be unbalanced
3815
3816Stratum 3: Within
3817
3818Terms:
3819                Residuals
3820Sum of Squares   29204.13
3821Deg. of Freedom        42
3822
3823Residual standard error: 26.36923
3824> summary(sample.aov)
3825
3826Error: subject
3827      Df Sum Sq Mean Sq
3828f1     1  47816   47816
3829f2     2 312824  156412
3830f1:f2  2 100371   50185
3831
3832Error: subject:f1
3833      Df Sum Sq Mean Sq
3834f1     2  484.0   242.0
3835f1:f2  4  869.7   217.4
3836
3837Error: Within
3838          Df Sum Sq Mean Sq F value Pr(>F)
3839Residuals 42  29204   695.3
3840> ## failed in 1.8.1
3841>
3842>
3843> ## PR#6645  stem() with near-constant values
3844> stem(rep(1, 100))
3845
3846  The decimal point is at the |
3847
3848  1 | 00000000000000000000000000000000000000000000000000000000000000000000+20
3849
3850> stem(rep(0.1, 10))
3851
3852  The decimal point is 1 digit(s) to the left of the |
3853
3854  1 | 0000000000
3855
3856> stem(c(rep(1, 10), 1+1.e-8))
3857
3858  The decimal point is 8 digit(s) to the left of the |
3859
3860  100000000 | 0000000000
3861  100000000 |
3862  100000001 | 0
3863
3864> stem(c(rep(1, 10), 1+1.e-9))
3865
3866  The decimal point is 8 digit(s) to the left of the |
3867
3868  100000000 | 00000000001
3869
3870> stem(c(rep(1, 10), 1+1.e-10), atom=0) # integer-overflow is avoided.
3871
3872  The decimal point is 8 digit(s) to the left of the |
3873
3874  100000000 | 00000000000
3875
3876> ##  had integer overflows in 1.8.1, and silly shifts of decimal point
3877>
3878>
3879> ## PR#6633 warnings with vector op matrix, and more
3880> set.seed(1)
3881> x1 <- rnorm(3)
3882> y1 <- rnorm(4)
3883> x1 * y1
3884[1]  0.5574682  0.1410502  0.1609194 -0.3641637
3885Warning message:
3886In x1 * y1 :
3887  longer object length is not a multiple of shorter object length
3888> x1 * as.matrix(y1) # no warning in 1.8.1
3889           [,1]
3890[1,]  0.5574682
3891[2,]  0.1410502
3892[3,]  0.1609194
3893[4,] -0.3641637
3894Warning message:
3895In x1 * as.matrix(y1) :
3896  longer object length is not a multiple of shorter object length
3897> x1 * matrix(y1,2,2)# ditto
3898          [,1]       [,2]
3899[1,] 0.5574682  0.1609194
3900[2,] 0.1410502 -0.3641637
3901Warning message:
3902In x1 * matrix(y1, 2, 2) :
3903  longer object length is not a multiple of shorter object length
3904> z1 <- x1 > 0
3905> z2 <- y1 > 0
3906> z1 & z2
3907[1]  TRUE  TRUE  TRUE FALSE
3908Warning message:
3909In z1 & z2 :
3910  longer object length is not a multiple of shorter object length
3911> z1 & as.matrix(z2) # no warning in 1.8.1
3912      [,1]
3913[1,]  TRUE
3914[2,]  TRUE
3915[3,]  TRUE
3916[4,] FALSE
3917Warning message:
3918In z1 & as.matrix(z2) :
3919  longer object length is not a multiple of shorter object length
3920> x1 < y1            # no warning in 1.8.1
3921[1] FALSE  TRUE FALSE FALSE
3922Warning message:
3923In x1 < y1 :
3924  longer object length is not a multiple of shorter object length
3925> x1 < as.matrix(y1) # ditto
3926      [,1]
3927[1,] FALSE
3928[2,]  TRUE
3929[3,] FALSE
3930[4,] FALSE
3931Warning message:
3932In x1 < as.matrix(y1) :
3933  longer object length is not a multiple of shorter object length
3934> ##
3935>
3936>
3937> ## summary method for mle
3938> library(stats4)
3939onLoad 'stats4' A
3940onLoad 'stats4' B
3941attach 'stats4' A
3942attach 'stats4' B
3943> N <- c(rep(3:6, 3), 7,7, rep(8,6), 9,9, 10,12)# sample from Pois(lam = 7)
3944> summary(mle(function(Lam = 1) -sum(dpois(N, Lam))))
3945Maximum likelihood estimation
3946
3947Call:
3948mle(minuslogl = function(Lam = 1) -sum(dpois(N, Lam)))
3949
3950Coefficients:
3951    Estimate Std. Error
3952Lam 6.063755   2.307546
3953
3954-2 log L: -5.437059
3955> ## "Coefficients" was "NULL" in 1.9.0's "devel"
3956>
3957>
3958> ## PR#6656 terms.formula(simplify = TRUE) was losing offset terms
3959> ## successive offsets caused problems
3960> df <- data.frame(x=1:4, y=sqrt( 1:4), z=c(2:4,1))
3961> fit1 <- glm(y ~ offset(x) + z, data=df)
3962> update(fit1, ". ~.")$call
3963glm(formula = y ~ z + offset(x), data = df)
3964> ## lost offset in 1.7.0 to 1.8.1
3965> terms(y ~ offset(x) + offset(log(x)) + z, data=df)
3966y ~ offset(x) + offset(log(x)) + z
3967attr(,"variables")
3968list(y, offset(x), offset(log(x)), z)
3969attr(,"offset")
3970[1] 2 3
3971attr(,"factors")
3972               z
3973y              0
3974offset(x)      0
3975offset(log(x)) 0
3976z              1
3977attr(,"term.labels")
3978[1] "z"
3979attr(,"order")
3980[1] 1
3981attr(,"intercept")
3982[1] 1
3983attr(,"response")
3984[1] 1
3985attr(,".Environment")
3986<environment: R_GlobalEnv>
3987> ## failed to remove second offset from formula in 1.8.1
3988> terms(y ~ offset(x) + z - z, data=df, simplify = TRUE)
3989y ~ offset(x)
3990attr(,"variables")
3991list(y, offset(x), z)
3992attr(,"offset")
3993[1] 2
3994attr(,"factors")
3995integer(0)
3996attr(,"term.labels")
3997character(0)
3998attr(,"order")
3999integer(0)
4000attr(,"intercept")
4001[1] 1
4002attr(,"response")
4003[1] 1
4004attr(,".Environment")
4005<environment: R_GlobalEnv>
4006> ## first fix failed for models with no non-offset terms.
4007>
4008>
4009> ## only the first two were wrong up to 1.8.1:
4010> 3:4 * 1e-100
4011[1] 3e-100 4e-100
4012> 8:11* 1e-100
4013[1] 8.0e-100 9.0e-100  1.0e-99  1.1e-99
4014> 1:2 * 1e-99
4015[1] 1e-99 2e-99
4016> 1:2 * 1e+99
4017[1] 1e+99 2e+99
4018> 8:11* 1e+99
4019[1]  8.0e+99  9.0e+99 1.0e+100 1.1e+100
4020> 3:4 * 1e+100
4021[1] 3e+100 4e+100
4022> ##
4023>
4024>
4025> ## negative subscripts could be mixed with NAs
4026> x <- 1:3
4027> try(x[-c(1, NA)])
4028Error in x[-c(1, NA)] : only 0's may be mixed with negative subscripts
4029> ## worked on some platforms, segfaulted on others in 1.8.1
4030>
4031>
4032> ## vector 'border' (and no 'pch', 'cex' nor 'bg'):
4033> boxplot(count ~ spray, data = InsectSprays, border=2:7)
4034> ## gave warnings in 1.9.0
4035>
4036> summary(as.Date(paste("2002-12", 26:31, sep="-")))
4037        Min.      1st Qu.       Median         Mean      3rd Qu.         Max.
4038"2002-12-26" "2002-12-27" "2002-12-28" "2002-12-28" "2002-12-29" "2002-12-31"
4039> ## printed all "2002.-12-29" in 1.9.1 {because digits was too small}
4040> as.matrix(data.frame(d = as.POSIXct("2004-07-20")))
4041     d
4042[1,] "2004-07-20"
4043> ## gave a warning in 1.9.1
4044>
4045>
4046> ## Dump should quote when necessary (PR#6857)
4047> x <- quote(b)
4048> dump("x", "")
4049x <-
4050quote(b)
4051> ## doesn't quote b in 1.9.0
4052>
4053>
4054> ## some checks of indexing by character, used to test hashing code
4055> x <- 1:26
4056> names(x) <- letters
4057> x[c("a", "aa", "aa")] <- 100:102
4058> x
4059  a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p   q   r   s   t
4060100   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
4061  u   v   w   x   y   z  aa
4062 21  22  23  24  25  26 102
4063>
4064> x <- 1:26
4065> names(x) <- rep("", 26)
4066> x[c("a", "aa", "aa")] <- 100:102
4067> x
4068
4069  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20
4070                          a  aa
4071 21  22  23  24  25  26 100 102
4072> ##
4073>
4074>
4075> ## tests of raw type
4076> # tests of logic operators
4077> x <- "A test string"
4078> (y <- charToRaw(x))
4079 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67
4080> (xx <- c(y, as.raw(0), charToRaw("more")))
4081 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67 00 6d 6f 72 65
4082>
4083> !y
4084 [1] be df 8b 9a 8c 8b df 8c 8b 8d 96 91 98
4085> y & as.raw(15)
4086 [1] 01 00 04 05 03 04 00 03 04 02 09 0e 07
4087> y | as.raw(128)
4088 [1] c1 a0 f4 e5 f3 f4 a0 f3 f4 f2 e9 ee e7
4089>
4090> # tests of binary read/write
4091> zz <- file("testbin", "wb")
4092> writeBin(xx, zz)
4093> close(zz)
4094> zz <- file("testbin", "rb")
4095> (yy <- readBin(zz, "raw", 100))
4096 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67 00 6d 6f 72 65
4097> seek(zz, 0, "start")
4098[1] 18
4099> readBin(zz, "integer", n=100, size = 1) # read as small integers
4100 [1]  65  32 116 101 115 116  32 115 116 114 105 110 103   0 109 111 114 101
4101> seek(zz, 0, "start")
4102[1] 18
4103> readBin(zz, "character", 100)  # is confused by embedded nul.
4104[1] "A test string"
4105Warning message:
4106In readBin(zz, "character", 100) :
4107  incomplete string at end of file has been discarded
4108> seek(zz, 0, "start")
4109[1] 18
4110> readChar(zz, length(xx)) # truncates at embedded nul
4111[1] "A test string"
4112Warning message:
4113In readChar(zz, length(xx)) : truncating string with embedded nuls
4114> seek(zz) # make sure current position is reported properly
4115[1] 18
4116> close(zz)
4117> unlink("testbin")
4118>
4119> # tests of ASCII read/write.
4120> cat(xx, file="testascii")
4121> scan("testascii", what=raw(0))
4122Read 18 items
4123 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67 00 6d 6f 72 65
4124> unlink("testascii")
4125> ##
4126>
4127>
4128> ## Example of prediction not from newdata as intended.
4129> set.seed(1)
4130> y <- rnorm(10)
4131> x  <- cbind(1:10, sample(1:10)) # matrix
4132> xt <- cbind(1:2,  3:4)
4133> (lm1 <- lm(y ~ x))
4134
4135Call:
4136lm(formula = y ~ x)
4137
4138Coefficients:
4139(Intercept)           x1           x2
4140    1.88803     -0.15694     -0.09072
4141
4142> predict(lm1, newdata = data.frame(x= xt))
4143          1           2           3           4           5           6
4144 1.36820341  1.02982433  1.14505218  0.35306615  0.92190094  0.12991492
4145          7           8           9          10
4146 0.33586416 -0.09323631 -0.15945124  0.22794078
4147Warning message:
4148'newdata' had 2 rows but variables found have 10 rows
4149> ## warns as from 2.0.0
4150>
4151>
4152> ## eval could alter a data.frame/list second argument
4153> data(trees)
4154> a <- trees
4155> eval(quote({Girth[1]<-NA;Girth}),a)
4156 [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
4157[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
4158[31] 20.6
4159> a[1, ]
4160  Girth Height Volume
41611   8.3     70   10.3
4162> trees[1, ]
4163  Girth Height Volume
41641   8.3     70   10.3
4165> ## both a and trees got altered in 1.9.1
4166>
4167>
4168> ## write.table did not apply qmethod to col.names (PR#7171)
4169> x <- data.frame("test string with \"" = c("a \" and a '"), check.names=FALSE)
4170> write.table(x)
4171"test string with \""
4172"1" "a \" and a '"
4173> write.table(x, qmethod = "double")
4174"test string with """
4175"1" "a "" and a '"
4176> ## Quote in col name was unescaped in 1.9.1.
4177>
4178>
4179> ## extensions to read.table
4180> Mat <- matrix(c(1:3, letters[1:3], 1:3, LETTERS[1:3],
4181+                 c("2004-01-01", "2004-02-01", "2004-03-01"),
4182+                 c("2004-01-01 12:00", "2004-02-01 12:00", "2004-03-01 12:00")),
4183+               3, 6)
4184> foo <- tempfile(tmpdir = getwd())
4185> write.table(Mat, foo, col.names = FALSE, row.names = FALSE)
4186> read.table(foo, colClasses = c(NA, NA, "NULL", "character", "Date", "POSIXct"),
4187+            stringsAsFactors=TRUE)
4188  V1 V2 V4         V5                  V6
41891  1  a  A 2004-01-01 2004-01-01 12:00:00
41902  2  b  B 2004-02-01 2004-02-01 12:00:00
41913  3  c  C 2004-03-01 2004-03-01 12:00:00
4192> unlist(sapply(.Last.value, class))
4193         V1          V2          V4          V5         V61         V62
4194  "integer"    "factor" "character"      "Date"   "POSIXct"    "POSIXt"
4195> read.table(foo, colClasses = c("factor",NA,"NULL","factor","Date","POSIXct"),
4196+            stringsAsFactors=TRUE)
4197  V1 V2 V4         V5                  V6
41981  1  a  A 2004-01-01 2004-01-01 12:00:00
41992  2  b  B 2004-02-01 2004-02-01 12:00:00
42003  3  c  C 2004-03-01 2004-03-01 12:00:00
4201> unlist(sapply(.Last.value, class))
4202       V1        V2        V4        V5       V61       V62
4203 "factor"  "factor"  "factor"    "Date" "POSIXct"  "POSIXt"
4204> read.table(foo, colClasses = c(V4="character"), stringsAsFactors=TRUE)
4205  V1 V2 V3 V4         V5               V6
42061  1  a  1  A 2004-01-01 2004-01-01 12:00
42072  2  b  2  B 2004-02-01 2004-02-01 12:00
42083  3  c  3  C 2004-03-01 2004-03-01 12:00
4209> unlist(sapply(.Last.value, class))
4210         V1          V2          V3          V4          V5          V6
4211  "integer"    "factor"   "integer" "character"    "factor"    "factor"
4212> unlink(foo)
4213> ## added in 2.0.0
4214>
4215>
4216> ## write.table with complex columns (PR#7260, in part)
4217> write.table(data.frame(x = 0.5+1:4, y = 1:4 + 1.5i), file = "")
4218"x" "y"
4219"1" 1.5 1+1.5i
4220"2" 2.5 2+1.5i
4221"3" 3.5 3+1.5i
4222"4" 4.5 4+1.5i
4223> # printed all as complex in 2.0.0.
4224> write.table(data.frame(x = 0.5+1:4, y = 1:4 + 1.5i), file = "", dec=",")
4225"x" "y"
4226"1" 1,5 1+1,5i
4227"2" 2,5 2+1,5i
4228"3" 3,5 3+1,5i
4229"4" 4,5 4+1,5i
4230> ## used '.' not ',' in 2.0.0
4231>
4232> ## splinefun() value test
4233> (x <- seq(0,6, length=25))
4234 [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
4235[16] 3.75 4.00 4.25 4.50 4.75 5.00 5.25 5.50 5.75 6.00
4236> mx <- sapply(c("fmm", "nat", "per"),
4237+              function(m) splinefun(1:5, c(1,2,4,3,1), method = m)(x))
4238> cbind(x,mx)
4239         x       fmm         nat       per
4240 [1,] 0.00 5.3333333  0.46428571 3.0000000
4241 [2,] 0.25 3.5312500  0.59821429 2.4062500
4242 [3,] 0.50 2.2500000  0.73214286 1.8125000
4243 [4,] 0.75 1.4270833  0.86607143 1.3125000
4244 [5,] 1.00 1.0000000  1.00000000 1.0000000
4245 [6,] 1.25 0.9062500  1.14118304 0.9453125
4246 [7,] 1.50 1.0833333  1.32589286 1.1250000
4247 [8,] 1.75 1.4687500  1.59765625 1.4921875
4248 [9,] 2.00 2.0000000  2.00000000 2.0000000
4249[10,] 2.25 2.6093750  2.54854911 2.5937500
4250[11,] 2.50 3.2083333  3.14732143 3.1875000
4251[12,] 2.75 3.7031250  3.67243304 3.6875000
4252[13,] 3.00 4.0000000  4.00000000 4.0000000
4253[14,] 3.25 4.0312500  4.03962054 4.0546875
4254[15,] 3.50 3.8333333  3.83482143 3.8750000
4255[16,] 3.75 3.4687500  3.46261161 3.5078125
4256[17,] 4.00 3.0000000  3.00000000 3.0000000
4257[18,] 4.25 2.4843750  2.51171875 2.4062500
4258[19,] 4.50 1.9583333  2.01339286 1.8125000
4259[20,] 4.75 1.4531250  1.50837054 1.3125000
4260[21,] 5.00 1.0000000  1.00000000 1.0000000
4261[22,] 5.25 0.6302083  0.49107143 0.9453125
4262[23,] 5.50 0.3750000 -0.01785714 1.1250000
4263[24,] 5.75 0.2656250 -0.52678571 1.4921875
4264[25,] 6.00 0.3333333 -1.03571429 2.0000000
4265>
4266>
4267> ## infinite loop in read.fwf (PR#7350)
4268> cat(file="test.txt", sep = "\n", "# comment 1", "1234567   # comment 2",
4269+     "1 234567  # comment 3", "12345  67 # comment 4", "# comment 5")
4270> read.fwf("test.txt", width=c(2,2,3), skip=1, n=4) # looped
4271  V1 V2  V3
42721 12 34 567
42732  1 23 456
42743 12 34   5
4275> read.fwf("test.txt", width=c(2,2,3), skip=1)      # 1 line short
4276  V1 V2  V3
42771 12 34 567
42782  1 23 456
42793 12 34   5
4280> read.fwf("test.txt", width=c(2,2,3), skip=0)
4281  V1 V2  V3
42821 12 34 567
42832  1 23 456
42843 12 34   5
4285> unlink("test.txt")
4286> ##
4287>
4288>
4289> ## split was not handling lists and raws
4290> split(as.list(1:3), c(1,1,2))
4291$`1`
4292$`1`[[1]]
4293[1] 1
4294
4295$`1`[[2]]
4296[1] 2
4297
4298
4299$`2`
4300$`2`[[1]]
4301[1] 3
4302
4303
4304> (y <- charToRaw("A test string"))
4305 [1] 41 20 74 65 73 74 20 73 74 72 69 6e 67
4306> (z <- split(y, rep(1:5, times=c(1,1,4,1,6))))
4307$`1`
4308[1] 41
4309
4310$`2`
4311[1] 20
4312
4313$`3`
4314[1] 74 65 73 74
4315
4316$`4`
4317[1] 20
4318
4319$`5`
4320[1] 73 74 72 69 6e 67
4321
4322> sapply(z, rawToChar)
4323       1        2        3        4        5
4324     "A"      " "   "test"      " " "string"
4325> ## wrong results in 2.0.0
4326>
4327>
4328> ## tests of changed S3 implicit classes in 2.1.0
4329> foo <- function(x, ...) UseMethod("foo")
4330> foo.numeric <- function(x) cat("numeric arg\n")
4331> foo(1:10)
4332numeric arg
4333> foo(pi)
4334numeric arg
4335> foo(matrix(1:10, 2, 5))
4336numeric arg
4337> foo.integer <- function(x) cat("integer arg\n")
4338> foo.double <- function(x) cat("double arg\n")
4339> foo(1:10)
4340integer arg
4341> foo(pi)
4342double arg
4343> foo(matrix(1:10, 2, 5))
4344integer arg
4345> ##
4346>
4347>
4348> ## str() interpreted escape sequences prior to 2.1.0
4349> x <- "ab\bc\ndef"
4350> str(x)
4351 chr "ab\bc\ndef"
4352> str(x, vec.len=0)# failed in rev 32244
4353 chr  ...
4354> str(factor(x))
4355 Factor w/ 1 level "ab\bc\ndef": 1
4356>
4357> x <- c("a", NA, "b")
4358> factor(x)
4359[1] a    <NA> b
4360Levels: a b
4361> factor(x, exclude="")
4362[1] a    <NA> b
4363Levels: a b <NA>
4364> str(x)
4365 chr [1:3] "a" NA "b"
4366> str(factor(x))
4367 Factor w/ 2 levels "a","b": 1 NA 2
4368> str(factor(x, exclude=""))
4369 Factor w/ 3 levels "a","b",NA: 1 3 2
4370> ##
4371>
4372>
4373> ## print.factor(quote=TRUE) was not quoting levels
4374> x <- c("a", NA, "b", 'a " test') #" (comment for fontification)
4375> factor(x)
4376[1] a        <NA>     b        a " test
4377Levels: a a " test b
4378> factor(x, exclude="")
4379[1] a        <NA>     b        a " test
4380Levels: a a " test b <NA>
4381> print(factor(x), quote=TRUE)
4382[1] "a"         NA          "b"         "a \" test"
4383Levels: "a" "a \" test" "b"
4384> print(factor(x, exclude=""), quote=TRUE)
4385[1] "a"         NA          "b"         "a \" test"
4386Levels: "a" "a \" test" "b" NA
4387> ## last two printed levels differently from values in 2.0.1
4388>
4389>
4390> ## write.table in marginal cases
4391> x <- matrix(, 3, 0)
4392> write.table(x) # 3 rows
4393"1"
4394"2"
4395"3"
4396> write.table(x, row.names=FALSE)
4397
4398
4399
4400> # note: scan and read.table won't read this as they take empty fields as NA
4401> ## was 1 row in 2.0.1
4402>
4403>
4404> ## More tests of write.table
4405> x <- list(a=1, b=1:2, c=3:4, d=5)
4406> dim(x) <- c(2,2)
4407> x
4408     [,1]      [,2]
4409[1,] 1         integer,2
4410[2,] integer,2 5
4411> write.table(x)
4412"V1" "V2"
4413"1" 1 3:4
4414"2" 1:2 5
4415>
4416> x1 <- data.frame(a=1:2, b=I(matrix(LETTERS[1:4], 2, 2)), c = c("(i)", "(ii)"))
4417> x1
4418  a b.1 b.2    c
44191 1   A   C  (i)
44202 2   B   D (ii)
4421> write.table(x1) # In 2.0.1 had 3 headers, 4 cols
4422"a" "b.1" "b.2" "c"
4423"1" 1 A C "(i)"
4424"2" 2 B D "(ii)"
4425> write.table(x1, quote=c(2,3,4))
4426"a" "b.1" "b.2" "c"
4427"1" 1 "A" "C" "(i)"
4428"2" 2 "B" "D" "(ii)"
4429>
4430> x2 <- data.frame(a=1:2, b=I(list(a=1, b=2)))
4431> x2
4432  a b
4433a 1 1
4434b 2 2
4435> write.table(x2)
4436"a" "b"
4437"a" 1 1
4438"b" 2 2
4439>
4440> x3 <- seq(as.Date("2005-01-01"), len=6, by="day")
4441> x4 <- data.frame(x=1:6, y=x3)
4442> dim(x3) <- c(2,3)
4443> x3
4444[1] "2005-01-01" "2005-01-02" "2005-01-03" "2005-01-04" "2005-01-05"
4445[6] "2005-01-06"
4446> write.table(x3) # matrix, so loses class
4447"V1" "V2" "V3"
4448"1" 12784 12786 12788
4449"2" 12785 12787 12789
4450> x4
4451  x          y
44521 1 2005-01-01
44532 2 2005-01-02
44543 3 2005-01-03
44554 4 2005-01-04
44565 5 2005-01-05
44576 6 2005-01-06
4458> write.table(x4) # preserves class, does not quote
4459"x" "y"
4460"1" 1 2005-01-01
4461"2" 2 2005-01-02
4462"3" 3 2005-01-03
4463"4" 4 2005-01-04
4464"5" 5 2005-01-05
4465"6" 6 2005-01-06
4466> ##
4467>
4468>
4469> ## Problem with earlier regexp code spotted by KH
4470> grep("(.*s){2}", "Arkansas", v = TRUE)
4471[1] "Arkansas"
4472> grep("(.*s){3}", "Arkansas", v = TRUE)
4473character(0)
4474> grep("(.*s){3}", state.name, v = TRUE)
4475[1] "Massachusetts" "Mississippi"
4476> ## Thought Arkansas had 3 s's.
4477>
4478>
4479> ## Replacing part of a non-existent column could create a short column.
4480> xx<- data.frame(a=1:4, b=letters[1:4])
4481> xx[2:3, "c"] <- 2:3
4482> ## gave short column in R < 2.1.0.
4483>
4484>
4485> ## add1/drop1 could give misleading results if missing values were involved
4486> y <- rnorm(1:20)
4487> x <- 1:20; x[10] <- NA
4488> x2 <- runif(20); x2[20] <- NA
4489> fit <- lm(y ~ x)
4490> drop1(fit)
4491Single term deletions
4492
4493Model:
4494y ~ x
4495       Df Sum of Sq     RSS     AIC
4496<none>               9.1728 -9.8358
4497x       1    1.6593 10.8321 -8.6766
4498> res <-  try(stats:::drop1.default(fit))
4499Error in stats:::drop1.default(fit) :
4500  number of rows in use has changed: remove missing values?
4501> stopifnot(inherits(res, "try-error"))
4502> add1(fit, ~ . +x2)
4503Single term additions
4504
4505Model:
4506y ~ x
4507       Df Sum of Sq    RSS     AIC
4508<none>              8.8475 -8.7842
4509x2      1  0.030932 8.8166 -6.8473
4510Warning message:
4511In add1.lm(fit, ~. + x2) : using the 18/19 rows from a combined fit
4512> res <-  try(stats:::add1.default(fit, ~ . +x2))
4513Error in stats:::add1.default(fit, ~. + x2) :
4514  number of rows in use has changed: remove missing values?
4515> stopifnot(inherits(res, "try-error"))
4516> ## 2.0.1 ran and gave incorrect answers.
4517>
4518>
4519> ## (PR#7789) escaped quotes in the first five lines for read.table
4520> tf <- tempfile(tmpdir = getwd())
4521> x <- c("6 'TV2  Shortland Street'",
4522+        "2 'I don\\\'t watch TV at 7'",
4523+        "1 'I\\\'m not bothered, whatever that looks good'",
4524+        "2 'I channel surf'")
4525> writeLines(x, tf)
4526> read.table(tf)
4527  V1                                         V2
45281  6                      TV2  Shortland Street
45292  2                      I don't watch TV at 7
45303  1 I'm not bothered, whatever that looks good
45314  2                             I channel surf
4532> x <- c("6 'TV2  Shortland Street'",
4533+        "2 'I don''t watch TV at 7'",
4534+        "1 'I''m not bothered, whatever that looks good'",
4535+        "2 'I channel surf'")
4536> writeLines(x, tf)
4537> read.table(tf, sep=" ")
4538  V1                                         V2
45391  6                      TV2  Shortland Street
45402  2                      I don't watch TV at 7
45413  1 I'm not bothered, whatever that looks good
45424  2                             I channel surf
4543> unlink(tf)
4544> ## mangled in 2.0.1
4545>
4546>
4547> ## (PR#7802) printCoefmat(signif.legend =FALSE) failed
4548> set.seed(123)
4549> cmat <- cbind(rnorm(3, 10), sqrt(rchisq(3, 12)))
4550> cmat <- cbind(cmat, cmat[,1]/cmat[,2])
4551> cmat <- cbind(cmat, 2*pnorm(-cmat[,3]))
4552> colnames(cmat) <- c("Estimate", "Std.Err", "Z value", "Pr(>z)")
4553> printCoefmat(cmat, signif.stars = TRUE)
4554     Estimate Std.Err Z value    Pr(>z)
4555[1,]  11.3092  2.8636  3.9493 7.837e-05 ***
4556[2,]  11.2301  3.5301  3.1812  0.001467 **
4557[3,]   9.9161  3.0927  3.2063  0.001344 **
4558---
4559Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4560> printCoefmat(cmat, signif.stars = TRUE, signif.legend = FALSE)
4561     Estimate Std.Err Z value    Pr(>z)
4562[1,]  11.3092  2.8636  3.9493 7.837e-05 ***
4563[2,]  11.2301  3.5301  3.1812  0.001467 **
4564[3,]   9.9161  3.0927  3.2063  0.001344 **
4565> # no stars, so no legend
4566> printCoefmat(cmat, signif.stars = FALSE)
4567     Estimate Std.Err Z value    Pr(>z)
4568[1,]  11.3092  2.8636  3.9493 7.837e-05
4569[2,]  11.2301  3.5301  3.1812  0.001467
4570[3,]   9.9161  3.0927  3.2063  0.001344
4571> printCoefmat(cmat, signif.stars = TRUE, signif.legend = TRUE)
4572     Estimate Std.Err Z value    Pr(>z)
4573[1,]  11.3092  2.8636  3.9493 7.837e-05 ***
4574[2,]  11.2301  3.5301  3.1812  0.001467 **
4575[3,]   9.9161  3.0927  3.2063  0.001344 **
4576---
4577Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4578> ## did not work in 2.1.0
4579>
4580>
4581> ## PR#7824 subscripting an array by a matrix
4582> x <- matrix(1:6, ncol=2)
4583> x[rbind(c(1,1), c(2,2))]
4584[1] 1 5
4585> x[rbind(c(1,1), c(2,2), c(0,1))]
4586[1] 1 5
4587> x[rbind(c(1,1), c(2,2), c(0,0))]
4588[1] 1 5
4589> x[rbind(c(1,1), c(2,2), c(0,2))]
4590[1] 1 5
4591> x[rbind(c(1,1), c(2,2), c(0,3))]
4592[1] 1 5
4593> x[rbind(c(1,1), c(2,2), c(1,0))]
4594[1] 1 5
4595> x[rbind(c(1,1), c(2,2), c(2,0))]
4596[1] 1 5
4597> x[rbind(c(1,1), c(2,2), c(3,0))]
4598[1] 1 5
4599> x[rbind(c(1,0), c(0,2), c(3,0))]
4600integer(0)
4601> x[rbind(c(1,0), c(0,0), c(3,0))]
4602integer(0)
4603> x[rbind(c(1,1), c(2,2), c(1,2))]
4604[1] 1 5 4
4605> x[rbind(c(1,1), c(2,NA), c(1,2))]
4606[1]  1 NA  4
4607> x[rbind(c(1,0), c(2,NA), c(1,2))]
4608[1] NA  4
4609> try(x[rbind(c(1,1), c(2,2), c(-1,2))])
4610Error in x[rbind(c(1, 1), c(2, 2), c(-1, 2))] :
4611  negative values are not allowed in a matrix subscript
4612> try(x[rbind(c(1,1), c(2,2), c(-2,2))])
4613Error in x[rbind(c(1, 1), c(2, 2), c(-2, 2))] :
4614  negative values are not allowed in a matrix subscript
4615> try(x[rbind(c(1,1), c(2,2), c(-3,2))])
4616Error in x[rbind(c(1, 1), c(2, 2), c(-3, 2))] :
4617  negative values are not allowed in a matrix subscript
4618> try(x[rbind(c(1,1), c(2,2), c(-4,2))])
4619Error in x[rbind(c(1, 1), c(2, 2), c(-4, 2))] :
4620  negative values are not allowed in a matrix subscript
4621> try(x[rbind(c(1,1), c(2,2), c(-1,-1))])
4622Error in x[rbind(c(1, 1), c(2, 2), c(-1, -1))] :
4623  negative values are not allowed in a matrix subscript
4624> try(x[rbind(c(1,1,1), c(2,2,2))])
4625[1] 1 2 1 2 1 2
4626>
4627> # verify that range checks are applied to negative indices
4628> x <- matrix(1:6, ncol=3)
4629> try(x[rbind(c(1,1), c(2,2), c(-3,3))])
4630Error in x[rbind(c(1, 1), c(2, 2), c(-3, 3))] :
4631  negative values are not allowed in a matrix subscript
4632> try(x[rbind(c(1,1), c(2,2), c(-4,3))])
4633Error in x[rbind(c(1, 1), c(2, 2), c(-4, 3))] :
4634  negative values are not allowed in a matrix subscript
4635> ## generally allowed in 2.1.0.
4636>
4637>
4638> ## printing RAW matrices/arrays was not implemented
4639> s <- sapply(0:7, function(i) rawShift(charToRaw("my text"),i))
4640> s
4641     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
4642[1,]   6d   da   b4   68   d0   a0   40   80
4643[2,]   79   f2   e4   c8   90   20   40   80
4644[3,]   20   40   80   00   00   00   00   00
4645[4,]   74   e8   d0   a0   40   80   00   00
4646[5,]   65   ca   94   28   50   a0   40   80
4647[6,]   78   f0   e0   c0   80   00   00   00
4648[7,]   74   e8   d0   a0   40   80   00   00
4649> dim(s) <- c(7,4,2)
4650> s
4651, , 1
4652
4653     [,1] [,2] [,3] [,4]
4654[1,]   6d   da   b4   68
4655[2,]   79   f2   e4   c8
4656[3,]   20   40   80   00
4657[4,]   74   e8   d0   a0
4658[5,]   65   ca   94   28
4659[6,]   78   f0   e0   c0
4660[7,]   74   e8   d0   a0
4661
4662, , 2
4663
4664     [,1] [,2] [,3] [,4]
4665[1,]   d0   a0   40   80
4666[2,]   90   20   40   80
4667[3,]   00   00   00   00
4668[4,]   40   80   00   00
4669[5,]   50   a0   40   80
4670[6,]   80   00   00   00
4671[7,]   40   80   00   00
4672
4673> ## empty < 2.1.1
4674>
4675>
4676> ## interpretation of '.' directly by model.matrix
4677> dd <- data.frame(a = gl(3,4), b = gl(4,1,12))
4678> model.matrix(~ .^2, data = dd)
4679   (Intercept) a2 a3 b2 b3 b4 a2:b2 a3:b2 a2:b3 a3:b3 a2:b4 a3:b4
46801            1  0  0  0  0  0     0     0     0     0     0     0
46812            1  0  0  1  0  0     0     0     0     0     0     0
46823            1  0  0  0  1  0     0     0     0     0     0     0
46834            1  0  0  0  0  1     0     0     0     0     0     0
46845            1  1  0  0  0  0     0     0     0     0     0     0
46856            1  1  0  1  0  0     1     0     0     0     0     0
46867            1  1  0  0  1  0     0     0     1     0     0     0
46878            1  1  0  0  0  1     0     0     0     0     1     0
46889            1  0  1  0  0  0     0     0     0     0     0     0
468910           1  0  1  1  0  0     0     1     0     0     0     0
469011           1  0  1  0  1  0     0     0     0     1     0     0
469112           1  0  1  0  0  1     0     0     0     0     0     1
4692attr(,"assign")
4693 [1] 0 1 1 2 2 2 3 3 3 3 3 3
4694attr(,"contrasts")
4695attr(,"contrasts")$a
4696[1] "contr.treatment"
4697
4698attr(,"contrasts")$b
4699[1] "contr.treatment"
4700
4701> ## lost ^2 in 2.1.1
4702>
4703>
4704> ## add1.lm and drop.lm did not know about offsets (PR#8049)
4705> set.seed(2)
4706> y <- rnorm(10)
4707> z <- 1:10
4708> lm0 <- lm(y ~ 1)
4709> lm1 <- lm(y ~ 1, offset = 1:10)
4710> lm2 <- lm(y ~ z, offset = 1:10)
4711>
4712> add1(lm0, scope = ~ z)
4713Single term additions
4714
4715Model:
4716y ~ 1
4717       Df  Sum of Sq    RSS      AIC
4718<none>               6.3161 -2.59479
4719z       1 0.00029765 6.3158 -0.59526
4720> anova(lm1, lm2)
4721Analysis of Variance Table
4722
4723Model 1: y ~ 1
4724Model 2: y ~ z
4725  Res.Df    RSS Df Sum of Sq     F    Pr(>F)
47261      9 89.130
47272      8  6.316  1    82.814 104.9 7.099e-06 ***
4728---
4729Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
4730> add1(lm1, scope = ~ z)
4731Single term additions
4732
4733Model:
4734y ~ 1
4735       Df Sum of Sq    RSS     AIC
4736<none>              89.130 23.8751
4737z       1    82.814  6.316 -0.5953
4738> drop1(lm2)
4739Single term deletions
4740
4741Model:
4742y ~ z
4743       Df Sum of Sq    RSS     AIC
4744<none>               6.316 -0.5953
4745z       1    82.814 89.130 23.8751
4746> ## Last two ignored the offset in 2.1.1
4747>
4748>
4749> ## tests of raw conversion
4750> as.raw(1234)
4751[1] 00
4752Warning message:
4753out-of-range values treated as 0 in coercion to raw
4754> as.raw(list(a=1234))
4755[1] 00
4756Warning message:
4757out-of-range values treated as 0 in coercion to raw
4758> ## 2.1.1: spurious and missing messages, wrong result for second.
4759>
4760>
4761> ### end of tests added in 2.1.1 patched ###
4762>
4763>
4764> ## Tests of logical matrix indexing with NAs
4765> df1 <- data.frame(a = c(NA, 0, 3, 4)); m1 <- as.matrix(df1)
4766> df2 <- data.frame(a = c(NA, 0, 0, 4)); m2 <- as.matrix(df2)
4767> df1[df1 == 0] <- 2; df1
4768   a
47691 NA
47702  2
47713  3
47724  4
4773> m1[m1 == 0] <- 2;   m1
4774      a
4775[1,] NA
4776[2,]  2
4777[3,]  3
4778[4,]  4
4779> df2[df2 == 0] <- 2; df2  # not allowed in 2.{0,1}.z
4780   a
47811 NA
47822  2
47833  2
47844  4
4785> m2[m2 == 0] <- 2;   m2
4786      a
4787[1,] NA
4788[2,]  2
4789[3,]  2
4790[4,]  4
4791> df1[df1 == 2] # this is first coerced to a matrix, and drops to a vector
4792[1] NA  2
4793> df3 <- data.frame(a=1:2, b=2:3)
4794> df3[df3 == 2]            # had spurious names
4795[1] 2 2
4796> # but not allowed
4797> ## (modified to make printed result the same whether numeric() is
4798> ##  compiled or interpreted)
4799> ## try(df2[df2 == 2] <- 1:2)
4800> ## try(m2[m2 == 2] <- 1:2)
4801> tryCatch(df2[df2 == 2] <- 1:2,
4802+          error = function(e) paste("Error:", conditionMessage(e)))
4803[1] "Error: NAs are not allowed in subscripted assignments"
4804> tryCatch(m2[m2 == 2] <- 1:2,
4805+          error = function(e) paste("Error:", conditionMessage(e)))
4806[1] "Error: NAs are not allowed in subscripted assignments"
4807> ##
4808>
4809>
4810> ## vector indexing of matrices: issue is when rownames are used
4811> # 1D array
4812> m1 <- c(0,1,2,0)
4813> dim(m1) <- 4
4814> dimnames(m1) <- list(1:4)
4815> m1[m1 == 0]                        # has rownames
48161 4
48170 0
4818> m1[which(m1 == 0)]                 # has rownames
48191 4
48200 0
4821> m1[which(m1 == 0, arr.ind = TRUE)] # no names < 2.2.0 (side effect of PR#937)
48221 4
48230 0
4824>
4825> # 2D array with 2 cols
4826> m2 <- as.matrix(data.frame(a=c(0,1,2,0), b=0:3))
4827> m2[m2 == 0]                        # a vector, had names < 2.2.0
4828[1] 0 0 0
4829> m2[which(m2 == 0)]                 # a vector, had names < 2.2.0
4830[1] 0 0 0
4831> m2[which(m2 == 0, arr.ind = TRUE)] # no names (PR#937)
4832[1] 0 0 0
4833>
4834> # 2D array with one col: could use rownames but do not.
4835> m21 <- m2[, 1, drop = FALSE]
4836> m21[m21 == 0]
4837[1] 0 0
4838> m21[which(m21 == 0)]
4839[1] 0 0
4840> m21[which(m21 == 0, arr.ind = TRUE)]
4841[1] 0 0
4842> ## not consistent < 2.2.0: S never gives names
4843>
4844>
4845> ## tests of indexing as quoted in Extract.Rd
4846> x <- NULL
4847> x$foo <- 2
4848> x # now, a list
4849$foo
4850[1] 2
4851
4852> x <- NULL
4853> x[[2]] <- pi
4854> x # now, a list, too
4855[[1]]
4856NULL
4857
4858[[2]]
4859[1] 3.141593
4860
4861> x <- NULL
4862> x[[1]] <- 1:3
4863> x # list
4864[[1]]
4865[1] 1 2 3
4866
4867> ##
4868>
4869>
4870> ## printing of a kernel:
4871> kernel(1)
4872unknown
4873coef[0] = 1
4874> ## printed wrongly in R <= 2.1.1
4875>
4876>
4877> ## using NULL as a replacement value
4878> DF <- data.frame(A=1:2, B=3:4)
4879> try(DF[2, 1:3] <- NULL)
4880Error in x[[jj]][iseq] <- vjj : replacement has length zero
4881> ## wrong error message in R < 2.2.0
4882>
4883>
4884> ## tests of signif
4885> ob <- 0:9 * 2000
4886> print(signif(ob, 3), digits=17) # had rounding error in 2.1.1
4887 [1]     0  2000  4000  6000  8000 10000 12000 14000 16000 18000
4888> signif(1.2347e-305, 4)
4889[1] 1.235e-305
4890> signif(1.2347e-306, 4)  # only 3 digits in 2.1.1
4891[1] 1.235e-306
4892> signif(1.2347e-307, 4)
4893[1] 1.235e-307
4894> ##
4895>
4896> ### end of tests added in 2.2.0 patched ###
4897>
4898>
4899> ## printing lists with NA names
4900> A <- list(1, 2)
4901> names(A) <- c("NA", NA)
4902> A
4903$`NA`
4904[1] 1
4905
4906$<NA>
4907[1] 2
4908
4909> ## both printed as "NA" in 2.2.0
4910>
4911>
4912> ## subscripting with both NA and "NA" names
4913> x <- 1:4
4914> names(x) <- c(NA, "NA", "a", "")
4915> x[names(x)]
4916<NA>   NA    a <NA>
4917  NA    2    3   NA
4918> ## 2.2.0 had the second matching the first.
4919> lx <- as.list(x)
4920> lx[[as.character(NA)]]
4921NULL
4922> lx[as.character(NA)]
4923$<NA>
4924NULL
4925
4926> ## 2.2.0 had both matching element 1
4927>
4928>
4929> ## data frame replacement subscripting
4930> # Charles C. Berry, R-devel, 2005-10-26
4931> a.frame <- data.frame( x=letters[1:5] )
4932> a.frame[ 2:5, "y" ] <- letters[2:5]
4933> a.frame  # added rows 1:4
4934  x    y
49351 a <NA>
49362 b    b
49373 c    c
49384 d    d
49395 e    e
4940> # and adding and replacing matrices failed
4941> a.frame[ ,"y" ] <- matrix(1:10, 5, 2)
4942> a.frame
4943  x y.1 y.2
49441 a   1   6
49452 b   2   7
49463 c   3   8
49474 d   4   9
49485 e   5  10
4949> a.frame[3:5 ,"y" ] <- matrix(1:6, 3, 2)
4950> a.frame
4951  x y.1 y.2
49521 a   1   6
49532 b   2   7
49543 c   1   4
49554 d   2   5
49565 e   3   6
4957> a.frame <- data.frame( x=letters[1:5] )
4958> a.frame[3:5 ,"y" ] <- matrix(1:6, 3, 2)
4959> a.frame
4960  x y.1 y.2
49611 a  NA  NA
49622 b  NA  NA
49633 c   1   4
49644 d   2   5
49655 e   3   6
4966> ## failed/wrong ans in 2.2.0
4967>
4968>
4969> ### end of tests added in 2.2.0 patched ###
4970>
4971>
4972> ## test of fix of trivial warning PR#8252
4973> pairs(iris[1:4], oma=rep(3,4))
4974> ## warned in 2.2.0 only
4975>
4976>
4977> ## str(<dendrogram>)
4978> dend <- as.dendrogram(hclust(dist(USArrests), "ave")) # "print()" method
4979> dend2 <- cut(dend, h=70)
4980> str(dend2$upper)
4981--[dendrogram w/ 2 branches and 4 members at h = 152]
4982  |--[dendrogram w/ 2 branches and 2 members at h = 77.6]
4983  |  |--leaf "Branch 1" (h= 38.5 midpoint = 0.5, x.member = 2 )
4984  |  `--leaf "Branch 2" (h= 44.3 midpoint = 5.03, x.member = 14 )
4985  `--[dendrogram w/ 2 branches and 2 members at h = 89.2]
4986     |--leaf "Branch 3" (h= 44.8 midpoint = 6.8, x.member = 14 )
4987     `--leaf "Branch 4" (h= 54.7 midpoint = 7.65, x.member = 20 )
4988> ## {{for Emacs: `}}  gave much too many spaces in 2.2.[01]
4989>
4990>
4991> ## formatC on Windows (PR#8337)
4992> xx  <- pi * 10^(-5:4)
4993> cbind(formatC(xx, wid = 9))
4994      [,1]
4995 [1,] "3.142e-05"
4996 [2,] "0.0003142"
4997 [3,] " 0.003142"
4998 [4,] "  0.03142"
4999 [5,] "   0.3142"
5000 [6,] "    3.142"
5001 [7,] "    31.42"
5002 [8,] "    314.2"
5003 [9,] "     3142"
5004[10,] "3.142e+04"
5005> cbind(formatC(xx, wid = 9, flag = "-"))
5006      [,1]
5007 [1,] "3.142e-05"
5008 [2,] "0.0003142"
5009 [3,] "0.003142 "
5010 [4,] "0.03142  "
5011 [5,] "0.3142   "
5012 [6,] "3.142    "
5013 [7,] "31.42    "
5014 [8,] "314.2    "
5015 [9,] "3142     "
5016[10,] "3.142e+04"
5017> cbind(formatC(xx, wid = 9, flag = "0"))
5018      [,1]
5019 [1,] "3.142e-05"
5020 [2,] "0.0003142"
5021 [3,] "00.003142"
5022 [4,] "000.03142"
5023 [5,] "0000.3142"
5024 [6,] "00003.142"
5025 [7,] "000031.42"
5026 [8,] "0000314.2"
5027 [9,] "000003142"
5028[10,] "3.142e+04"
5029> ## extra space on 2.2.1
5030>
5031>
5032> ## an impossible glm fit
5033> success <- c(13,12,11,14,14,11,13,11,12)
5034> failure <- c(0,0,0,0,0,0,0,2,2)
5035> predictor <- c(0, 5^(0:7))
5036> try(glm(cbind(success,failure) ~ 0+predictor, family = binomial(link="log")))
5037Error : no valid set of coefficients has been found: please supply starting values
5038> # no coefficient is possible as the first case will have mu = 1
5039> ## 2.2.1 gave a subscript out of range warning instead.
5040>
5041>
5042> ## error message from solve (PR#8494)
5043> temp <- diag(1, 5)[, 1:4]
5044> rownames(temp) <- as.character(1:5)
5045> colnames(temp) <- as.character(1:4)
5046> try(solve(temp))
5047Error in solve.default(temp) : 'a' (5 x 4) must be square
5048> # also complex
5049> try(solve(temp+0i))
5050Error in solve.default(temp + (0+0i)) : 'a' (5 x 4) must be square
5051> # and non-comformant systems
5052> try(solve(temp, diag(3)))
5053Error in solve.default(temp, diag(3)) : 'a' (5 x 4) must be square
5054> ## gave errors from rownames<- in 2.2.1
5055>
5056>
5057> ## PR#8462 terms.formula(simplify = TRUE) needs parentheses.
5058> update.formula (Reaction ~ Days + (Days | Subject), . ~ . + I(Days^2))
5059Reaction ~ Days + (Days | Subject) + I(Days^2)
5060> ## < 2.3.0 dropped parens on second term.
5061>
5062>
5063> ## PR#8528: errors in the post-2.1.0 pgamma
5064> pgamma(seq(0.75, 1.25, by=0.05)*1e100, shape = 1e100, log=TRUE)
5065 [1] -3.768207e+98 -2.314355e+98 -1.251893e+98 -5.360516e+97 -1.293294e+97
5066 [6] -6.931472e-01  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
5067[11]  0.000000e+00
5068> pgamma(seq(0.75, 1.25, by=0.05)*1e100, shape = 1e100, log=TRUE, lower=FALSE)
5069 [1]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
5070 [6] -6.931472e-01 -1.209836e+97 -4.689820e+97 -1.023806e+98 -1.767844e+98
5071[11] -2.685645e+98
5072> pgamma(c(1-1e-10, 1+1e-10)*1e100, shape = 1e100)
5073[1] 0 1
5074> pgamma(0.9*1e25, 1e25, log=TRUE)
5075[1] -5.360516e+22
5076> ## were NaN, -Inf etc in 2.2.1.
5077>
5078>
5079> ## + for POSIXt objects was non-commutative
5080> # SPSS-style dates
5081> c(10485849600,10477641600,10561104000,10562745600)+ISOdate(1582,10,14)
5082[1] "1915-01-26 12:00:00 GMT" "1914-10-23 12:00:00 GMT"
5083[3] "1917-06-15 12:00:00 GMT" "1917-07-04 12:00:00 GMT"
5084> ## was in the local time zone in 2.2.1.
5085>
5086>
5087> ## Limiting lines on deparse (wishlist PR#8638)
5088> op <- options(deparse.max.lines = 3)
5089> f <- function(...) browser()
5090> do.call(f, mtcars)
5091Called from: (function (...)
5092browser())(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4,
509322.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, 30.4,
5094  ...
5095Browse[1]> c
5096>
5097> op <- c(op, options(error = expression(NULL)))
5098> f <- function(...) stop()
5099> do.call(f, mtcars)
5100Error in (function (...)  :
5101Calls: do.call -> <Anonymous>
5102> traceback()
51033: stop()
51042: (function (...)
5105   stop())(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8,
5106   19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4, 14.7, 32.4, 30.4, 33.9,
5107    ...
51081: do.call(f, mtcars)
5109>
5110> ## Debugger can handle a function that has a single function call as its body
5111> g <- function(fun) fun(1)
5112> debug(g)
5113> g(function(x) x+1)
5114debugging in: g(function(x) x + 1)
5115debug: fun(1)
5116Browse[2]>
5117exiting from: g(function(x) x + 1)
5118[1] 2
5119> options(op)
5120> ## unlimited < 2.3.0
5121>
5122>
5123> ## row names in as.table (PR#8652)
5124> as.table(matrix(1:60, ncol=2))
5125    A  B
5126A   1 31
5127B   2 32
5128C   3 33
5129D   4 34
5130E   5 35
5131F   6 36
5132G   7 37
5133H   8 38
5134I   9 39
5135J  10 40
5136K  11 41
5137L  12 42
5138M  13 43
5139N  14 44
5140O  15 45
5141P  16 46
5142Q  17 47
5143R  18 48
5144S  19 49
5145T  20 50
5146U  21 51
5147V  22 52
5148W  23 53
5149X  24 54
5150Y  25 55
5151Z  26 56
5152A1 27 57
5153B1 28 58
5154C1 29 59
5155D1 30 60
5156> ## rows past 26 had NA row names
5157>
5158>
5159> ## summary on a glm with zero weights and estimated dispersion (PR#8720)
5160> y <- rnorm(10)
5161> x <- 1:10
5162> w <- c(rep(1,9), 0)
5163> summary(glm(y ~ x, weights = w))
5164
5165Call:
5166glm(formula = y ~ x, weights = w)
5167
5168Deviance Residuals:
5169    Min       1Q   Median       3Q      Max
5170-1.7806  -0.1416   0.1863   0.5690   1.2057
5171
5172Coefficients:
5173            Estimate Std. Error t value Pr(>|t|)
5174(Intercept)  -0.7532     0.7862  -0.958    0.370
5175x             0.1311     0.1397   0.938    0.379
5176
5177(Dispersion parameter for gaussian family taken to be 1.17125)
5178
5179    Null deviance: 9.2298  on 8  degrees of freedom
5180Residual deviance: 8.1988  on 7  degrees of freedom
5181AIC: Inf
5182
5183Number of Fisher Scoring iterations: 2
5184
5185Warning message:
5186In summary.glm(glm(y ~ x, weights = w)) :
5187  observations with zero weight not used for calculating dispersion
5188> summary(glm(y ~ x, subset = w > 0))
5189
5190Call:
5191glm(formula = y ~ x, subset = w > 0)
5192
5193Deviance Residuals:
5194    Min       1Q   Median       3Q      Max
5195-1.7806  -0.1582   0.3726   0.5896   1.2057
5196
5197Coefficients:
5198            Estimate Std. Error t value Pr(>|t|)
5199(Intercept)  -0.7532     0.7862  -0.958    0.370
5200x             0.1311     0.1397   0.938    0.379
5201
5202(Dispersion parameter for gaussian family taken to be 1.17125)
5203
5204    Null deviance: 9.2298  on 8  degrees of freedom
5205Residual deviance: 8.1988  on 7  degrees of freedom
5206AIC: 30.702
5207
5208Number of Fisher Scoring iterations: 2
5209
5210> ## has NA dispersion in 2.2.1
5211>
5212>
5213> ## substitute was losing "..." after r37269
5214> yaa <- function(...) substitute(list(...))
5215> yaa(foo(...))
5216list(foo(...))
5217> ## and wasn't substituting after "..."
5218> substitute(list(..., x), list(x=1))
5219list(..., 1)
5220> ## fixed for 2.3.0
5221>
5222>
5223> ## uniroot never warned (PR#8750)
5224> ff <- function(x) (x-pi)^3
5225> uniroot(ff, c(-10,10), maxiter=10)
5226$root
5227[1] 3.291126
5228
5229$f.root
5230[1] 0.003343587
5231
5232$iter
5233[1] 10
5234
5235$init.it
5236[1] NA
5237
5238$estim.prec
5239[1] 0.8295023
5240
5241Warning message:
5242In uniroot(ff, c(-10, 10), maxiter = 10) : _NOT_ converged in 10 iterations
5243> ## should warn, did not < 2.3.0
5244>
5245>
5246> ### end of tests added in 2.3.0 ###
5247>
5248>
5249> ## prod etc on empty lists and raw vectors
5250> try(min(list()))
5251Error in min(list()) : invalid 'type' (list) of argument
5252> try(max(list()))
5253Error in max(list()) : invalid 'type' (list) of argument
5254> try(sum(list()))
5255Error in sum(list()) : invalid 'type' (list) of argument
5256> try(prod(list()))
5257Error in prod(list()) : invalid 'type' (list) of argument
5258> try(min(raw()))
5259Error in min(raw()) : invalid 'type' (raw) of argument
5260> try(max(raw()))
5261Error in max(raw()) : invalid 'type' (raw) of argument
5262> try(sum(raw()))
5263Error in sum(raw()) : invalid 'type' (raw) of argument
5264> try(prod(raw()))
5265Error in prod(raw()) : invalid 'type' (raw) of argument
5266> ## Inf, -Inf, list(NULL) etc in 2.2.1
5267>
5268> r <- hist(rnorm(100), plot = FALSE, breaks = 12,
5269+           ## arguments which don't make sense for plot=FALSE - give a warning:
5270+           xlab = "N(0,1)", col = "blue")
5271Warning message:
5272In hist.default(rnorm(100), plot = FALSE, breaks = 12, xlab = "N(0,1)",  :
5273  arguments 'col', 'xlab' are not made use of
5274> ## gave no warning in 2.3.0 and earlier
5275>
5276>
5277> ## rbind.data.frame on permuted cols (PR#8868)
5278> d1 <- data.frame(x=1:10, y=letters[1:10], z=1:10)
5279> d2 <- data.frame(y=LETTERS[1:5], z=5:1, x=7:11)
5280> rbind(d1, d2)
5281    x y  z
52821   1 a  1
52832   2 b  2
52843   3 c  3
52854   4 d  4
52865   5 e  5
52876   6 f  6
52887   7 g  7
52898   8 h  8
52909   9 i  9
529110 10 j 10
529211  7 A  5
529312  8 B  4
529413  9 C  3
529514 10 D  2
529615 11 E  1
5297> # got factor y  wrong in 2.3.0
5298> # and failed with duplicated col names.
5299> d1 <- data.frame(x=1:2, y=5:6, x=8:9, check.names=FALSE)
5300> d2 <- data.frame(x=3:4, x=-(1:2), y=8:9, check.names=FALSE)
5301> rbind(d1, d2)
5302  x y  x
53031 1 5  8
53042 2 6  9
53053 3 8 -1
53064 4 9 -2
5307> ## corrupt in 2.3.0
5308>
5309>
5310> ## sort.list on complex vectors was unimplemented prior to 2.4.0
5311> x <- rep(2:1, c(2, 2)) + 1i*c(4, 1, 2, 3)
5312> (o <- sort.list(x))
5313[1] 3 4 2 1
5314> x[o]
5315[1] 1+2i 1+3i 2+1i 2+4i
5316> sort(x)  # for a cross-check
5317[1] 1+2i 1+3i 2+1i 2+4i
5318> ##
5319>
5320>
5321> ## PR#9044 write.table(quote=TRUE, row.names=FALSE) did not quote column names
5322> m <- matrix(1:9, nrow=3, dimnames=list(c("A","B","C"),  c("I","II","III")))
5323> write.table(m)
5324"I" "II" "III"
5325"A" 1 4 7
5326"B" 2 5 8
5327"C" 3 6 9
5328> write.table(m, col.names=FALSE)
5329"A" 1 4 7
5330"B" 2 5 8
5331"C" 3 6 9
5332> write.table(m, row.names=FALSE)
5333"I" "II" "III"
53341 4 7
53352 5 8
53363 6 9
5337> # wrong < 2.3.1 patched.
5338> write.table(m, quote=FALSE)
5339I II III
5340A 1 4 7
5341B 2 5 8
5342C 3 6 9
5343> write.table(m, col.names=FALSE, quote=FALSE)
5344A 1 4 7
5345B 2 5 8
5346C 3 6 9
5347> write.table(m, row.names=FALSE, quote=FALSE)
5348I II III
53491 4 7
53502 5 8
53513 6 9
5352> d <- as.data.frame(m)
5353> write.table(d)
5354"I" "II" "III"
5355"A" 1 4 7
5356"B" 2 5 8
5357"C" 3 6 9
5358> write.table(d, col.names=FALSE)
5359"A" 1 4 7
5360"B" 2 5 8
5361"C" 3 6 9
5362> write.table(d, row.names=FALSE)
5363"I" "II" "III"
53641 4 7
53652 5 8
53663 6 9
5367> write.table(d, quote=FALSE)
5368I II III
5369A 1 4 7
5370B 2 5 8
5371C 3 6 9
5372> write.table(d, col.names=FALSE, quote=FALSE)
5373A 1 4 7
5374B 2 5 8
5375C 3 6 9
5376> write.table(d, row.names=FALSE, quote=FALSE)
5377I II III
53781 4 7
53792 5 8
53803 6 9
5381> write.table(m, quote=numeric(0)) # not the same as FALSE
5382"I" "II" "III"
5383"A" 1 4 7
5384"B" 2 5 8
5385"C" 3 6 9
5386> ##
5387>
5388>
5389> ## removing variable from baseenv
5390> try(remove("ls", envir=baseenv()))
5391Error in remove("ls", envir = baseenv()) :
5392  cannot remove variables from the base environment
5393> try(remove("ls", envir=asNamespace("base")))
5394Error in remove("ls", envir = asNamespace("base")) :
5395  cannot remove variables from base namespace
5396> ## no message in 2.3.1
5397>
5398>
5399> ## tests of behaviour of factors
5400> (x <- factor(LETTERS[1:5])[2:4])
5401[1] B C D
5402Levels: A B C D E
5403> x[2]
5404[1] C
5405Levels: A B C D E
5406> x[[2]]
5407[1] C
5408Levels: A B C D E
5409> stopifnot(identical(x[2], x[[2]]))
5410> as.list(x)
5411[[1]]
5412[1] B
5413Levels: A B C D E
5414
5415[[2]]
5416[1] C
5417Levels: A B C D E
5418
5419[[3]]
5420[1] D
5421Levels: A B C D E
5422
5423> (xx <- unlist(as.list(x)))
5424[1] B C D
5425Levels: A B C D E
5426> stopifnot(identical(x, xx))
5427> as.vector(x, "list")
5428[[1]]
5429[1] B
5430Levels: A B C D E
5431
5432[[2]]
5433[1] C
5434Levels: A B C D E
5435
5436[[3]]
5437[1] D
5438Levels: A B C D E
5439
5440> (sx <- sapply(x, function(.).))
5441[1] B C D
5442Levels: A B C D E
5443> stopifnot(identical(x, sx))
5444> ## changed in 2.4.0
5445>
5446>
5447> ## as.character on a factor with "NA" level
5448> as.character(as.factor(c("AB", "CD", NA)))
5449[1] "AB" "CD" NA
5450> as.character(as.factor(c("NA", "CD", NA)))  # use <NA> is 2.3.x
5451[1] "NA" "CD" NA
5452> as.vector(as.factor(c("NA", "CD", NA)))     # but this did not
5453[1] "NA" "CD" NA
5454> ## used <NA> before
5455>
5456>
5457> ## [ on a zero-column data frame, names of such
5458> data.frame()[FALSE]
5459data frame with 0 columns and 0 rows
5460> names(data.frame())
5461character(0)
5462> # gave NULL names and hence spurious warning.
5463>
5464>
5465> ## residuals from zero-weight glm fits
5466> d.AD <- data.frame(treatment = gl(3,3), outcome = gl(3,1,9),
5467+                    counts = c(18,17,15,20,10,20,25,13,12))
5468> fit <- glm(counts ~ outcome + treatment, family = poisson,
5469+            data = d.AD, weights = c(0, rep(1,8)))
5470> print(residuals(fit, type="working"),
5471+       width = 37) # first was NA < 2.4.0 //  using new 'width'
5472          1           2           3
5473-0.31250000  0.15546875 -0.13231383
5474          4           5           6
5475-0.11111111 -0.20909091  0.34622824
5476          7           8           9
5477 0.11111111  0.02818182 -0.19226306
5478> ## working residuals were NA for zero-weight cases.
5479> fit2 <- glm(counts ~ outcome + treatment, family = poisson,
5480+             data = d.AD, weights = c(0, rep(1,8)), y = FALSE)
5481> for(z in c("response", "working", "deviance", "pearson"))
5482+     stopifnot(all.equal(residuals(fit, type=z), residuals(fit2, type=z),
5483+                         scale = 1, tolerance = 1e-10))
5484>
5485> ## apply on arrays with zero extents
5486> ## Robin Hankin, R-help, 2006-02-13
5487> A <- array(0, c(3, 0, 4))
5488> dimnames(A) <- list(D1 = letters[1:3], D2 = NULL, D3 = LETTERS[1:4])
5489> f <- function(x) 5
5490> apply(A, 1:2, f)
5491   D2
5492D1
5493  a
5494  b
5495  c
5496> apply(A, 1, f)
5497a b c
54985 5 5
5499> apply(A, 2, f)
5500numeric(0)
5501> ## dropped dims in 2.3.1
5502>
5503>
5504> ## print a factor with names
5505> structure(factor(1:4), names = letters[1:4])
5506a b c d
55071 2 3 4
5508Levels: 1 2 3 4
5509> ## dropped names < 2.4.0
5510>
5511>
5512> ## some tests of factor matrices
5513> A <- factor(7:12)
5514> dim(A) <- c(2, 3)
5515> A
5516     [,1] [,2] [,3]
5517[1,] 7    9    11
5518[2,] 8    10   12
5519Levels: 7 8 9 10 11 12
5520> str(A)
5521 Factor[1:2, 1:3] w/ 6 levels "7","8","9","10",..: 1 2 3 4 5 6
5522> A[, 1:2]
5523     [,1] [,2]
5524[1,] 7    9
5525[2,] 8    10
5526Levels: 7 8 9 10 11 12
5527> A[, 1:2, drop=TRUE]
5528[1] 7  8  9  10
5529Levels: 7 8 9 10
5530> A[1,1] <- "9"
5531> A
5532     [,1] [,2] [,3]
5533[1,] 9    9    11
5534[2,] 8    10   12
5535Levels: 7 8 9 10 11 12
5536> ## misbehaved < 2.4.0
5537>
5538>
5539> ## [dpqr]t with vector ncp
5540> nc <- c(0, 0.0001, 1)
5541> dt(1.8, 10, nc)
5542[1] 0.08311639 0.08312972 0.26650393
5543> pt(1.8, 10, nc)
5544[1] 0.9489739 0.9489641 0.7584267
5545> qt(0.95, 10, nc)
5546[1] 1.812461 1.812579 3.041742
5547> ## gave warnings in 2.3.1, short answer for qt.
5548> dt(1.8, 10, -nc[-1])
5549[1] 0.08310306 0.01074629
5550> pt(1.8, 10, -nc[-1])
5551[1] 0.9489837 0.9949472
5552> qt(0.95, 10, -nc[-1])
5553[1] 1.8123429 0.6797902
5554> ## qt in 2.3.1 did not allow negative ncp.
5555>
5556>
5557> ## merge() used to insert row names as factor, not character, so
5558> ## sorting was unexpected.
5559> A <- data.frame(a = 1:4)
5560> row.names(A) <- c("2002-11-15", "2002-12-15", "2003-01-15", "2003-02-15")
5561> B <- data.frame(b = 1:4)
5562> row.names(B) <- c("2002-09-15", "2002-10-15", "2002-11-15", "2002-12-15")
5563> merge(A, B, by=0, all=TRUE)
5564   Row.names  a  b
55651 2002-09-15 NA  1
55662 2002-10-15 NA  2
55673 2002-11-15  1  3
55684 2002-12-15  2  4
55695 2003-01-15  3 NA
55706 2003-02-15  4 NA
5571>
5572>
5573> ## assigning to a list loop index could alter the index (PR#9216)
5574> L <- list(a = list(txt = "original value"))
5575> f <- function(LL) {
5576+     for (ll in LL) ll$txt <- "changed in f"
5577+     LL
5578+ }
5579> f(L)
5580$a
5581$a$txt
5582[1] "original value"
5583
5584
5585> L
5586$a
5587$a$txt
5588[1] "original value"
5589
5590
5591> ## both were changed < 2.4.0
5592>
5593>
5594> ## summary.mlm misbehaved with na.action = na.exclude
5595> n <- 50
5596> x <- runif(n=n)
5597> y1 <- 2 * x + rnorm(n=n)
5598> y2 <- 5 * x + rnorm(n=n)
5599> y2[sample(1:n, size=5)] <- NA
5600> y <- cbind(y1, y2)
5601> fit <- lm(y ~ 1, na.action="na.exclude")
5602> summary(fit)
5603Response y1 :
5604
5605Call:
5606lm(formula = y1 ~ 1, na.action = "na.exclude")
5607
5608Residuals:
5609    Min      1Q  Median      3Q     Max
5610-3.2359 -0.8766  0.2338  0.9944  2.5905
5611
5612Coefficients:
5613            Estimate Std. Error t value Pr(>|t|)
5614(Intercept)   1.1419     0.1966   5.808 6.47e-07 ***
5615---
5616Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
5617
5618Residual standard error: 1.319 on 44 degrees of freedom
5619  (5 observations deleted due to missingness)
5620
5621
5622Response y2 :
5623
5624Call:
5625lm(formula = y2 ~ 1, na.action = "na.exclude")
5626
5627Residuals:
5628    Min      1Q  Median      3Q     Max
5629-4.2822 -1.2548  0.4364  1.2185  3.8575
5630
5631Coefficients:
5632            Estimate Std. Error t value Pr(>|t|)
5633(Intercept)   2.7098     0.2798   9.685 1.77e-12 ***
5634---
5635Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
5636
5637Residual standard error: 1.877 on 44 degrees of freedom
5638  (5 observations deleted due to missingness)
5639
5640
5641> ## failed < 2.4.0
5642>
5643> RNGkind("default","default")## reset to default - ease  R core
5644>
5645> ## prettyNum lost attributes (PR#8695)
5646> format(matrix(1:16, 4), big.mark = ",")
5647     [,1] [,2] [,3] [,4]
5648[1,] " 1" " 5" " 9" "13"
5649[2,] " 2" " 6" "10" "14"
5650[3,] " 3" " 7" "11" "15"
5651[4,] " 4" " 8" "12" "16"
5652> ## was a vector < 2.4.0
5653>
5654>
5655> ## printing of complex numbers of very different magnitudes
5656> 1e100  + 1e44i
5657[1] 1e+100+0e+00i
5658> 1e100 + pi*1i*10^(c(-100,0,1,40,100))
5659[1] 1e+100+ 0.000000e+00i 1e+100+ 0.000000e+00i 1e+100+ 0.000000e+00i
5660[4] 1e+100+ 0.000000e+00i 1e+100+3.141593e+100i
5661> ## first was silly, second not rounded correctly in 2.2.0 - 2.3.1
5662> ## We don't get them lining up, but that is a printf issue
5663> ## that only happens for very large complex nos.
5664>
5665>
5666> ### end of tests added in 2.4.0 ###
5667>
5668>
5669> ## Platform-specific behaviour in lowess reported to R-help
5670> ## 2006-10-12 by Frank Harrell
5671> x <- c(0,7,8,14,15,120,242)
5672> y <- c(122,128,130,158,110,110,92)
5673> lowess(x, y, iter=0)
5674$x
5675[1]   0   7   8  14  15 120 242
5676
5677$y
5678[1] 121.95735 128.00000 131.06649 136.93673 126.76467 109.99903  92.00003
5679
5680> lowess(x, y)
5681$x
5682[1]   0   7   8  14  15 120 242
5683
5684$y
5685[1] 122 128 128 158 110 110  92
5686
5687> ## MAD of iterated residuals was zero, and result depended on the platform.
5688>
5689>
5690> ## PR#9263: problems with R_Visible
5691> a <- list(b=5)
5692> a[[(t<-'b')]]
5693[1] 5
5694> x <- matrix(5:-6, 3)
5695> x[2, invisible(3)]
5696[1] -2
5697> ## both invisible in 2.4.0
5698>
5699>
5700> ### end of tests added in 2.4.1 ###
5701>
5702>
5703> ## tests of deparsing
5704> x <-list(a = NA, b = as.integer(NA), c=0+NA, d=0i+NA,
5705+          e = 1, f = 1:1, g = 1:3, h = c(NA, 1:3),
5706+          i = as.character(NA), j = c("foo", NA, "bar")
5707+          )
5708> dput(x, control=NULL)
5709list(NA, NA, NA, NA, 1, 1, 1:3, c(NA, 1, 2, 3), NA, c("foo",
5710NA, "bar"))
5711> dput(x, control="keepInteger")
5712list(NA, NA_integer_, NA, NA, 1, 1L, 1:3, c(NA, 1L, 2L, 3L),
5713    NA, c("foo", NA, "bar"))
5714> dput(x, control="keepNA")
5715list(NA, NA_integer_, NA_real_, NA_complex_, 1, 1, 1:3, c(NA,
57161, 2, 3), NA_character_, c("foo", NA, "bar"))
5717> dput(x)
5718list(a = NA, b = NA_integer_, c = NA_real_, d = NA_complex_,
5719    e = 1, f = 1L, g = 1:3, h = c(NA, 1L, 2L, 3L), i = NA_character_,
5720    j = c("foo", NA, "bar"))
5721> dput(x, control="all")
5722list(a = NA, b = NA_integer_, c = NA_real_, d = NA_complex_,
5723    e = 1, f = 1L, g = 1:3, h = c(NA, 1L, 2L, 3L), i = NA_character_,
5724    j = c("foo", NA, "bar"))
5725> dput(x, control=c("all", "S_compatible"))
5726list(a = NA, b = as.integer(NA), c = as.double(NA), d = as.complex(NA),
5727    e = 1., f = as.integer(1), g = 1:3, h = as.integer(c(NA,
5728    1, 2, 3)), i = as.character(NA), j = c("foo", NA, "bar"))
5729> tmp <- tempfile(tmpdir = getwd())
5730> dput(x, tmp, control="all")
5731> stopifnot(identical(dget(tmp), x))
5732> dput(x, tmp, control=c("all", "S_compatible"))
5733> stopifnot(identical(dget(tmp), x))
5734> unlink(tmp)
5735> ## changes in 2.5.0
5736>
5737>
5738> ## give better error message for nls with no parameters
5739> ## Ivo Welch, R-help, 2006-12-23.
5740> d <- data.frame(y= runif(10), x=runif(10))
5741> try(nls(y ~ 1/(1+x), data = d, start=list(x=0.5,y=0.5), trace=TRUE))
5742Error in nls(y ~ 1/(1 + x), data = d, start = list(x = 0.5, y = 0.5),  :
5743  no parameters to fit
5744> ## changed in 2.4.1 patched
5745>
5746>
5747> ## cut(breaks="years"), in part PR#9433
5748> cut(as.Date(c("2000-01-17","2001-01-13","2001-01-20")), breaks="years")
5749[1] 2000-01-01 2001-01-01 2001-01-01
5750Levels: 2000-01-01 2001-01-01
5751> cut(as.POSIXct(c("2000-01-17","2001-01-13","2001-01-20")), breaks="years")
5752[1] 2000-01-01 2001-01-01 2001-01-01
5753Levels: 2000-01-01 2001-01-01
5754> ## did not get day 01 < 2.4.1 patched
5755>
5756>
5757> ## manipulating rownames: problems in pre-2.5.0
5758> A <- data.frame(a=character(0))
5759> try(row.names(A) <- 1:10) # succeeded in Dec 2006
5760Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length
5761> A <- list(a=1:3)
5762> class(A) <- "data.frame"
5763> row.names(A) <- letters[24:26] # failed at one point in Dec 2006
5764> A
5765  a
5766x 1
5767y 2
5768z 3
5769> ##
5770>
5771>
5772> ## extreme cases for subsetting of data frames
5773> w <- women[1, ]
5774> w[]
5775  height weight
57761     58    115
5777> w[,drop = TRUE]
5778  height weight
57791     58    115
5780Warning message:
5781In `[.data.frame`(w, , drop = TRUE) : 'drop' argument will be ignored
5782> w[1,]
5783  height weight
57841     58    115
5785> w[,]
5786  height weight
57871     58    115
5788> w[1, , drop = FALSE]
5789  height weight
57901     58    115
5791> w[, , drop = FALSE]
5792  height weight
57931     58    115
5794> w[1, , drop = TRUE]
5795$height
5796[1] 58
5797
5798$weight
5799[1] 115
5800
5801> w[, , drop = TRUE]
5802$height
5803[1] 58
5804
5805$weight
5806[1] 115
5807
5808> ## regression test: code changed for 2.5.0
5809>
5810>
5811> ## data.frame() with zero columns ignored 'row.names'
5812> (x <- data.frame(row.names=1:4))
5813data frame with 0 columns and 4 rows
5814> nrow(x)
5815[1] 4
5816> row.names(x)
5817[1] "1" "2" "3" "4"
5818> attr(x, "row.names")
5819[1] 1 2 3 4
5820> ## ignored prior to 2.5.0.
5821>
5822>
5823> ## identical on data.frames
5824> d0 <- d1 <- data.frame(1:4, row.names=1:4)
5825> row.names(d0) <- NULL
5826> dput(d0)
5827structure(list(X1.4 = 1:4), class = "data.frame", row.names = c(NA,
5828-4L))
5829> dput(d1)
5830structure(list(X1.4 = 1:4), class = "data.frame", row.names = c(NA,
58314L))
5832> identical(d0, d1)
5833[1] TRUE
5834> all.equal(d0, d1)
5835[1] TRUE
5836> row.names(d1) <- as.character(1:4)
5837> dput(d1)
5838structure(list(X1.4 = 1:4), class = "data.frame", row.names = c("1",
5839"2", "3", "4"))
5840> identical(d0, d1)
5841[1] FALSE
5842> all.equal(d0, d1)
5843[1] "Attributes: < Component \"row.names\": Modes: numeric, character >"
5844[2] "Attributes: < Component \"row.names\": target is numeric, current is character >"
5845> ## identical used internal representation prior to 2.5.0
5846>
5847>
5848> ## all.equal
5849> # ignored check.attributes in 2.4.1
5850> all.equal(data.frame(x=1:5, row.names=letters[1:5]),
5851+           data.frame(x=1:5,row.names=LETTERS[1:5]),
5852+           check.attributes=FALSE)
5853[1] TRUE
5854> # treated logicals as numeric
5855> all.equal(c(T, F, F), c(T, T, F))
5856[1] "1 element mismatch"
5857> all.equal(c(T, T, F), c(T, F, F))
5858[1] "1 element mismatch"
5859> # ignored raw:
5860> all.equal(as.raw(1:3), as.raw(1:3))
5861[1] TRUE
5862> all.equal(as.raw(1:3), as.raw(3:1))
5863[1] "2 element mismatches"
5864> ##
5865>
5866>
5867> ## tests of deparsing
5868> # if we run this from stdin, we will have no source, so fake it
5869> f <- function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5870> attr(f, "srcref") <- srcref(srcfilecopy("",
5871+     "function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}"),
5872+     c(1L, 1L, 1L, 56L))
5873> f # uses the source
5874function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5875> dput(f) # not source
5876function (x, xm = max(1L, x))
5877{
5878    xx <- 0L
5879    yy <- NA_real_
5880}
5881> dput(f, control="all") # uses the source
5882function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5883> cat(deparse(f), sep="\n")
5884function (x, xm = max(1L, x))
5885{
5886    xx <- 0L
5887    yy <- NA_real_
5888}
5889> dump("f", file="")
5890f <-
5891function(x, xm  = max(1L, x)) {xx <- 0L; yy <- NA_real_}
5892> # remove the source
5893> attr(f, "srcref") <- NULL
5894> f
5895function (x, xm = max(1L, x))
5896{
5897    xx <- 0L
5898    yy <- NA_real_
5899}
5900> dput(f, control="all")
5901function (x, xm = max(1L, x))
5902{
5903    xx <- 0L
5904    yy <- NA_real_
5905}
5906> dump("f", file="")
5907f <-
5908function (x, xm = max(1L, x))
5909{
5910    xx <- 0L
5911    yy <- NA_real_
5912}
5913>
5914> expression(bin <- bin + 1L)
5915expression(bin <- bin + 1L)
5916> ## did not preserve e.g. 1L at some point in pre-2.5.0
5917>
5918>
5919> ## NAs in substr were handled as large negative numbers
5920> x <- "abcde"
5921> substr(x, 1, 3)
5922[1] "abc"
5923> substr(x, NA, 1)
5924[1] NA
5925> substr(x, 1, NA)
5926[1] NA
5927> substr(x, NA, 3) <- "abc"; x
5928[1] NA
5929> substr(x, 1, NA) <- "AA"; x
5930[1] NA
5931> substr(x, 1, 2) <- NA_character_; x
5932[1] NA
5933> ## "" or no change in 2.4.1, except last
5934>
5935>
5936> ## regression tests for pmin/pmax, rewritten in C for 2.5.0
5937> # NULL == integer(0)
5938> pmin(NULL, integer(0))
5939integer(0)
5940> pmax(integer(0), NULL)
5941integer(0)
5942> pmin(NULL, 1:3)# now ok
5943integer(0)
5944> pmax(pi, NULL, 2:4)
5945numeric(0)
5946>
5947> x <- c(1, NA, NA, 4, 5)
5948> y <- c(2, NA, 4, NA, 3)
5949> pmin(x, y)
5950[1]  1 NA NA NA  3
5951> stopifnot(identical(pmin(x, y), pmin(y, x)))
5952> pmin(x, y, na.rm=TRUE)
5953[1]  1 NA  4  4  3
5954> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
5955> pmax(x, y)
5956[1]  2 NA NA NA  5
5957> stopifnot(identical(pmax(x, y), pmax(y, x)))
5958> pmax(x, y, na.rm=TRUE)
5959[1]  2 NA  4  4  5
5960> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
5961>
5962> x <- as.integer(x); y <- as.integer(y)
5963> pmin(x, y)
5964[1]  1 NA NA NA  3
5965> stopifnot(identical(pmin(x, y), pmin(y, x)))
5966> pmin(x, y, na.rm=TRUE)
5967[1]  1 NA  4  4  3
5968> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
5969> pmax(x, y)
5970[1]  2 NA NA NA  5
5971> stopifnot(identical(pmax(x, y), pmax(y, x)))
5972> pmax(x, y, na.rm=TRUE)
5973[1]  2 NA  4  4  5
5974> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
5975>
5976> x <- as.character(x); y <- as.character(y)
5977> pmin(x, y)
5978[1] "1" NA  NA  NA  "3"
5979> stopifnot(identical(pmin(x, y), pmin(y, x)))
5980> pmin(x, y, na.rm=TRUE)
5981[1] "1" NA  "4" "4" "3"
5982> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
5983> pmax(x, y)
5984[1] "2" NA  NA  NA  "5"
5985> stopifnot(identical(pmax(x, y), pmax(y, x)))
5986> pmax(x, y, na.rm=TRUE)
5987[1] "2" NA  "4" "4" "5"
5988> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
5989>
5990> # tests of classed quantities
5991> x <- .leap.seconds[1:23]; y <- rev(x)
5992> x[2] <- y[2] <- x[3] <- y[4] <- NA
5993> format(pmin(x, y), tz="GMT")  # TZ names differ by platform
5994 [1] "1972-07-01" NA           NA           NA           "1976-01-01"
5995 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
5996[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
5997[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
5998[21] "1974-01-01" "1973-01-01" "1972-07-01"
5999> class(pmin(x, y))
6000[1] "POSIXct" "POSIXt"
6001> stopifnot(identical(pmin(x, y), pmin(y, x)))
6002> format(pmin(x, y, na.rm=TRUE), tz="GMT")
6003 [1] "1972-07-01" NA           "1997-07-01" "1975-01-01" "1976-01-01"
6004 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6005[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6006[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6007[21] "1974-01-01" "1973-01-01" "1972-07-01"
6008> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
6009> format(pmax(x, y), tz="GMT")
6010 [1] "2006-01-01" NA           NA           NA           "1994-07-01"
6011 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6012[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6013[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6014[21] "1997-07-01" "1999-01-01" "2006-01-01"
6015> stopifnot(identical(pmax(x, y), pmax(y, x)))
6016> format(pmax(x, y, na.rm=TRUE), tz="GMT")
6017 [1] "2006-01-01" NA           "1997-07-01" "1975-01-01" "1994-07-01"
6018 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6019[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6020[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6021[21] "1997-07-01" "1999-01-01" "2006-01-01"
6022> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
6023>
6024> x <- as.POSIXlt(x, tz="GMT"); y <- as.POSIXlt(y, tz="GMT")
6025> format(pmin(x, y), tz="GMT")
6026 [1] "1972-07-01" NA           NA           NA           "1976-01-01"
6027 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6028[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6029[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6030[21] "1974-01-01" "1973-01-01" "1972-07-01"
6031> class(pmin(x, y))
6032[1] "POSIXlt" "POSIXt"
6033> stopifnot(identical(pmin(x, y), pmin(y, x)))
6034> format(pmin(x, y, na.rm=TRUE), tz="GMT")
6035 [1] "1972-07-01" NA           "1997-07-01" "1975-01-01" "1976-01-01"
6036 [6] "1977-01-01" "1978-01-01" "1979-01-01" "1980-01-01" "1981-07-01"
6037[11] "1982-07-01" "1983-07-01" "1982-07-01" "1981-07-01" "1980-01-01"
6038[16] "1979-01-01" "1978-01-01" "1977-01-01" "1976-01-01" "1975-01-01"
6039[21] "1974-01-01" "1973-01-01" "1972-07-01"
6040> stopifnot(identical(pmin(x, y, na.rm=TRUE), pmin(y, x, na.rm=TRUE)))
6041> format(pmax(x, y), tz="GMT")
6042 [1] "2006-01-01" NA           NA           NA           "1994-07-01"
6043 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6044[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6045[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6046[21] "1997-07-01" "1999-01-01" "2006-01-01"
6047> stopifnot(identical(pmax(x, y), pmax(y, x)))
6048> format(pmax(x, y, na.rm=TRUE), tz="GMT")
6049 [1] "2006-01-01" NA           "1997-07-01" "1975-01-01" "1994-07-01"
6050 [6] "1993-07-01" "1992-07-01" "1991-01-01" "1990-01-01" "1988-01-01"
6051[11] "1985-07-01" "1983-07-01" "1985-07-01" "1988-01-01" "1990-01-01"
6052[16] "1991-01-01" "1992-07-01" "1993-07-01" "1994-07-01" "1996-01-01"
6053[21] "1997-07-01" "1999-01-01" "2006-01-01"
6054> stopifnot(identical(pmax(x, y, na.rm=TRUE), pmax(y, x, na.rm=TRUE)))
6055> ## regresion tests
6056>
6057>
6058> ## regression tests on names of 1D arrays
6059> x <- as.array(1:3)
6060> names(x) <- letters[x] # sets dimnames, really
6061> names(x)
6062[1] "a" "b" "c"
6063> dimnames(x)
6064[[1]]
6065[1] "a" "b" "c"
6066
6067> attributes(x)
6068$dim
6069[1] 3
6070
6071$dimnames
6072$dimnames[[1]]
6073[1] "a" "b" "c"
6074
6075
6076> names(x) <- NULL
6077> attr(x, "names") <- LETTERS[x] # sets dimnames, really
6078> names(x)
6079[1] "A" "B" "C"
6080> dimnames(x)
6081[[1]]
6082[1] "A" "B" "C"
6083
6084> attributes(x)
6085$dim
6086[1] 3
6087
6088$dimnames
6089$dimnames[[1]]
6090[1] "A" "B" "C"
6091
6092
6093> ## regression tests
6094>
6095>
6096> ## regression tests on NA attribute names
6097> x <- 1:3
6098> attr(x, "NA") <- 4
6099> attributes(x)
6100$`NA`
6101[1] 4
6102
6103> attr(x, "NA")
6104[1] 4
6105> attr(x, NA_character_)
6106NULL
6107> try(attr(x, NA_character_) <- 5)
6108Error in attr(x, NA_character_) <- 5 :
6109  'name' must be non-null character string
6110> ## prior to 2.5.0 NA was treated as "NA"
6111>
6112>
6113> ## qr with pivoting (PR#9623)
6114> A <- matrix(c(0,0,0, 1,1,1), nrow = 3,
6115+             dimnames = list(letters[1:3], c("zero","one")))
6116> y <- matrix(c(6,7,8), nrow = 3, dimnames = list(LETTERS[1:3], "y"))
6117> qr.coef(qr(A), y)
6118      y
6119zero NA
6120one   7
6121> qr.fitted(qr(A), y)
6122  y
6123A 7
6124B 7
6125C 7
6126>
6127> qr.coef(qr(matrix(0:1, 1, dimnames=list(NULL, c("zero","one")))), 5)
6128zero  one
6129  NA    5
6130> ## coef names were returned unpivoted <= 2.5.0
6131>
6132> ## readChar read extra items, terminated on zeros
6133> x <- as.raw(65:74)
6134> readChar(x, nchar=c(3,3,0,3,3,3))
6135[1] "ABC" "DEF" ""    "GHI" "J"
6136> f <- tempfile(tmpdir = getwd())
6137> writeChar("ABCDEFGHIJ", con=f, eos=NULL)
6138> readChar(f, nchar=c(3,3,0,3,3,3))
6139[1] "ABC" "DEF" ""    "GHI" "J"
6140> unlink(f)
6141> ##
6142>
6143>
6144> ## corner cases for cor
6145> set.seed(1)
6146> X <- cbind(NA, 1:3, rnorm(3))
6147> try(cor(X, use = "complete"))
6148Error in cor(X, use = "complete") : no complete element pairs
6149> try(cor(X, use = "complete", method="spearman"))
6150Error in cor(X, use = "complete", method = "spearman") :
6151  no complete element pairs
6152> try(cor(X, use = "complete", method="kendall"))
6153Error in cor(X, use = "complete", method = "kendall") :
6154  no complete element pairs
6155> cor(X, use = "pair")
6156     [,1]       [,2]       [,3]
6157[1,]   NA         NA         NA
6158[2,]   NA  1.0000000 -0.1942739
6159[3,]   NA -0.1942739  1.0000000
6160> cor(X, use = "pair", method="spearman")
6161     [,1] [,2] [,3]
6162[1,]   NA   NA   NA
6163[2,]   NA  1.0 -0.5
6164[3,]   NA -0.5  1.0
6165> cor(X, use = "pair", method="kendall")
6166     [,1]       [,2]       [,3]
6167[1,]   NA         NA         NA
6168[2,]   NA  1.0000000 -0.3333333
6169[3,]   NA -0.3333333  1.0000000
6170>
6171> X[1,1] <- 1
6172> cor(X, use = "complete")
6173     [,1] [,2] [,3]
6174[1,]   NA   NA   NA
6175[2,]   NA   NA   NA
6176[3,]   NA   NA   NA
6177> cor(X, use = "complete", method="spearman")
6178     [,1] [,2] [,3]
6179[1,]   NA   NA   NA
6180[2,]   NA   NA   NA
6181[3,]   NA   NA   NA
6182> cor(X, use = "complete", method="kendall")
6183     [,1] [,2] [,3]
6184[1,]   NA   NA   NA
6185[2,]   NA   NA   NA
6186[3,]   NA   NA   NA
6187> cor(X, use = "pair")
6188     [,1]       [,2]       [,3]
6189[1,]   NA         NA         NA
6190[2,]   NA  1.0000000 -0.1942739
6191[3,]   NA -0.1942739  1.0000000
6192> cor(X, use = "pair", method="spearman")
6193     [,1] [,2] [,3]
6194[1,]   NA   NA   NA
6195[2,]   NA  1.0 -0.5
6196[3,]   NA -0.5  1.0
6197> cor(X, use = "pair", method="kendall")
6198     [,1]       [,2]       [,3]
6199[1,]   NA         NA         NA
6200[2,]   NA  1.0000000 -0.3333333
6201[3,]   NA -0.3333333  1.0000000
6202> ## not consistent in 2.6.x
6203>
6204>
6205> ## confint on rank-deficient models (in part, PR#10494)
6206> junk <- data.frame(x = rep(1, 10L),
6207+                    u = factor(sample(c("Y", "N"), 10, replace=TRUE)),
6208+                    ans = rnorm(10))
6209> fit <-  lm(ans ~ x + u, data = junk)
6210> confint(fit)
6211                 2.5 %    97.5 %
6212(Intercept) -0.3224857 2.2194594
6213x                   NA        NA
6214uY          -2.6821240 0.3560815
6215> confint.default(fit)
6216                 2.5 %    97.5 %
6217(Intercept) -0.1317629 2.0287366
6218x                   NA        NA
6219uY          -2.4541666 0.1281242
6220> ## Mismatch gave NA for 'u' in 2.6.1
6221>
6222>
6223> ## corrupt data frame produced by subsetting (PR#10574)
6224> x <- data.frame(a=1:3, b=2:4)
6225> x[,3] <- x
6226Warning message:
6227In `[<-.data.frame`(`*tmp*`, , 3, value = list(a = 1:3, b = 2:4)) :
6228  provided 2 variables to replace 1 variables
6229> x
6230  a b a.1
62311 1 2   1
62322 2 3   2
62333 3 4   3
6234> ## warning during printing < 2.7.0
6235>
6236>
6237> ## format.factor used to lose dim[names] and names (PR#11512)
6238> x <- factor(c("aa", letters[-1]))
6239> dim(x) <- c(13,2)
6240> format(x, justify="right")
6241      [,1] [,2]
6242 [1,] "aa" " n"
6243 [2,] " b" " o"
6244 [3,] " c" " p"
6245 [4,] " d" " q"
6246 [5,] " e" " r"
6247 [6,] " f" " s"
6248 [7,] " g" " t"
6249 [8,] " h" " u"
6250 [9,] " i" " v"
6251[10,] " j" " w"
6252[11,] " k" " x"
6253[12,] " l" " y"
6254[13,] " m" " z"
6255> ##
6256>
6257>
6258> ## removing columns in within (PR#1131)
6259> abc <- data.frame(a=1:5, b=2:6, c=3:7)
6260> within(abc, b<-NULL)
6261  a c
62621 1 3
62632 2 4
62643 3 5
62654 4 6
62665 5 7
6267> within(abc,{d<-a+7;b<-NULL})
6268  a c  d
62691 1 3  8
62702 2 4  9
62713 3 5 10
62724 4 6 11
62735 5 7 12
6274> within(abc,{a<-a+7;b<-NULL})
6275   a c
62761  8 3
62772  9 4
62783 10 5
62794 11 6
62805 12 7
6281> ## Second produced corrupt data frame in 2.7.1
6282>
6283>
6284> ## aggregate on an empty data frame (PR#13167)
6285> z <- data.frame(a=integer(0), b=numeric(0))
6286> try(aggregate(z, by=z[1], FUN=sum))
6287Error in aggregate.data.frame(z, by = z[1], FUN = sum) :
6288  no rows to aggregate
6289> ## failed in unlist in 2.8.0, now gives explicit message.
6290> aggregate(data.frame(a=1:10)[F], list(rep(1:2, each=5)), sum)
6291  Group.1
62921       1
62932       2
6294> ## used to fail obscurely.
6295>
6296>
6297> ## subsetting data frames with duplicate rows
6298> z <- data.frame(a=1, a=2, b=3, check.names=FALSE)
6299> z[] # OK
6300  a a b
63011 1 2 3
6302> z[1, ]
6303  a a b
63041 1 2 3
6305> ## had row names a, a.1, b in 2.8.0.
6306>
6307>
6308> ## incorrect warning due to lack of fuzz.
6309> TS <-  ts(co2[1:192], freq=24)
6310> tmp2 <- window(TS, start(TS), end(TS))
6311> ## warned in 2.8.0
6312>
6313> ## failed to add tag
6314> Call <- call("foo", 1)
6315> Call[["bar"]] <- 2
6316> Call
6317foo(1, bar = 2)
6318> ## unnamed call in 2.8.1
6319>
6320> options(keep.source = TRUE)
6321> ## $<- on pairlists failed to duplicate (from Felix Andrews,
6322> ## https://stat.ethz.ch/pipermail/r-devel/2009-January/051698.html)
6323> foo <- function(given = NULL) {
6324+     callObj <- quote(callFunc())
6325+     if(!is.null(given)) callObj$given <- given
6326+     if (is.null(given)) callObj$default <- TRUE
6327+     callObj
6328+ }
6329>
6330> foo()
6331callFunc(default = TRUE)
6332> foo(given = TRUE)
6333callFunc(given = TRUE)
6334> foo("blah blah")
6335callFunc(given = "blah blah")
6336> foo(given = TRUE)
6337callFunc(given = TRUE)
6338> foo()
6339callFunc(default = TRUE)
6340> ## altered foo() in 2.8.1.
6341>
6342> ## Using  '#' flag in  sprintf():
6343> forms <- c("%#7.5g","%#5.f", "%#7x", "%#5d", "%#9.0e")
6344> nums <- list(-3.145, -31,   0xabc,  -123L, 123456)
6345> rbind(mapply(sprintf, forms,               nums),
6346+       mapply(sprintf, sub("#", '', forms), nums))
6347     %#7.5g    %#5.f   %#7x      %#5d    %#9.0e
6348[1,] "-3.1450" " -31." "  0xabc" " -123" "   1.e+05"
6349[2,] " -3.145" "  -31" "    abc" " -123" "    1e+05"
6350> ## gave an error in pre-release versions of 2.9.0
6351>
6352> ## (auto)printing of functions {with / without source attribute},
6353> ## including primitives
6354> sink(con <- textConnection("of", "w")) ; c ; sink(NULL); close(con)
6355> of2 <- capture.output(print(c))
6356> stopifnot(identical(of2, of),
6357+           identical(of2, "function (...)  .Primitive(\"c\")"))
6358> ## ^^ would have failed up to R 2.9.x
6359> foo
6360function(given = NULL) {
6361    callObj <- quote(callFunc())
6362    if(!is.null(given)) callObj$given <- given
6363    if (is.null(given)) callObj$default <- TRUE
6364    callObj
6365}
6366<bytecode: 0x29a71c0>
6367> print(foo, useSource = FALSE)
6368function (given = NULL)
6369{
6370    callObj <- quote(callFunc())
6371    if (!is.null(given))
6372        callObj$given <- given
6373    if (is.null(given))
6374        callObj$default <- TRUE
6375    callObj
6376}
6377<bytecode: 0x29a71c0>
6378> attr(foo, "srcref") <- NULL
6379> foo
6380function (given = NULL)
6381{
6382    callObj <- quote(callFunc())
6383    if (!is.null(given))
6384        callObj$given <- given
6385    if (is.null(given))
6386        callObj$default <- TRUE
6387    callObj
6388}
6389<bytecode: 0x29a71c0>
6390> (f <- structure(function(){}, note = "just a note",
6391+                 yada = function() "not the same"))
6392function(){}
6393attr(,"note")
6394[1] "just a note"
6395attr(,"yada")
6396function() "not the same"
6397> print(f, useSource = TRUE)
6398function(){}
6399attr(,"note")
6400[1] "just a note"
6401attr(,"yada")
6402function() "not the same"
6403> print(f, useSource = FALSE) # must print attributes
6404function ()
6405{
6406}
6407attr(,"note")
6408[1] "just a note"
6409attr(,"yada")
6410function ()
6411"not the same"
6412> print.function <- function(x, ...) {
6413+     cat("my print(<function>): "); str(x, give.attr=FALSE); invisible(x) }
6414> print.function
6415my print(<function>): function (x, ...)
6416> print(print.function)
6417my print(<function>): function (x, ...)
6418> rm(print.function)
6419> ## auto-printing and printing differed up to R 2.9.x -- and then *AGAIN* in R 3.6.0
6420>
6421>
6422> ## Make sure deparsing does not reset parameters
6423> print(list(f, expression(foo), f, quote(foo), f, base::list, f),
6424+       useSource = FALSE)
6425[[1]]
6426function ()
6427{
6428}
6429attr(,"note")
6430[1] "just a note"
6431attr(,"yada")
6432function ()
6433"not the same"
6434
6435[[2]]
6436expression(foo)
6437
6438[[3]]
6439function ()
6440{
6441}
6442attr(,"note")
6443[1] "just a note"
6444attr(,"yada")
6445function ()
6446"not the same"
6447
6448[[4]]
6449foo
6450
6451[[5]]
6452function ()
6453{
6454}
6455attr(,"note")
6456[1] "just a note"
6457attr(,"yada")
6458function ()
6459"not the same"
6460
6461[[6]]
6462function (...)  .Primitive("list")
6463
6464[[7]]
6465function ()
6466{
6467}
6468attr(,"note")
6469[1] "just a note"
6470attr(,"yada")
6471function ()
6472"not the same"
6473
6474>
6475> printCoefmat(cbind(0,1))
6476     [,1] [,2]
6477[1,]    0    1
6478> ## would print NaN up to R 2.9.0
6479>
6480>
6481> ## continuity correction for Kendall's tau.  Improves this example.
6482> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "kendall",
6483+          exact = TRUE)
6484
6485	Kendall's rank correlation tau
6486
6487data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6488T = 1, p-value = 0.08333
6489alternative hypothesis: true tau is not equal to 0
6490sample estimates:
6491 tau
6492-0.8
6493
6494> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "kendall",
6495+          exact = FALSE)
6496
6497	Kendall's rank correlation tau
6498
6499data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6500z = -1.9596, p-value = 0.05004
6501alternative hypothesis: true tau is not equal to 0
6502sample estimates:
6503 tau
6504-0.8
6505
6506> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "kendall",
6507+          exact = FALSE, continuity = TRUE)
6508
6509	Kendall's rank correlation tau
6510
6511data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6512z = -1.7146, p-value = 0.08641
6513alternative hypothesis: true tau is not equal to 0
6514sample estimates:
6515 tau
6516-0.8
6517
6518> # and a little for Spearman's
6519> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "spearman",
6520+          exact = TRUE)
6521
6522	Spearman's rank correlation rho
6523
6524data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6525S = 38, p-value = 0.08333
6526alternative hypothesis: true rho is not equal to 0
6527sample estimates:
6528 rho
6529-0.9
6530
6531> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "spearman",
6532+          exact = FALSE)
6533
6534	Spearman's rank correlation rho
6535
6536data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6537S = 38, p-value = 0.03739
6538alternative hypothesis: true rho is not equal to 0
6539sample estimates:
6540 rho
6541-0.9
6542
6543> cor.test(c(1, 2, 3, 4, 5), c(8, 6, 7, 5, 3), method = "spearman",
6544+          exact = FALSE, continuity = TRUE)
6545
6546	Spearman's rank correlation rho
6547
6548data:  c(1, 2, 3, 4, 5) and c(8, 6, 7, 5, 3)
6549S = 38, p-value = 0.09689
6550alternative hypothesis: true rho is not equal to 0
6551sample estimates:
6552 rho
6553-0.9
6554
6555> ## Kendall case is wish of PR#13691
6556>
6557>
6558> ## corrupt data frame, PR#13724
6559> foo <- matrix(1:12, nrow = 3)
6560> bar <- as.data.frame(foo)
6561> val <- integer(0)
6562> try(bar$NewCol <- val)
6563Error in `$<-.data.frame`(`*tmp*`, NewCol, value = integer(0)) :
6564  replacement has 0 rows, data has 3
6565> # similar, not in the report
6566> try(bar[["NewCol"]] <- val)
6567Error in `[[<-.data.frame`(`*tmp*`, "NewCol", value = integer(0)) :
6568  replacement has 0 rows, data has 3
6569> # [ ] is tricker, so just check the result is reasonable and prints
6570> bar["NewCol"] <- val
6571> bar[, "NewCol2"] <- val
6572> bar[FALSE, "NewCol3"] <- val
6573> bar
6574  V1 V2 V3 V4 NewCol NewCol2 NewCol3
65751  1  4  7 10     NA      NA      NA
65762  2  5  8 11     NA      NA      NA
65773  3  6  9 12     NA      NA      NA
6578> ## Succeeded but gave corrupt result in 2.9.0
6579>
6580>
6581> ## Printing NA_complex_
6582> m22 <- matrix(list(NA_complex_, 3, "A string", NA_complex_), 2,2)
6583> print(m22)
6584     [,1] [,2]
6585[1,] NA   "A string"
6586[2,] 3    NA
6587> print(m22, na.print="<missing value>")
6588     [,1]            [,2]
6589[1,] <missing value> "A string"
6590[2,] 3               <missing value>
6591> ## used uninitialized variable in C, noticably Windows, for R <= 2.9.0
6592>
6593>
6594> ## non-standard variable names in update etc
6595> ## never guaranteed to work, requested by Sundar Dorai-Raj in
6596> ## https://stat.ethz.ch/pipermail/r-devel/2009-July/054184.html
6597> update(`a: b` ~ x, ~ . + y)
6598`a: b` ~ x + y
6599> ## 2.9.1 dropped backticks
6600>
6601>
6602> ## print(ls.str(.)) did evaluate calls
6603> E <- new.env(); E$cl <- call("print", "Boo !")
6604> ls.str(E)
6605cl :  language print("Boo !")
6606> ## 2.10.0 did print..
6607>
6608>
6609> ## complete.cases with no input
6610> try(complete.cases())
6611Error in complete.cases() : no input has determined the number of cases
6612> try(complete.cases(list(), list()))
6613Error in complete.cases(list(), list()) :
6614  no input has determined the number of cases
6615> ## gave unhelpful messages in 2.10.0, silly results in pre-2.10.1
6616>
6617>
6618> ## error messages from (C-level) evalList
6619> tst <- function(y) { stopifnot(is.numeric(y)); y+ 1 }
6620> try(tst()) # even nicer since R 3.5.0's change to sequential stopifnot()
6621Error in stopifnot(is.numeric(y)) :
6622  argument "y" is missing, with no default
6623> try(c(1,,2))
6624Error in c(1, , 2) : argument 2 is empty
6625> ## change in 2.8.0 made these less clear
6626>
6627>
6628> ## empty levels from cut.Date (cosmetic, PR#14162)
6629> x <- as.Date(c("2009-03-21","2009-03-31"))
6630> cut(x, breaks= "quarter") # had two levels in 2.10.1
6631[1] 2009-01-01 2009-01-01
6632Levels: 2009-01-01
6633> cut(as.POSIXlt(x), breaks= "quarter")
6634[1] 2009-01-01 2009-01-01
6635Levels: 2009-01-01
6636> ## remove empty final level
6637>
6638>
6639> ## tests of error conditions in switch()
6640> switch("a", a=, b=, c=, 4)
6641[1] 4
6642> switch("a", a=, b=, c=, )
6643> .Last.value
6644NULL
6645> switch("a", a=, b=, c=, invisible(4))
6646> .Last.value
6647[1] 4
6648> ## visiblilty changed in 2.11.0
6649>
6650>
6651> ## rounding error in aggregate.ts
6652> ## https://stat.ethz.ch/pipermail/r-devel/2010-April/057225.html
6653> x <- rep(6:10, 1:5)
6654> aggregate(as.ts(x), FUN = mean, ndeltat = 5)
6655Time Series:
6656Start = 1
6657End = 11
6658Frequency = 0.2
6659[1]  7.2  8.8 10.0
6660> x <- rep(6:10, 1:5)
6661> aggregate(as.ts(x), FUN = mean, nfrequency = 0.2)
6662Time Series:
6663Start = 1
6664End = 11
6665Frequency = 0.2
6666[1]  7.2  8.8 10.0
6667> ## platform-dependent in 2.10.1
6668>
6669>
6670> ## wish of PR#9574
6671> a <- c(0.1, 0.3, 0.4, 0.5, 0.3, 0.0001)
6672> format.pval(a, eps=0.01)
6673[1] "0.1"   "0.3"   "0.4"   "0.5"   "0.3"   "<0.01"
6674> format.pval(a, eps=0.01, nsmall =2)
6675[1] "0.10"  "0.30"  "0.40"  "0.50"  "0.30"  "<0.01"
6676> ## granted in 2.12.0
6677>
6678>
6679> ## printing fractional dates
6680> as.Date(0.5, origin="1969-12-31")
6681[1] "1969-12-31"
6682> ## changed to round down in 2.12.1
6683>
6684>
6685> ## printing data frames with  ""  colnames
6686> dfr <- data.frame(x=1:6, CC=11:16, f = gl(3,2)); colnames(dfr)[2] <- ""
6687> dfr
6688  x    f
66891 1 11 1
66902 2 12 1
66913 3 13 2
66924 4 14 2
66935 5 15 3
66946 6 16 3
6695> ## now prints the same as data.matrix(dfr) does here
6696>
6697>
6698> ## format(., zero.print) --> prettyNum()
6699> set.seed(9); m <- matrix(local({x <- rnorm(40)
6700+                                 sign(x)*round(exp(2*x))/10}), 8,5)
6701> noquote(format(m, zero.print= "."))
6702     [,1] [,2] [,3] [,4] [,5]
6703[1,]  .   -0.1 -0.1  .    0.8
6704[2,]  .    .    .   21.4  0.1
6705[3,] -0.1  1.3  0.6  0.2  0.1
6706[4,] -0.1  .    .    .    .
6707[5,]  0.2  0.1  3.4  0.2  0.2
6708[6,]  .   -0.1  0.1  0.2  .
6709[7,]  1.1  4.0 -0.1  .    0.2
6710[8,] -0.1  .    0.6 -0.1  0.1
6711> ## used to print  ". 0" instead of ".  "
6712>
6713>
6714> ## tests of NA having precedence over NaN -- all must print "NA"
6715> min(c(NaN, NA))
6716[1] NA
6717> min(c(NA, NaN)) # NaN in 2.12.2
6718[1] NA
6719> min(NaN, NA_real_)  # NaN in 2.12.2
6720[1] NA
6721> min(NA_real_, NaN)
6722[1] NA
6723> max(c(NaN, NA))
6724[1] NA
6725> max(c(NA, NaN))  # NaN in 2.12.2
6726[1] NA
6727> max(NaN, NA_real_)  # NaN in 2.12.2
6728[1] NA
6729> max(NA_real_, NaN)
6730[1] NA
6731> ## might depend on compiler < 2.13.0
6732>
6733>
6734> ## PR#14514
6735> # Data are from Conover, "Nonparametric Statistics", 3rd Ed, p. 197,
6736> # re-arranged to make a lower-tail test the issue of relevance:  we
6737> # want to see if pregnant nurses exposed to nitrous oxide have higher
6738> # rates of miscarriage, stratifying on the type of nurse.
6739> Nitrous <- array(c(32,210,8,26,18,21,3,3,7,75,0,10), dim = c(2,2,3),
6740+                  dimnames = list(c("Exposed","NotExposed"),
6741+                  c("FullTerm","Miscarriage"),
6742+                  c("DentalAsst","OperRoomNurse","OutpatientNurse")))
6743> mantelhaen.test(Nitrous, exact=TRUE, alternative="less")
6744
6745	Exact conditional test of independence in 2 x 2 x k tables
6746
6747data:  Nitrous
6748S = 57, p-value = 0.1959
6749alternative hypothesis: true common odds ratio is less than 1
675095 percent confidence interval:
6751 0.000000 1.388197
6752sample estimates:
6753common odds ratio
6754        0.6652418
6755
6756> mantelhaen.test(Nitrous, exact=FALSE, alternative="less")
6757
6758	Mantel-Haenszel chi-squared test with continuity correction
6759
6760data:  Nitrous
6761Mantel-Haenszel X-squared = 0.71432, df = 1, p-value = 0.199
6762alternative hypothesis: true common odds ratio is less than 1
676395 percent confidence interval:
6764 0.000000 1.260053
6765sample estimates:
6766common odds ratio
6767        0.6645374
6768
6769> ## exact = FALSE gave the wrong tail in 2.12.2.
6770>
6771>
6772> ## scan(strip.white=TRUE) could strip trailing (but not leading) space
6773> ## inside quoted strings.
6774> writeLines(' "  A  "; "B" ;"C";" D ";"E ";  F  ;G  ', "foo")
6775> cat(readLines("foo"), sep = "\n")
6776 "  A  "; "B" ;"C";" D ";"E ";  F  ;G
6777> scan('foo', list(""), sep=";")[[1]]
6778Read 7 records
6779[1] "   A  " " B "    "C"      " D "    "E "     "  F  "  "G  "
6780> scan('foo', "", sep=";")
6781Read 7 items
6782[1] "   A  " " B "    "C"      " D "    "E "     "  F  "  "G  "
6783> scan('foo', list(""), sep=";", strip.white = TRUE)[[1]]
6784Read 7 records
6785[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6786> scan('foo', "", sep=";", strip.white = TRUE)
6787Read 7 items
6788[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6789> unlink('foo')
6790>
6791> writeLines(' "  A  "\n "B" \n"C"\n" D "\n"E "\n  F  \nG  ', "foo2")
6792> scan('foo2', "")
6793Read 7 items
6794[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6795> scan('foo2', "", strip.white=TRUE) # documented to be ignored ...
6796Read 7 items
6797[1] "  A  " "B"     "C"     " D "   "E "    "F"     "G"
6798> unlink('foo2')
6799> ## Changed for 2.13.0, found when investigating non-bug PR#14522.
6800>
6801>
6802> ## PR#14488: missing values in rank correlations
6803> set.seed(1)
6804> x <- runif(10)
6805> y <- runif(10)
6806> x[3] <- NA; y[5] <- NA
6807> xy <- cbind(x, y)
6808>
6809> cor(x, y, method = "spearman", use = "complete.obs")
6810[1] 0.2380952
6811> cor(x, y, method = "spearman", use = "pairwise.complete.obs")
6812[1] 0.2380952
6813> cor(na.omit(xy),  method = "spearman", use = "complete.obs")
6814          x         y
6815x 1.0000000 0.2380952
6816y 0.2380952 1.0000000
6817> cor(xy,  method = "spearman", use = "complete.obs")
6818          x         y
6819x 1.0000000 0.2380952
6820y 0.2380952 1.0000000
6821> cor(xy,  method = "spearman", use = "pairwise.complete.obs")
6822          x         y
6823x 1.0000000 0.2380952
6824y 0.2380952 1.0000000
6825> ## inconsistent in R < 2.13.0
6826>
6827>
6828> ## integer overflow in rowsum() went undetected
6829> # https://stat.ethz.ch/pipermail/r-devel/2011-March/060304.html
6830> x <- 2e9L
6831> rowsum(c(x, x), c("a", "a"))
6832  [,1]
6833a   NA
6834> rowsum(data.frame(z = c(x, x)), c("a", "a"))
6835   z
6836a NA
6837> ## overflow in R < 2.13.0.
6838>
6839>
6840> ## method dispatch in [[.data.frame:
6841> ## https://stat.ethz.ch/pipermail/r-devel/2011-April/060409.html
6842> d <- data.frame(num = 1:4,
6843+           fac = factor(letters[11:14], levels = letters[1:15]),
6844+           date = as.Date("2011-04-01") + (0:3),
6845+           pv = package_version(c("1.2-3", "4.5", "6.7", "8.9-10")))
6846> for (i in seq_along(d)) print(d[[1, i]])
6847[1] 1
6848[1] k
6849Levels: a b c d e f g h i j k l m n o
6850[1] "2011-04-01"
6851[1] '1.2.3'
6852> ## did not dispatch in R < 2.14.0
6853>
6854>
6855> ## some tests of 24:00 as midnight
6856> as.POSIXlt("2011-05-16 24:00:00", tz = "GMT")
6857[1] "2011-05-17 GMT"
6858> as.POSIXlt("2010-01-31 24:00:00", tz = "GMT")
6859[1] "2010-02-01 GMT"
6860> as.POSIXlt("2011-02-28 24:00:00", tz = "GMT")
6861[1] "2011-03-01 GMT"
6862> as.POSIXlt("2008-02-28 24:00:00", tz = "GMT")
6863[1] "2008-02-29 GMT"
6864> as.POSIXlt("2008-02-29 24:00:00", tz = "GMT")
6865[1] "2008-03-01 GMT"
6866> as.POSIXlt("2010-12-31 24:00:00", tz = "GMT")
6867[1] "2011-01-01 GMT"
6868> ## new in 2.14.0
6869>
6870>
6871> ## Unwarranted conversion of logical values
6872> try(double(FALSE))
6873Error in double(FALSE) : invalid 'length' argument
6874> x <- 1:3
6875> try(length(x) <- TRUE)
6876Error in length(x) <- TRUE : invalid value
6877> ## coerced to integer in 2.13.x
6878>
6879>
6880> ## filter(recursive = TRUE) on input with NAs
6881> # https://stat.ethz.ch/pipermail/r-devel/2011-July/061547.html
6882> x <- c(1:4, NA, 6:9)
6883> cbind(x, "1"=filter(x, 0.5, method="recursive"),
6884+          "2"=filter(x, c(0.5, 0.0), method="recursive"),
6885+          "3"=filter(x, c(0.5, 0.0, 0.0), method="recursive"))
6886Time Series:
6887Start = 1
6888End = 9
6889Frequency = 1
6890   x     1     2     3
68911  1 1.000 1.000 1.000
68922  2 2.500 2.500 2.500
68933  3 4.250 4.250 4.250
68944  4 6.125 6.125 6.125
68955 NA    NA    NA    NA
68966  6    NA    NA    NA
68977  7    NA    NA    NA
68988  8    NA    NA    NA
68999  9    NA    NA    NA
6900> ## NAs in wrong place in R <= 2.13.1.
6901>
6902>
6903> ## PR#14679.  Format depends if TZ is set.
6904> x <- as.POSIXlt(c("2010-02-27 22:30:33", "2009-08-09 06:01:03",
6905+                   "2010-07-23 17:29:59"))
6906> stopifnot(!is.na(trunc(x, units = "days")[1:3]))
6907> ## gave NAs after the first in R < 2.13.2
6908>
6909>
6910> ## explicit error message for silly input (tol = 0)
6911> aa <- c(1, 2, 3, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 13, 14)
6912> try(smooth.spline(aa, seq_along(aa)))
6913Error in smooth.spline(aa, seq_along(aa)) :
6914  'tol' must be strictly positive and finite
6915> fit <- smooth.spline(aa, seq_along(aa), tol = 0.1)
6916> # actual output is too unstable to diff.
6917> ## Better message from R 2.14.2
6918>
6919>
6920> ## PR#14840
6921> d <- data.frame(x = 1:9,
6922+                 y = 1:9 + 0.1*c(1, 2, -1, 0, 1, 1000, 0, 1, -1),
6923+                 w = c(1, 0.5, 2, 1, 2, 0, 1, 2, 1))
6924> fit <- lm(y ~ x, data=d, weights=w)
6925> summary(fit)
6926
6927Call:
6928lm(formula = y ~ x, data = d, weights = w)
6929
6930Weighted Residuals:
6931    Min      1Q  Median      3Q     Max
6932-0.1883 -0.0310  0.0000  0.1006  0.1165
6933
6934Coefficients:
6935            Estimate Std. Error t value Pr(>|t|)
6936(Intercept)  0.03949    0.08612   0.459    0.663
6937x            0.99788    0.01502  66.419 7.83e-10 ***
6938---
6939Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
6940
6941Residual standard error: 0.1232 on 6 degrees of freedom
6942Multiple R-squared:  0.9986,	Adjusted R-squared:  0.9984
6943F-statistic:  4412 on 1 and 6 DF,  p-value: 7.834e-10
6944
6945> ## issue is how the 5-number summary is labelled
6946> ## (also seen in example(case.names))
6947>
6948>
6949> ## is.unsorted got it backwards for dataframes of more than one column
6950> ## it is supposed to look for violations of x[2] > x[1], x[3] > x[2], etc.
6951> is.unsorted(data.frame(x=2:1))
6952[1] FALSE
6953> is.unsorted(data.frame(x=1:2, y=3:4))
6954[1] FALSE
6955> is.unsorted(data.frame(x=3:4, y=1:2))
6956[1] TRUE
6957> ## R < 2.15.1 got these as FALSE, TRUE, FALSE.
6958>
6959>
6960> library("methods")# (not needed here)
6961> assertError <- tools::assertError
6962> assertErrorV <- function(expr) assertError(expr, verbose=TRUE)
6963> assertErrorV( getMethod(ls, "bar", fdef=ls) )
6964Asserted error: no generic function found for 'ls'
6965> assertErrorV( getMethod(show, "bar") )
6966Asserted error: no method found for function 'show' and signature bar
6967> ## R < 2.15.1 gave
6968> ##   cannot coerce type 'closure' to vector of type 'character'
6969>
6970>
6971> ## corner cases for array
6972> # allowed, gave non-array in 2.15.x
6973> try(array(1, integer()))
6974Error in array(1, integer()) : 'dims' cannot be of length 0
6975> # if no dims, an error to supply dimnames
6976> try(array(1, integer(), list(1, 2)))
6977Error in array(1, integer(), list(1, 2)) : 'dims' cannot be of length 0
6978> ##
6979>
6980>
6981> ## is.na() on an empty dataframe (PR#14059)
6982> DF <- data.frame(row.names=1:3)
6983> is.na(DF); str(.Last.value)
6984
69851
69862
69873
6988 logi[1:3, 0 ]
6989 - attr(*, "dimnames")=List of 2
6990  ..$ : chr [1:3] "1" "2" "3"
6991  ..$ : NULL
6992> is.na(DF[FALSE, ]); str(.Last.value)
6993<0 x 0 matrix>
6994 logi[0 , 0 ]
6995> ## first failed in R 2.15.1, second gave NULL
6996>
6997>
6998> ## split() with dots in levels
6999> df <- data.frame(x = rep(c("a", "a.b"), 3L), y = rep(c("b.c", "c"), 3L),
7000+                  z = 1:6)
7001> df
7002    x   y z
70031   a b.c 1
70042 a.b   c 2
70053   a b.c 3
70064 a.b   c 4
70075   a b.c 5
70086 a.b   c 6
7009> split(df, df[, 1:2]) # default is sep = "."
7010$a.b.c
7011    x   y z
70121   a b.c 1
70132 a.b   c 2
70143   a b.c 3
70154 a.b   c 4
70165   a b.c 5
70176 a.b   c 6
7018
7019$a.b.b.c
7020[1] x y z
7021<0 rows> (or 0-length row.names)
7022
7023$a.c
7024[1] x y z
7025<0 rows> (or 0-length row.names)
7026
7027> split(df, df[, 1:2], sep = ":")
7028$`a:b.c`
7029  x   y z
70301 a b.c 1
70313 a b.c 3
70325 a b.c 5
7033
7034$`a.b:b.c`
7035[1] x y z
7036<0 rows> (or 0-length row.names)
7037
7038$`a:c`
7039[1] x y z
7040<0 rows> (or 0-length row.names)
7041
7042$`a.b:c`
7043    x y z
70442 a.b c 2
70454 a.b c 4
70466 a.b c 6
7047
7048> ##
7049>
7050>
7051> ## The difference between sort.list and order
7052> z <- c(4L, NA, 2L, 3L, NA, 1L)
7053> order(z, na.last = NA)
7054[1] 6 3 4 1
7055> sort.list(z, na.last = NA)
7056[1] 4 2 3 1
7057> sort.list(z, na.last = NA, method = "shell")
7058[1] 4 2 3 1
7059> sort.list(z, na.last = NA, method = "quick")
7060[1] 4 2 3 1
7061> sort.list(z, na.last = NA, method = "radix")
7062[1] 4 2 3 1
7063> ## Differences first documented in R 2.15.2
7064>
7065>
7066> ## PR#15028: names longer than cutoff NB (= 1000)
7067> NB <- 1000
7068> lns <- capture.output(
7069+     setNames(c(255, 1000, 30000),
7070+              c(paste(rep.int("a", NB+2), collapse=""),
7071+                paste(rep.int("b", NB+2), collapse=""),
7072+                paste(rep.int("c", NB+2), collapse=""))))
7073> sub("^ +", '', lns[2* 1:3])
7074[1] "255 "   "1000 "  "30000 "
7075> ## *values* were cutoff when printed
7076>
7077>
7078> ## allows deparse limits to be set
7079> form <- reallylongnamey ~ reallylongnamex0 + reallylongnamex1 + reallylongnamex2 + reallylongnamex3
7080> form
7081reallylongnamey ~ reallylongnamex0 + reallylongnamex1 + reallylongnamex2 +
7082    reallylongnamex3
7083> op <- options(deparse.cutoff=80)
7084> form
7085reallylongnamey ~ reallylongnamex0 + reallylongnamex1 + reallylongnamex2 + reallylongnamex3
7086> options(deparse.cutoff=50)
7087> form
7088reallylongnamey ~ reallylongnamex0 + reallylongnamex1 +
7089    reallylongnamex2 + reallylongnamex3
7090> options(op)
7091> ## fixed to 60 in R 2.15.x
7092>
7093>
7094> ## PR#15179: user defined binary ops were not deparsed properly
7095> quote( `%^%`(x, `%^%`(y,z)) )
7096x %^% (y %^% z)
7097> quote( `%^%`(x) )
7098`%^%`(x)
7099> ##
7100>
7101>
7102> ## Anonymous function calls were not deparsed properly
7103> substitute(f(x), list(f = function(x) x + 1))
7104(function(x) x + 1)(x)
7105> substitute(f(x), list(f = quote(function(x) x + 1)))
7106(function(x) x + 1)(x)
7107> substitute(f(x), list(f = quote(f+g)))
7108(f + g)(x)
7109> substitute(f(x), list(f = quote(base::mean)))
7110base::mean(x)
7111> substitute(f(x), list(f = quote(a[n])))
7112a[n](x)
7113> substitute(f(x), list(f = quote(g(y))))
7114g(y)(x)
7115> ## The first three need parens, the last three don't.
7116>
7117>
7118> ## PR#15247 : str() on invalid data frame names (where print() works):
7119> d <- data.frame(1:3, "B", 4, stringsAsFactors=TRUE)
7120> names(d) <- c("A", "B\xba","C\xabcd")
7121> str(d)
7122'data.frame':	3 obs. of  3 variables:
7123 $ A      : int  1 2 3
7124 $ B�  : Factor w/ 1 level "B": 1 1 1
7125 $ C�cd: num  4 4 4
7126> ## gave an error in R <= 3.0.0
7127>
7128>
7129> ## PR#15299 : adding a simple vector to a classed object produced a bad result:
7130> 1:2 + table(1:2)
7131
71321 2
71332 3
7134> ## Printed the class attribute in R <= 3.0.0
7135>
7136>
7137> ## PR#15311 : regmatches<- mishandled regexpr results.
7138>   x <- c('1', 'B', '3')
7139>   m <- regexpr('\\d', x)
7140>   regmatches(x, m) <- c('A', 'C')
7141>   print(x)
7142[1] "A" "B" "C"
7143> ## Gave a warning and a wrong result up to 3.0.1
7144>
7145>
7146> ## Bad warning found by Radford Neal
7147>   saveopt <- options(warnPartialMatchDollar=TRUE)
7148>   pl <- pairlist(abc=1, def=2)
7149>   pl$ab
7150[1] 1
7151Warning message:
7152In pl$ab : partial match of 'ab' to 'abc'
7153>   if (!is.null(saveopt[["warnPartialMatchDollar"]])) options(saveopt)
7154> ## 'abc' was just ''
7155>
7156>
7157> ## seq() with NaN etc inputs now gives explicit error messages
7158> try(seq(NaN))
7159Error in seq.default(NaN) : 'from' must be a finite number
7160> try(seq(to = NaN))
7161Error in seq.default(to = NaN) : 'to' must be a finite number
7162> try(seq(NaN, NaN))
7163Error in seq.default(NaN, NaN) : 'from' must be a finite number
7164> try(seq.int(NaN))
7165Error in seq.int(NaN) : 'from' must be a finite number
7166> try(seq.int(to = NaN))
7167Error in seq.int(to = NaN) : 'to' must be a finite number
7168> try(seq.int(NaN, NaN))
7169Error in seq.int(NaN, NaN) : 'from' must be a finite number
7170> ## R 3.0.1 gave messages from ':' or about negative-length vectors.
7171>
7172>
7173> ## Some dimnames were lost from 1D arrays: PR#15301
7174> x <- array(0:2, dim=3, dimnames=list(d1=LETTERS[1:3]))
7175> x
7176d1
7177A B C
71780 1 2
7179> x[]
7180d1
7181A B C
71820 1 2
7183> x[3:1]
7184d1
7185C B A
71862 1 0
7187> x <- array(0, dimnames=list(d1="A"))
7188> x
7189d1
7190A
71910
7192> x[]
7193d1
7194A
71950
7196> x[drop = FALSE]
7197d1
7198A
71990
7200> ## lost dimnames in 3.0.1
7201>
7202>
7203> ## PR#15396
7204> load(file.path(Sys.getenv('SRCDIR'), 'arima.rda'))
7205> (f1 <- arima(x, xreg = xreg, order = c(1,1,1), seasonal = c(1,0,1)))
7206
7207Call:
7208arima(x = x, order = c(1, 1, 1), seasonal = c(1, 0, 1), xreg = xreg)
7209
7210Coefficients:
7211          ar1     ma1    sar1     sma1    xreg
7212      -0.4791  0.3525  0.9877  -0.8295  0.3574
7213s.e.   0.4162  0.4420  0.0329   0.2209  0.7440
7214
7215sigma^2 estimated as 0.001499:  log likelihood = 163.79,  aic = -315.58
7216> (f2 <- arima(diff(x), xreg = diff(xreg), order = c(1,0,1), seasonal = c(1,0,1),
7217+              include.mean = FALSE))
7218
7219Call:
7220arima(x = diff(x), order = c(1, 0, 1), seasonal = c(1, 0, 1), xreg = diff(xreg),
7221    include.mean = FALSE)
7222
7223Coefficients:
7224          ar1     ma1    sar1     sma1  diff(xreg)
7225      -0.4791  0.3526  0.9877  -0.8295      0.3571
7226s.e.   0.4162  0.4420  0.0329   0.2210      0.7441
7227
7228sigma^2 estimated as 0.001499:  log likelihood = 163.79,  aic = -315.58
7229> stopifnot(all.equal(coef(f1), coef(f2), tolerance = 1e-3, check.names = FALSE))
7230> ## first gave local optim in 3.0.1
7231>
7232> ## all.equal always checked the names
7233> x <- c(a=1, b=2)
7234> y <- c(a=1, d=2)
7235> all.equal(x, y, check.names = FALSE)
7236[1] TRUE
7237> ## failed on mismatched attributes
7238>
7239>
7240> ## PR#15411, plus digits change
7241> format(9992, digits = 3)
7242[1] "9992"
7243> format(9996, digits = 3)
7244[1] "9996"
7245> format(0.0002, digits = 0, nsmall = 2)
7246[1] "0.00"
7247> format(pi*10, digits = 0, nsmall = 1)
7248[1] "31.4"
7249> ## second added an extra space; 3rd and 4th were not allowed.
7250>
7251> ## and one branch of this was wrong:
7252> xx <- c(-86870268, 107833358, 302536985, 481015309, 675718935, 854197259,
7253+         1016450281, 1178703303, 1324731023, 1454533441)
7254> xx
7255 [1]  -86870268  107833358  302536985  481015309  675718935  854197259
7256 [7] 1016450281 1178703303 1324731023 1454533441
7257> ## dropped spaces without long doubles
7258>
7259> ## and rounding was being detected improperly (PR#15583)
7260> 1000* ((10^(1/4)) ^ c(0:4))
7261[1]  1000.000  1778.279  3162.278  5623.413 10000.000
7262> 7/0.07
7263[1] 100
7264> ## Spacing was incorrect
7265>
7266>
7267> ## PR#15468
7268> M <- matrix(11:14, ncol=2, dimnames=list(paste0("Row", 1:2), paste0("Col",
7269+ 1:2)))
7270> L <- list(elem1=1, elem2=2)
7271> rbind(M, L)
7272     Col1 Col2
7273Row1 11   13
7274Row2 12   14
7275L    1    2
7276> rbind(L, M)
7277     elem1 elem2
7278L    1     2
7279Row1 11    13
7280Row2 12    14
7281> cbind(M, L)
7282     Col1 Col2 L
7283Row1 11   13   1
7284Row2 12   14   2
7285> cbind(L, M)
7286      L Col1 Col2
7287elem1 1 11   13
7288elem2 2 12   14
7289> ## lost the dim of M, so returned NULL entries
7290>
7291>
7292> ## NA_character_ was not handled properly in min and max (reported by Magnus Thor Torfason)
7293> str(min(NA, "bla"))
7294 chr NA
7295> str(min("bla", NA))
7296 chr NA
7297> str(min(NA_character_, "bla"))
7298 chr NA
7299> str(max(NA, "bla"))
7300 chr NA
7301> str(max("bla", NA))
7302 chr NA
7303> str(max(NA_character_, "bla"))
7304 chr NA
7305> ## NA_character_ could be treated as "NA"; depending on the locale, it would not necessarily
7306> ## be the min or max.
7307>
7308>
7309> ## When two entries needed to be cut to width, str() mixed up
7310> ## the values (reported by Gerrit Eichner)
7311> oldopts <- options(width=70)
7312> n <- 11      # number of rows of data frame
7313> M <- 10000   # order of magnitude of numerical values
7314> longer.char.string <- "zjtvorkmoydsepnxkabmeondrjaanutjmfxlgzmrbjp"
7315> X <- data.frame( A = 1:n * M,
7316+                  B = factor(rep(longer.char.string, n)))
7317> str( X, strict.width = "cut")
7318'data.frame':	11 obs. of  2 variables:
7319 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
7320 $ B: Factor w/ 1 level "zjtvorkmoydsepnxkabmeondrjaanutjmfxlgzmrbj"..
7321> options(oldopts)
7322> ## The first row of the str() result was duplicated.
7323>
7324>
7325> ## PR15624: rounding in extreme cases
7326> dpois(2^52,1,1)
7327[1] -1.578226e+17
7328> dpois(2^52+1,1,1)
7329[1] -1.578226e+17
7330> ## second warned in R 3.0.2.
7331>
7332>
7333> ## Example from PR15625
7334> f <- file.path(Sys.getenv('SRCDIR'), 'EmbeddedNuls.csv')
7335> ## This is a file with a UTF-8 BOM and some fields which are a single nul.
7336> ## The output does rely on this being run in a non-UTF-8 locale (C in tests).
7337> read.csv(f) # warns
7338  X...ColA ColB ColC
73391        a   NA   NA
73402        b   NA   NA
73413        c   NA   NA
73424        d   NA   NA
73435        e   NA    1
73446        f   NA    1
7345Warning messages:
73461: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7347  line 2 appears to contain embedded nulls
73482: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7349  line 3 appears to contain embedded nulls
73503: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7351  line 4 appears to contain embedded nulls
73524: In read.table(file = file, header = header, sep = sep, quote = quote,  :
7353  line 5 appears to contain embedded nulls
73545: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
7355  embedded nul(s) found in input
7356> read.csv(f, skipNul = TRUE, fileEncoding = "UTF-8-BOM")
7357  ColA ColB ColC
73581    a   NA    1
73592    b   NA    1
73603    c   NA    1
73614    d   NA    1
73625    e   NA    1
73636    f   NA    1
7364> ## 'skipNul' is new in 3.1.0.  Should not warn on BOM, ignore in second.
7365>
7366>
7367> ## all.equal datetime method
7368> x <- Sys.time()
7369> all.equal(x,x)
7370[1] TRUE
7371>
7372> # FIXME: check.tzone = FALSE needed because since 79037, all.equal.POSIXt
7373> # strictly reports "" and the current time zone (even from TZ environment
7374> # variable) as different.  The conversion round-trip from Sys.time()
7375> # (POSIXct) via POSIXlt and back to POSIXct creates an object with the
7376> # current time zone, yet the original is with "" as time zone (and both
7377> # refer to the same time zone).
7378> all.equal(x, as.POSIXlt(x), check.tzone = FALSE)
7379[1] TRUE
7380>
7381> all.equal(x, as.numeric(x))  # errored in R <= 4.0.2
7382[1] "'current' is not a POSIXt"
7383> all.equal(x, as.POSIXlt(x, tz = "EST5EDT"))
7384[1] "'tzone' attributes are inconsistent ('' and 'EST5EDT')"
7385> all.equal(x, x+1e-4)
7386[1] TRUE
7387> isTRUE(all.equal(x, x+0.002)) # message will depend on representation error
7388[1] FALSE
7389> ## as.POSIXt method is new in 3.1.0.
7390>
7391>
7392>
7393> ## Misuse of PR#15633
7394> try(bartlett.test(yield ~ block*N, data = npk))
7395Error in bartlett.test.formula(yield ~ block * N, data = npk) :
7396  'formula' should be of the form response ~ group
7397> try(fligner.test (yield ~ block*N, data = npk))
7398Error in fligner.test.formula(yield ~ block * N, data = npk) :
7399  'formula' should be of the form response ~ group
7400> ## used the first factor with an incorrect description in R < 3.0.3
7401>
7402>
7403> ## Misguided expectation of PR#15687
7404> xx <- window(AirPassengers, start = 1960)
7405> cbind(xx, xx)
7406          xx  xx
7407Jan 1960 417 417
7408Feb 1960 391 391
7409Mar 1960 419 419
7410Apr 1960 461 461
7411May 1960 472 472
7412Jun 1960 535 535
7413Jul 1960 622 622
7414Aug 1960 606 606
7415Sep 1960 508 508
7416Oct 1960 461 461
7417Nov 1960 390 390
7418Dec 1960 432 432
7419> op <- options(digits = 2)
7420> cbind(xx, xx)
7421          xx  xx
7422Jan 1960 417 417
7423Feb 1960 391 391
7424Mar 1960 419 419
7425Apr 1960 461 461
7426May 1960 472 472
7427Jun 1960 535 535
7428Jul 1960 622 622
7429Aug 1960 606 606
7430Sep 1960 508 508
7431Oct 1960 461 461
7432Nov 1960 390 390
7433Dec 1960 432 432
7434> options(op)
7435> ## 'digits' was applied to the time.
7436>
7437>
7438> ## Related to PR#15190
7439> difftime(
7440+     as.POSIXct(c("1970-01-01 00:00:00", "1970-01-01 12:00:00"), tz="EST5EDT"),
7441+     as.POSIXct(c("1970-01-01 00:00:00", "1970-01-01 00:00:00"), tz="UTC"))
7442Time differences in hours
7443[1]  5 17
7444> ## kept tzone from first arg.
7445>
7446>
7447> ## PR#15706
7448> x1 <- as.dendrogram(hclust(dist(c(i=1,ii=2,iii=3,v=5,vi=6,vii=7))))
7449> attr(cophenetic(x1), "Labels")
7450[1] "iii" "i"   "ii"  "vii" "v"   "vi"
7451> ## gave a matrix in 3.0.3
7452>
7453>
7454> ## PR#15708
7455> aa <- anova( lm(sr ~ ., data = LifeCycleSavings) )
7456> op <- options(width = 50)
7457> aa
7458Analysis of Variance Table
7459
7460Response: sr
7461          Df Sum Sq Mean Sq F value    Pr(>F)
7462pop15      1 204.12 204.118 14.1157 0.0004922 ***
7463pop75      1  53.34  53.343  3.6889 0.0611255 .
7464dpi        1  12.40  12.401  0.8576 0.3593551
7465ddpi       1  63.05  63.054  4.3605 0.0424711 *
7466Residuals 45 650.71  14.460
7467---
7468Signif. codes:
74690 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
7470> options(width = 40)
7471> aa ; options(op)
7472Analysis of Variance Table
7473
7474Response: sr
7475          Df Sum Sq Mean Sq F value
7476pop15      1 204.12 204.118 14.1157
7477pop75      1  53.34  53.343  3.6889
7478dpi        1  12.40  12.401  0.8576
7479ddpi       1  63.05  63.054  4.3605
7480Residuals 45 650.71  14.460
7481             Pr(>F)
7482pop15     0.0004922 ***
7483pop75     0.0611255 .
7484dpi       0.3593551
7485ddpi      0.0424711 *
7486Residuals
7487---
7488Signif. codes:
7489  0 '***' 0.001 '**' 0.01 '*' 0.05
7490  '.' 0.1 ' ' 1
7491> ## did not line wrap "Signif. codes" previously
7492>
7493>
7494> ## PR#15718
7495> d <- data.frame(a=1)
7496> d[integer(), "a"] <- 2
7497> ## warned in 3.0.3.
7498>
7499>
7500> ## PR#15781
7501> options(foo = 1)
7502> print(options(foo = NULL))
7503$foo
7504[1] 1
7505
7506> ## printed wrong value in 3.1.0
7507>
7508>
7509> ## getParseData bug reported by Andrew Redd
7510> raw <- "
7511+ function( a   # parameter 1
7512+          , b=2 # parameter 2
7513+          ){a+b}"
7514> p <- parse(text = raw)
7515> getParseData(p)
7516   line1 col1 line2 col2 id parent          token terminal          text
751732     2    1     4   15 32      0           expr    FALSE
75183      2    1     2    8  3     32       FUNCTION     TRUE      function
75194      2    9     2    9  4     32            '('     TRUE             (
75205      2   11     2   11  5     32 SYMBOL_FORMALS     TRUE             a
75216      2   15     2   27  6     32        COMMENT     TRUE # parameter 1
75228      3   10     3   10  8     32            ','     TRUE             ,
752310     3   12     3   12 10     32 SYMBOL_FORMALS     TRUE             b
752411     3   13     3   13 11     32     EQ_FORMALS     TRUE             =
752512     3   14     3   14 12     13      NUM_CONST     TRUE             2
752613     3   14     3   14 13     32           expr    FALSE
752714     3   16     3   28 14     32        COMMENT     TRUE # parameter 2
752816     4   10     4   10 16     32            ')'     TRUE             )
752929     4   11     4   15 29     32           expr    FALSE
753019     4   11     4   11 19     29            '{'     TRUE             {
753126     4   12     4   14 26     29           expr    FALSE
753220     4   12     4   12 20     22         SYMBOL     TRUE             a
753322     4   12     4   12 22     26           expr    FALSE
753421     4   13     4   13 21     26            '+'     TRUE             +
753523     4   14     4   14 23     25         SYMBOL     TRUE             b
753625     4   14     4   14 25     26           expr    FALSE
753724     4   15     4   15 24     29            '}'     TRUE             }
7538> ## Got some parents wrong
7539>
7540>
7541> ## wish of PR#15819
7542> set.seed(123); x <- runif(10); y <- rnorm(10)
7543> op <- options(OutDec = ",")
7544> fit <- lm(y ~ x)
7545> summary(fit)
7546
7547Call:
7548lm(formula = y ~ x)
7549
7550Residuals:
7551     Min       1Q   Median       3Q      Max
7552-1,62155 -0,33471  0,05238  0,55227  1,19742
7553
7554Coefficients:
7555            Estimate Std. Error t value Pr(>|t|)
7556(Intercept)   0,8994     0,6282   1,432    0,190
7557x            -1,3275     0,9780  -1,357    0,212
7558
7559Residual standard error: 0,8648 on 8 degrees of freedom
7560Multiple R-squared:  0,1872,	Adjusted R-squared:  0,08557
7561F-statistic: 1,842 on 1 and 8 DF,  p-value: 0,2117
7562
7563> options(op)
7564> ## those parts using formatC still used a decimal point.
7565>
7566>
7567> ## Printing a list with "bad" component names
7568> L <- list(`a\\b` = 1, `a\\c` = 2, `a\bc` = "backspace")
7569> setClass("foo", representation(`\\C` = "numeric"))
7570> ## the next three all print correctly:
7571> names(L)
7572[1] "a\\b" "a\\c" "a\bc"
7573> unlist(L)
7574       a\\b        a\\c        a\bc
7575        "1"         "2" "backspace"
7576> as.pairlist(L)
7577$`a\\b`
7578[1] 1
7579
7580$`a\\c`
7581[1] 2
7582
7583$`a\bc`
7584[1] "backspace"
7585
7586> cat(names(L), "\n")# yes, backspace is backspace here
7587a\b a\c ac
7588> L
7589$`a\\b`
7590[1] 1
7591
7592$`a\\c`
7593[1] 2
7594
7595$`a\bc`
7596[1] "backspace"
7597
7598> new("foo")
7599An object of class "foo"
7600Slot "\\C":
7601numeric(0)
7602
7603> ## the last two lines printed wrongly in R <= 3.1.1
7604>
7605>
7606> ## Printing of arrays where last dim(.) == 0 :
7607> r <- matrix(,0,4, dimnames=list(Row=NULL, Col=paste0("c",1:4)))
7608> r
7609      Col
7610Row    c1 c2 c3 c4
7611> t(r) # did not print "Row", "Col"
7612    Row
7613Col
7614  c1
7615  c2
7616  c3
7617  c4
7618> A <- array(dim=3:0, dimnames=list(D1=c("a","b","c"), D2=c("X","Y"), D3="I", D4=NULL))
7619> A ## did not print *anything*
7620<3 x 2 x 1 x 0 array of logical>
7621   D2
7622D1  X Y
7623  a
7624  b
7625  c
7626
7627> A[,,"I",] # ditto
7628<3 x 2 x 0 array of logical>
7629   D2
7630D1  X Y
7631  a
7632  b
7633  c
7634
7635> A[,,0,]   # ditto
7636<3 x 2 x 0 x 0 array of logical>
7637   D2
7638D1  X Y
7639  a
7640  b
7641  c
7642
7643> aperm(A, c(3:1,4))   # ditto
7644<1 x 2 x 3 x 0 array of logical>
7645   D2
7646D3  X Y
7647  I
7648
7649> aperm(A, c(1:2, 4:3))# ditto
7650<3 x 2 x 0 x 1 array of logical>
7651   D2
7652D1  X Y
7653  a
7654  b
7655  c
7656
7657> unname(A)            # ditto
7658<3 x 2 x 1 x 0 array of logical>
7659     [,1] [,2]
7660[1,]
7661[2,]
7662[3,]
7663
7664> format(A[,,1,])	     # ditto
7665<3 x 2 x 0 array of character>
7666   D2
7667D1  X Y
7668  a
7669  b
7670  c
7671
7672> aperm(A, 4:1) # was ok, is unchanged
7673, , D2 = X, D1 = a
7674
7675      D3
7676D4     I
7677
7678, , D2 = Y, D1 = a
7679
7680      D3
7681D4     I
7682
7683, , D2 = X, D1 = b
7684
7685      D3
7686D4     I
7687
7688, , D2 = Y, D1 = b
7689
7690      D3
7691D4     I
7692
7693, , D2 = X, D1 = c
7694
7695      D3
7696D4     I
7697
7698, , D2 = Y, D1 = c
7699
7700      D3
7701D4     I
7702
7703> ## sometimes not printing anything in R <= 3.1.1
7704>
7705>
7706> ## Printing objects with very long names cut off literal values (PR#15999)
7707> make_long_name <- function(n)
7708+ {
7709+   paste0(rep("a", n), collapse = "")
7710+ }
7711> setNames(TRUE, make_long_name(1000))  # value printed as TRU
7712aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7713                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   TRUE
7714> setNames(TRUE, make_long_name(1002))  # value printed as T
7715aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7716                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   TRUE
7717> setNames(TRUE, make_long_name(1003))  # value not printed
7718aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
7719                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   TRUE
7720> ##
7721>
7722>
7723> ## PR#16437
7724> dd <- data.frame(F = factor(rep(c("A","B","C"), each = 3)), num = 1:9)
7725> cs <- list(F = contr.sum(3, contrasts = FALSE))
7726> a1 <- aov(num ~ F, data = dd, contrasts = cs)
7727> model.tables(a1, "means")
7728Tables of means
7729Grand mean
7730
77315
7732
7733 F
7734F
7735A B C
77362 5 8
7737> t1 <- TukeyHSD(a1) ## don't print to avoid precision issues.
7738> a2 <- aov(num ~ 0+F, data = dd, contrasts = cs)
7739> model.tables(a2, "means")
7740Tables of means
7741
7742 F
7743F
7744A B C
77452 5 8
7746> t2 <- TukeyHSD(a2)
7747> attr(t1, "orig.call") <- attr(t2, "orig.call")
7748> stopifnot(all.equal(t1, t2))
7749> ## functions both failed on a2 in R <= 3.2.2.
7750>
7751>
7752> ## deparse() did not add parens before [
7753> substitute(a[1], list(a = quote(x * y)))
7754(x * y)[1]
7755> ## should be (x * y)[1], was x * y[1]
7756> # Check all levels of precedence
7757> # (Comment out illegal ones)
7758> quote(`$`(a :: b, c))
7759a::b$c
7760> # quote(`::`(a $ b, c $ d))
7761> quote(`[`(a $ b, c $ d))
7762a$b[c$d]
7763> quote(`$`(a[b], c))
7764a[b]$c
7765> quote(`^`(a[b], c[d]))
7766a[b]^c[d]
7767> quote(`[`(a ^ b, c ^ d))
7768(a^b)[c^d]
7769> quote(`-`(a ^ b))
7770-a^b
7771> quote(`^`(-b, -d))
7772(-b)^-d
7773> quote(`:`(-b, -d))
7774-b:-d
7775> quote(`-`(a : b))
7776-(a:b)
7777> quote(`%in%`(a : b, c : d))
7778a:b %in% c:d
7779> quote(`:`(a %in% b, c %in% d))
7780(a %in% b):(c %in% d)
7781> quote(`*`(a %in% b, c %in% d))
7782a %in% b * c %in% d
7783> quote(`%in%`(a * b, c * d))
7784(a * b) %in% (c * d)
7785> quote(`+`(a * b, c * d))
7786a * b + c * d
7787> quote(`*`(a + b, c + d))
7788(a + b) * (c + d)
7789> quote(`<`(a + b, c + d))
7790a + b < c + d
7791> quote(`+`(a < b, c < d))
7792(a < b) + (c < d)
7793> quote(`!`(a < b))
7794!a < b
7795> quote(`<`(!b, !d))
7796(!b) < !d
7797> quote(`&`(!b, !d))
7798!b & !d
7799> quote(`!`(a & b))
7800!(a & b)
7801> quote(`|`(a & b, c & d))
7802a & b | c & d
7803> quote(`&`(a | b, c | d))
7804(a | b) & (c | d)
7805> quote(`~`(a | b, c | d))
7806a | b ~ c | d
7807> quote(`|`(a ~ b, c ~ d))
7808(a ~ b) | (c ~ d)
7809> quote(`->`(a ~ b, d))
7810`->`(a ~ b, d)
7811> quote(`~`(a -> b, c -> d))
7812(b <- a) ~ (d <- c)
7813> quote(`<-`(a, c -> d))
7814a <- d <- c
7815> quote(`->`(a <- b, c))
7816`->`(a <- b, c)
7817> quote(`=`(a, c <- d))
7818a = c <- d
7819> quote(`<-`(a, `=`(c, d)))
7820a <- (c = d)
7821> quote(`?`(`=`(a, b), `=`(c, d)))
7822`?`((a = b), (c = d))
7823> quote(`=`(a, c ? d))
7824a = `?`(c, d)
7825> quote(`?`(a = b))
7826`?`(a = b)
7827> quote(`=`(b, ?d))
7828b = `?`(d)
7829>
7830> ## dput() quoted the empty symbol (PR#16686)
7831> a <- alist(one = 1, two = )
7832> dput(a)
7833list(one = 1, two = )
7834> ## deparsed two to quote()
7835>
7836> ## Deparsing of repeated unary operators; the first 3 were "always" ok:
7837> quote(~~x)
7838~~x
7839> quote(++x)
7840++x
7841> quote(--x)
7842--x
7843> quote(!!x) # was `!(!x)`
7844!!x
7845> quote(??x) # Suboptimal
7846`?`(`?`(x))
7847> quote(~+-!?x) # ditto: ....`?`(x)
7848~+-!`?`(x)
7849> ## `!` no longer produces parentheses now
7850>
7851>
7852> ## summary.data.frame() with NAs in columns of class "Date" -- PR#16709
7853> x <- c(18000000, 18810924, 19091227, 19027233, 19310526, 19691228, NA)
7854> x.Date <- as.Date(as.character(x), format = "%Y%m%d")
7855> summary(x.Date)
7856        Min.      1st Qu.       Median         Mean      3rd Qu.         Max.
7857"1881-09-24" "1902-12-04" "1920-09-10" "1923-04-12" "1941-01-17" "1969-12-28"
7858        NA's
7859         "3"
7860> DF.Dates <- data.frame(c1 = x.Date)
7861> summary(DF.Dates) ## NA's missing from output :
7862       c1
7863 Min.   :1881-09-24
7864 1st Qu.:1902-12-04
7865 Median :1920-09-10
7866 Mean   :1923-04-12
7867 3rd Qu.:1941-01-17
7868 Max.   :1969-12-28
7869 NA's   :3
7870> DF.Dates$x1 <- 1:7
7871> summary(DF.Dates) ## NA's still missing
7872       c1                   x1
7873 Min.   :1881-09-24   Min.   :1.0
7874 1st Qu.:1902-12-04   1st Qu.:2.5
7875 Median :1920-09-10   Median :4.0
7876 Mean   :1923-04-12   Mean   :4.0
7877 3rd Qu.:1941-01-17   3rd Qu.:5.5
7878 Max.   :1969-12-28   Max.   :7.0
7879 NA's   :3
7880> DF.Dates$x2 <- c(1:6, NA)
7881> ## now, NA's show fine:
7882> summary(DF.Dates)
7883       c1                   x1            x2
7884 Min.   :1881-09-24   Min.   :1.0   Min.   :1.00
7885 1st Qu.:1902-12-04   1st Qu.:2.5   1st Qu.:2.25
7886 Median :1920-09-10   Median :4.0   Median :3.50
7887 Mean   :1923-04-12   Mean   :4.0   Mean   :3.50
7888 3rd Qu.:1941-01-17   3rd Qu.:5.5   3rd Qu.:4.75
7889 Max.   :1969-12-28   Max.   :7.0   Max.   :6.00
7890 NA's   :3                          NA's   :1
7891> ## 2 of 4  summary(.) above did not show NA's  in R <= 3.2.3
7892>
7893>
7894> ## Printing complex matrix
7895> matrix(1i,2,13)
7896     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
7897[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
7898[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
7899> ## Spacing was wrong in R <= 3.2.4
7900>
7901>
7902> E <- expression(poly = x^3 - 3 * x^2)
7903> str(E)
7904  expression(poly = x^3 - 3 * x^2)
7905> ## no longer shows "structure(...., .Names = ..)"
7906>
7907>
7908> ## summary(<logical>) working via table():
7909> logi <- c(NA, logical(3), NA, !logical(2), NA)
7910> summary(logi)
7911   Mode   FALSE    TRUE    NA's
7912logical       3       2       3
7913> summary(logi[!is.na(logi)])
7914   Mode   FALSE    TRUE
7915logical       3       2
7916> summary(TRUE)
7917   Mode    TRUE
7918logical       1
7919> ## was always showing counts for NA's even when 0 in  2.8.0 <= R <= 3.3.1
7920> ii <- as.integer(logi)
7921> summary(ii)
7922   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
7923    0.0     0.0     0.0     0.4     1.0     1.0       3
7924> summary(ii[!is.na(ii)])
7925   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
7926    0.0     0.0     0.0     0.4     1.0     1.0
7927> summary(1L)
7928   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
7929      1       1       1       1       1       1
7930>
7931>
7932> ## str.default() for "AsIs" arrays
7933> str(I(m <- matrix(pi*1:4, 2)))
7934 'AsIs' num [1:2, 1:2] 3.14 6.28 9.42 12.57
7935> ## did look ugly (because of toString() for numbers) in R <= 3.3.1
7936>
7937>
7938> ## check automatic coercions from double to integer
7939> ##
7940> ## these should work due to coercion
7941> sprintf("%d", 1)
7942[1] "1"
7943> sprintf("%d", NA_real_)
7944[1] "NA"
7945> sprintf("%d", c(1,2))
7946[1] "1" "2"
7947> sprintf("%d", c(1,NA))
7948[1] "1"  "NA"
7949> sprintf("%d", c(NA,1))
7950[1] "NA" "1"
7951> ##
7952> ## these should fail
7953> assertErrorV( sprintf("%d", 1.1) )
7954Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7955> assertErrorV( sprintf("%d", c(1.1,1)) )
7956Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7957> assertErrorV( sprintf("%d", c(1,1.1)) )
7958Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7959> assertErrorV( sprintf("%d", NaN) )
7960Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7961> assertErrorV( sprintf("%d", c(1,NaN)) )
7962Asserted error: invalid format '%d'; use format %f, %e, %g or %a for numeric objects
7963>
7964>
7965> ## formatting of named raws:
7966> setNames(as.raw(1:3), c("a", "bbbb", "c"))
7967   a bbbb    c
7968  01   02   03
7969> ## was quite ugly for R <= 3.4.2
7970>
7971>
7972> ## str(x) when is.vector(x) is false :
7973> str(structure(c(a = 1, b = 2:7), color = "blue"))
7974 Named num [1:7] 1 2 3 4 5 6 7
7975 - attr(*, "names")= chr [1:7] "a" "b1" "b2" "b3" ...
7976 - attr(*, "color")= chr "blue"
7977> ## did print " atomic [1:7] ..." in R <= 3.4.x
7978>
7979>
7980> ## check stopifnot(exprs = ....)
7981> tryCatch(stopifnot(exprs = {
7982+   all.equal(pi, 3.1415927)
7983+   2 < 2
7984+   cat("Kilroy was here!\n")
7985+   all(1:10 < 12)
7986+   "a" < "b"
7987+ }), error = function(e) e$message) -> M ; cat("Error: ", M, "\n")
7988Error:  2 < 2 is not TRUE
7989>
7990> tryCatch(stopifnot(exprs = {
7991+   all.equal(pi, 3.1415927)
7992+   { cat("Kilroy was here!\n"); TRUE }
7993+   pi < 3
7994+   cat("whereas I won't be printed ...\n")
7995+   all(1:10 < 12)
7996+   "a" < "b"
7997+ }), error = function(e) e$message) -> M2 ; cat("Error: ", M2, "\n")
7998Kilroy was here!
7999Error:  pi < 3 is not TRUE
8000>
8001> stopifnot(exprs = {
8002+   all.equal(pi, 3.1415927)
8003+   { cat("\nKilroy was here! ... "); TRUE }
8004+   pi > 3
8005+   all(1:10 < 12)
8006+   "a" < "b"
8007+   { cat("and I'm printed as well ...\n"); TRUE}
8008+ })
8009
8010Kilroy was here! ... and I'm printed as well ...
8011> ## without "{ .. }" :
8012> stopifnot(exprs = 2 == 2)
8013> try(stopifnot(exprs = 1 > 2))
8014Error : 1 > 2 is not TRUE
8015> ## passing an expression object:
8016> stopifnot(exprObject = expression(2 == 2, pi < 4))
8017> tryCatch(stopifnot(exprObject = expression(
8018+                        2 == 2,
8019+                        { cat("\n Kilroy again .."); TRUE },
8020+                        pi < 4,
8021+                        0 == 1,
8022+                        { cat("\n no way..\n"); TRUE })),
8023+          error = function(e) e$message) -> M3
8024
8025 Kilroy again ..> cat("Error: ", M3, "\n")
8026Error:  0 == 1 is not TRUE
8027> ## was partly not ok for many weeks in R-devel, early 2018
8028>
8029>
8030> ## print.htest() with small 'digits'
8031> print(t.test(1:28), digits = 3)
8032
8033	One Sample t-test
8034
8035data:  1:28
8036t = 9, df = 27, p-value = 6e-10
8037alternative hypothesis: true mean is not equal to 0
803895 percent confidence interval:
8039 11.3 17.7
8040sample estimates:
8041mean of x
8042     14.5
8043
8044> ## showed 'df = 30' from signif(*, digits=1) and too many digits for CI, in R <= 3.5.1
8045>
8046>
8047> ## str(<d.frame w/ attrib>):
8048> treeA <- trees
8049> attr(treeA, "someA") <- 1:77
8050> str(treeA)
8051'data.frame':	31 obs. of  3 variables:
8052 $ Girth : num  8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
8053 $ Height: num  70 65 63 72 81 83 66 75 80 75 ...
8054 $ Volume: num  10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...
8055 - attr(*, "someA")= int [1:77] 1 2 3 4 5 6 7 8 9 10 ...
8056> ## now shows the *length* of "someA"
8057>
8058>
8059> ## summaryRprof() bug PR#15886  + "Rprof() not enabled" PR#17836
8060> if(capabilities("Rprof")) {
8061+     Rprof(tf <- tempfile("Rprof.out", tmpdir = getwd()), memory.profiling=TRUE, line.profiling=FALSE)
8062+     out <- lapply(1:10000, rnorm, n= 512)
8063+     Rprof(NULL)
8064+     if(interactive())
8065+         print(length(readLines(tf))) # ca. 10 .. 20 lines
8066+     op <- options(warn = 2) # no warnings, even !
8067+     for (cs in 1:21) s <- summaryRprof(tf, memory="tseries", chunksize=cs)
8068+     ## "always" triggered an error (or a warning) in R <= 3.6.3
8069+     options(op)
8070+     unlink(tf)
8071+ }
8072>
8073>
8074> ## printing *named* complex vectors (*not* arrays), PR#17868 (and PR#18019):
8075> a <- 1:12; (z <- a + a*1i); names(z) <- letters[seq_along(z)]; z
8076 [1]  1+ 1i  2+ 2i  3+ 3i  4+ 4i  5+ 5i  6+ 6i  7+ 7i  8+ 8i  9+ 9i 10+10i
8077[11] 11+11i 12+12i
8078     a      b      c      d      e      f      g      h      i      j      k
8079 1+ 1i  2+ 2i  3+ 3i  4+ 4i  5+ 5i  6+ 6i  7+ 7i  8+ 8i  9+ 9i 10+10i 11+11i
8080     l
808112+12i
8082> ## fixed in R-devel in July 2020;  R 4.0.3 patched on Dec 26, 2020
8083>
8084>
8085> ## identical(*) on "..." object
8086> (ddd <- (function(...) environment())(1)$...) # <...>
8087<...>
8088>  dd2 <- (function(...) environment())(1)$...
8089> stopifnot( identical(ddd, dd2) )
8090> ## In R <= 4.0.3,  printed to console (no warning, no message!):
8091> ## "Unknown Type: ... (11)"
8092>
8093>
8094> ## printCoefmat() should keep NaN values (PR#17336)
8095> ##cm <- summary(lm(c(0,0,0) ~ 1))$coefficients
8096> cm <- cbind(Estimate = 0, SE = 0, t = NaN, "Pr(>|t|)" = NaN)
8097> printCoefmat(cm)  # NaN's were replaced by NA in R < 4.1.0
8098     Estimate SE   t Pr(>|t|)
8099[1,]        0  0 NaN      NaN
8100>
8101