R version 3.6.0 beta (2019-04-15 r76395) -- "Planting of a Tree" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ### Regression tests for which the printed output is the issue > ### May fail. > ### Skipped on a Unix-alike without Recommended packages > > pdf("reg-tests-3.pdf", encoding = "ISOLatin1.enc") > > ## str() for character & factors with NA (levels), and for Surv objects: > ff <- factor(c(2:1, NA), exclude = NULL) > str(levels(ff)) chr [1:3] "1" "2" NA > str(ff) Factor w/ 3 levels "1","2",NA: 2 1 3 > str(ordered(ff, exclude=NULL)) Ord.factor w/ 3 levels "1"<"2" if(require(survival)) { + (sa <- Surv(aml$time, aml$status)) + str(sa) + detach("package:survival", unload = TRUE) + } Loading required package: survival 'Surv' num [1:23, 1:2] 9 13 13+ 18 23 28+ 31 34 45+ 48 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:2] "time" "status" - attr(*, "type")= chr "right" > ## were different, the last one failed in 1.6.2 (at least) > > > ## lm.influence where hat[1] == 1 > if(require(MASS)) { + fit <- lm(formula = 1000/MPG.city ~ Weight + Cylinders + Type + EngineSize + DriveTrain, data = Cars93) + print(lm.influence(fit)) + ## row 57 should have hat = 1 and resid=0. + summary(influence.measures(fit)) + } Loading required package: MASS $hat 1 2 3 4 5 6 7 0.09313909 0.07134091 0.19138434 0.08101081 0.24991662 0.10448752 0.12591828 8 9 10 11 12 13 14 0.39348171 0.10008864 0.23497010 0.27831516 0.11499791 0.06684324 0.16777903 15 16 17 18 19 20 21 0.10418769 0.19438856 0.22249600 0.18531791 0.42832529 0.13160780 0.11571055 22 23 24 25 26 27 28 0.13542772 0.05989558 0.09115955 0.07274599 0.16979948 0.10059554 0.36420370 29 30 31 32 33 34 35 0.05892084 0.12226683 0.14266192 0.06389391 0.07851639 0.16317503 0.10514036 36 37 38 39 40 41 42 0.16620182 0.07407892 0.21406715 0.35800879 0.11660151 0.12115515 0.05846839 43 44 45 46 47 48 49 0.07915006 0.05841339 0.07599254 0.14272015 0.10370606 0.22461698 0.07423925 50 51 52 53 54 55 56 0.16054084 0.10007740 0.22613089 0.05679789 0.05802486 0.07274599 0.16620182 57 58 59 60 61 62 63 1.00000000 0.16034032 0.14337335 0.11805892 0.13059078 0.05892084 0.10869261 64 65 66 67 68 69 70 0.07024346 0.07721617 0.25915706 0.08887161 0.06631974 0.10330515 0.19438856 71 72 73 74 75 76 77 0.12591828 0.21538400 0.05645115 0.08933216 0.16777903 0.07190036 0.12435356 78 79 80 81 82 83 84 0.06735745 0.06233173 0.40499233 0.20574068 0.20315406 0.35602282 0.08812076 85 86 87 88 89 90 91 0.13555308 0.09482733 0.24869622 0.06728598 0.57312772 0.08142621 0.15694445 92 93 0.15864447 0.57312772 $coefficients (Intercept) Weight Cylinders4 Cylinders5 Cylinders6 1 -0.8045874665 2.867170e-04 -3.820998e-03 -0.121186522 -0.085652499 2 -0.1624020957 7.405395e-05 -3.377846e-02 -0.058135639 0.032561909 3 0.0730227014 -1.000408e-04 2.635594e-02 -0.038987943 -0.136284069 4 0.0154995743 8.165607e-06 5.679643e-03 0.005807148 0.050432610 5 2.0624972203 -5.727657e-04 4.651265e-01 1.314202802 1.689003061 6 0.1889725900 -8.408128e-05 3.552355e-02 -0.042386516 -0.038483733 7 0.0288527501 -1.891425e-05 4.221544e-03 0.012091377 0.008077810 8 -0.9237858418 3.777463e-06 -2.504289e-01 -0.282474268 -0.778087752 9 0.0027522480 9.783189e-05 2.129655e-02 -0.007988299 0.014432116 10 0.9903462340 -5.169747e-04 1.630209e-01 0.294911151 0.129970424 11 -0.5182963206 1.916075e-04 -1.215727e-01 -0.226050823 -0.161523754 12 -0.6387428727 2.494952e-04 -1.008869e-01 -0.179703222 -0.143884548 13 -0.3568385025 7.917221e-05 -2.534541e-02 -0.028384831 -0.029395607 14 -0.0077820700 -4.699458e-06 -1.266873e-03 0.041173344 0.053631137 15 -0.2615585508 1.297214e-04 -5.490059e-02 -0.275540505 -0.222909574 16 -0.0195241852 2.061693e-04 6.572061e-02 0.294616782 0.074266087 17 0.0965040227 -1.534149e-04 1.527511e-02 -0.028420127 -0.112348604 18 0.0048862795 -1.111273e-06 1.332650e-03 0.001477077 0.001007189 19 -0.1837125526 1.943923e-04 -1.515756e-02 -0.122275191 0.014588114 20 0.0080448668 -3.212441e-05 -2.747115e-03 0.002147238 -0.048260808 21 0.3062320767 -7.003532e-05 1.382568e-01 0.212411378 0.364192354 22 0.0834715351 -7.391740e-05 1.122255e-02 0.030230238 -0.037744856 23 -0.0076656309 1.396550e-05 -4.020753e-02 -0.044659212 -0.050554976 24 -1.5070278126 3.723597e-04 1.647077e-02 -0.161486560 -0.278755415 25 -0.0239986724 1.966635e-05 -2.200355e-02 -0.039815491 -0.051838322 26 -0.2726502980 7.668984e-05 -7.104259e-02 -0.070135093 -0.138776999 27 -0.0237099021 -1.906594e-05 -1.449196e-02 -0.165127041 -0.182407191 28 0.5989984194 -3.350192e-04 8.982947e-02 0.072939768 0.051948750 29 0.0049978357 1.024575e-05 -4.596944e-02 -0.048846124 -0.057195412 30 -0.0420784682 4.604021e-06 -9.761996e-03 -0.018154729 -0.051613812 31 -0.1226019720 5.936642e-05 -4.859332e-02 -0.071029678 -0.070396498 32 -1.2891791826 3.470986e-04 1.870320e-01 0.029725520 0.047497829 33 0.5677503929 -2.038892e-04 6.741942e-02 0.117380014 0.074644216 34 -0.0732129453 3.754795e-05 -1.228743e-02 -0.110181891 -0.113812479 35 0.0194920033 -7.575835e-06 5.134183e-03 0.017360915 0.015396275 36 1.6888356455 -4.377455e-04 4.524306e-01 0.411034679 0.902823919 37 -0.4890085420 1.725038e-04 -1.049924e-01 -0.186804182 -0.420107392 38 -0.0082739419 -1.137356e-04 -2.907676e-02 0.013409601 -0.082572165 39 -1.0909018362 1.064695e-04 8.658188e-01 0.866130219 0.806474055 40 -0.6733060595 1.783564e-04 -1.305062e-01 0.065871030 -0.125533828 41 0.3690425668 -1.245558e-04 9.024714e-02 0.216243273 0.228933588 42 0.6432124241 -7.951017e-05 -7.008503e-01 -0.653531527 -0.847103140 43 0.2616446485 -1.975002e-04 9.041771e-02 0.187584888 0.139640344 44 0.0454749520 -4.284837e-06 -5.453546e-02 -0.051589176 -0.066116786 45 -2.2631327197 7.379870e-04 1.070445e-01 -0.204329361 -0.128262892 46 -0.0612084384 2.238252e-05 -1.234131e-02 -0.011911444 -0.017360476 47 0.8600843682 -2.923003e-04 1.777695e-01 -0.255446144 -0.114886957 48 0.1775813222 -1.196361e-04 2.413830e-02 0.077055159 -0.014203507 49 -0.1424954874 9.842541e-05 -2.377345e-02 -0.051500781 0.113004619 50 0.2613474511 -1.665525e-05 8.367041e-02 0.117064766 0.300913215 51 -0.5457545031 1.270106e-04 -1.351808e-01 -0.192894338 -0.176826828 52 0.3111798506 -2.896481e-04 2.816237e-02 0.136852358 -0.007250608 53 0.0297317368 1.296449e-05 -6.708602e-02 -0.069529496 -0.075630367 54 0.0989545407 -1.357243e-05 -3.683573e-02 -0.028339562 -0.025145841 55 0.1644148644 -1.347342e-04 1.507463e-01 0.272775865 0.355144259 56 -1.0973102505 2.844224e-04 -2.939639e-01 -0.267067176 -0.586604116 57 0.0000000000 0.000000e+00 0.000000e+00 0.000000000 0.000000000 58 1.1181936467 -1.814925e-04 1.820092e-01 0.230407448 0.281788680 59 -0.1289781075 2.595372e-05 -3.776833e-02 -0.058580136 -0.126069473 60 0.4827651281 -1.458463e-04 9.396412e-02 -0.005593267 0.099263965 61 -0.1929691299 1.326052e-04 -4.434766e-02 -0.106219857 -0.124334762 62 0.0049978357 1.024575e-05 -4.596944e-02 -0.048846124 -0.057195412 63 -0.3935296223 2.040809e-04 -7.524962e-02 -0.146355742 -0.019064641 64 0.4603333737 -1.617410e-04 -5.546499e-02 0.010390154 -0.035282319 65 0.3126987326 -1.960180e-04 1.168042e-01 0.223520593 0.218762880 66 -0.1920212451 8.908026e-05 -4.283525e-02 -0.117606580 -0.033622259 67 -0.8795466532 3.620658e-04 -1.815067e-01 -0.332837224 -0.502419092 68 -0.0331296115 -3.321728e-05 2.875172e-02 0.062289524 0.061442068 69 -0.1135318718 5.034205e-05 -2.126782e-02 0.029790905 0.026695041 70 -0.0195241852 2.061693e-04 6.572061e-02 0.294616782 0.074266087 71 0.0288527501 -1.891425e-05 4.221544e-03 0.012091377 0.008077810 72 -0.2291016407 5.487125e-05 -6.613686e-02 -0.098852165 -0.051549477 73 0.1700259290 7.628143e-06 -2.032259e-01 -0.198173180 -0.224109893 74 0.5968477257 -1.921799e-04 9.263890e-02 0.150229991 0.156628646 75 -0.0077820700 -4.699458e-06 -1.266873e-03 0.041173344 0.053631137 76 -0.0194397858 2.531489e-05 -1.458165e-07 -0.009800589 -0.035894083 77 0.0134907894 -1.033768e-05 1.558189e-03 0.006006815 0.003684406 78 0.9077181399 -1.582828e-04 7.745093e-02 0.077205972 0.141055974 79 0.2164417917 -3.971900e-05 -4.607492e-02 -0.024531503 -0.012649902 80 0.9960541035 4.247826e-06 -7.839184e-01 -0.702085425 -0.798219133 81 0.0007910652 -3.072859e-07 8.023023e-04 0.001256898 0.000758261 82 -0.6435072296 -7.492359e-05 -1.735778e-01 -0.355994454 -0.119101997 83 0.0611662403 1.159480e-05 -1.119647e-01 -0.121657673 -0.117008905 84 -0.5769304812 3.253972e-04 -3.191547e-01 -0.437477397 -0.423951235 85 1.0837148496 -4.307667e-04 2.461529e-01 0.572974426 0.542167217 86 0.0083937926 -1.990781e-06 8.287336e-04 -0.045561514 -0.037803655 87 -0.1545228365 9.611522e-05 -2.127841e-02 -0.171230178 -0.137086764 88 0.2463906019 -2.892912e-04 3.477162e-01 0.438821017 0.357674795 89 -0.6025253492 2.525728e-04 -1.370524e-01 1.172830299 -0.211660377 90 -0.2820706112 3.173532e-04 -1.101740e-01 -0.261059565 -0.118916876 91 1.4258537942 -6.533290e-04 2.630332e-01 0.890368685 1.145291551 92 0.4060610493 -2.135821e-06 5.871214e-02 0.048538680 0.094105407 93 -0.6025253492 2.525728e-04 -1.370524e-01 -1.878927238 -0.211660377 Cylinders8 Cylindersrotary TypeLarge TypeMidsize TypeSmall 1 -0.1124657876 -0.0651605878 -5.802887e-02 -0.0555471473 0.2528314269 2 0.0053388461 0.0047782307 -6.569650e-02 0.0350485943 0.0252041164 3 -0.1679122402 0.0274285066 2.008834e-01 0.1844628894 0.0674315814 4 0.0638568606 -0.0003503783 -9.564934e-03 0.0149006180 -0.0087430921 5 2.5938169745 0.8582948229 -2.399208e-01 -0.5792472372 -0.5285037464 6 -0.0288706903 0.0299679804 1.045061e-01 0.1382939842 -0.0401298599 7 -0.0312731330 0.0246836012 5.564636e-02 0.0035711688 -0.0041697238 8 -1.8340782811 0.0716558396 2.304687e-01 0.0032843291 0.3376172236 9 0.1847255512 -0.2306585282 1.114501e-01 -0.0803119855 -0.0298407737 10 1.1851421958 0.8654297998 4.409688e-01 0.0708134508 -0.2042104727 11 0.3843948456 0.1406061718 -3.010002e-01 0.0273414412 0.0837774246 12 -0.1597129689 -0.1864801897 6.450603e-02 0.0597885728 0.2076322416 13 -0.0586771076 -0.0646598581 1.706543e-01 0.1735883622 0.2361560351 14 -0.0028726461 -0.0993484475 -4.198827e-02 -0.0328695117 0.0082498333 15 -0.2068476225 -0.1445082313 1.225231e-01 0.1673204751 0.0312950406 16 0.2059222894 -0.1200505921 8.218720e-02 0.0002209106 0.0173235673 17 -0.3504899068 0.3446336843 -9.851809e-02 0.0158568288 0.0633581211 18 0.0120965218 -0.0020492335 6.525536e-03 0.0002012250 -0.0008929206 19 -0.0539420147 -0.1374351833 1.576257e-01 0.0201581755 -0.0041475049 20 -0.0070837751 0.0317471863 -1.531881e-01 0.0051020166 0.0109305108 21 0.5602808822 -0.0939068584 2.916889e-01 0.2079842274 0.0719036134 22 0.0126364571 0.0642138666 -1.824736e-01 0.0127807493 0.0009786882 23 -0.0590906405 -0.0349751702 -5.567345e-03 -0.0025732617 -0.0225313251 24 -0.5271125509 0.1602771709 -1.660813e-01 -0.0765130701 0.5564898293 25 -0.0681411476 0.0031024272 -6.907299e-02 -0.0610995775 -0.0429840790 26 -0.1735454433 -0.0706705707 -1.739837e-02 -0.0112946369 0.0452224232 27 -0.2193360665 0.0008241219 1.092126e-01 0.1738553921 0.0047428510 28 0.0830814596 0.1950801461 1.354514e-01 0.1170474131 -0.1299135184 29 -0.0675817916 -0.0375435877 -5.699613e-03 -0.0018561352 -0.0297646003 30 0.0331484828 -0.0113220048 -1.952427e-01 -0.0016275866 0.0158334658 31 -0.0814880252 -0.0547203065 -1.397635e-02 -0.0112820160 0.0077466973 32 -0.0305111798 0.1574388970 -9.111875e-02 -0.0694657561 0.5501978390 33 0.0753789673 0.1710615320 -1.462954e-01 -0.1345579924 -0.2507910840 34 -0.1921551895 -0.4405196059 1.130618e-01 0.0550822506 0.0142852838 35 0.0139101694 0.0258169696 -7.341174e-03 -0.0040191802 -0.0014323289 36 1.1438837591 0.4210260247 1.057460e-01 0.0605827133 -0.2795146003 37 -0.4363174667 -0.2224017015 7.276605e-02 -0.1577658535 0.1089681503 38 -0.5706613637 0.2470506317 -2.448941e-01 0.0200009992 0.0295593111 39 0.7628832511 0.8929585543 -2.839854e-02 -0.0150058474 0.0623044167 40 -0.4269483338 0.6476956209 -3.978519e-01 -0.2049708931 0.2326834589 41 0.2669874618 0.2216701222 -2.713083e-02 -0.0189484276 -0.0596156237 42 -1.0313086539 -0.4717065449 -5.947438e-02 0.0164415576 -0.6187804909 43 0.1137733941 0.1389371633 1.866498e-01 0.1973976445 0.1051395744 44 -0.0802417862 -0.0375174905 -4.849177e-03 0.0009183418 -0.0468179606 45 -0.2250554681 -0.0236009451 -1.620885e-01 -0.1443281442 0.7996413905 46 -0.0298791385 0.0117333041 -1.717830e-02 -0.0101575259 0.0149621883 47 0.0567064443 -0.0207407914 5.592524e-01 0.6766291378 -0.2163209845 48 -0.4128397633 0.1262494802 1.555317e-01 -0.0336491273 -0.0274472024 49 0.1227716704 -0.0185633712 -7.120767e-02 0.0510945769 0.0093727142 50 0.2753274562 -0.2227910135 1.638844e-02 0.0838038858 -0.0528014684 51 -0.3972662514 0.1137542901 -1.850157e-01 0.0563752358 0.1303601054 52 -0.6043582748 0.4122452714 -2.755341e-01 0.0529148176 -0.0181328373 53 -0.0823840936 -0.0629773704 -4.430653e-03 -0.0021608372 -0.0531359038 54 -0.0150792891 -0.0425585103 6.777594e-03 0.0030583353 -0.0591176911 55 0.4668348880 -0.0212547234 4.732189e-01 0.4185931034 0.2944838529 56 -0.7432312183 -0.2735589895 -6.870778e-02 -0.0393632338 0.1816128390 57 0.0000000000 0.0000000000 0.000000e+00 0.0000000000 0.0000000000 58 0.1945880055 -0.5587521455 -2.266734e-01 -0.3613221042 -0.5509923750 59 -0.0900361434 0.0807855154 -8.877433e-04 -0.0437027380 0.0203231292 60 0.2757970992 -0.3494459094 2.397384e-01 0.1279587545 -0.1512732820 61 0.1520532649 0.0495057257 6.424741e-02 -0.1224729549 -0.0152320811 62 -0.0675817916 -0.0375435877 -5.699613e-03 -0.0018561352 -0.0297646003 63 -0.0124737319 -0.1163136988 -6.666660e-02 0.0045716898 0.0573650532 64 -0.0495762572 0.0108982197 2.072756e-02 0.0311491661 -0.1744779053 65 0.2450971786 0.1014330960 2.438442e-01 0.2322886433 0.1145616875 66 -0.0137450945 -0.0933626778 -1.455145e-02 -0.0219051447 0.0210761620 67 -0.5159902331 -0.3502832221 3.148977e-02 -0.1793660556 0.1719234355 68 0.0601331294 0.0072908696 1.448763e-01 0.1417048477 0.1267967674 69 0.0205395611 -0.0166707782 -6.624376e-02 -0.0877281099 0.0244232730 70 0.2059222894 -0.1200505921 8.218720e-02 0.0002209106 0.0173235673 71 -0.0312731330 0.0246836012 5.564636e-02 0.0035711688 -0.0041697238 72 -0.0698149636 -0.0077907772 -5.798951e-02 -0.0404309294 0.0291804508 73 -0.2461674520 -0.1792254003 -8.946335e-03 -0.0005023396 -0.1849210773 74 0.2142676665 0.1219475973 -7.874021e-02 -0.0918428593 -0.2301439149 75 -0.0028726461 -0.0993484475 -4.198827e-02 -0.0328695117 0.0082498333 76 0.0016544356 -0.0670470508 3.751826e-02 -0.0342084452 -0.0003680573 77 -0.0256147452 0.0156400843 4.086022e-02 0.0019511571 -0.0017546993 78 0.2825081053 0.0902228220 -3.983641e-01 -0.4346234712 -0.6043441371 79 0.0159835202 -0.0629476770 1.898330e-02 0.0085089202 -0.1077243741 80 -0.8150304378 -0.7413746212 5.446384e-03 0.0101047426 0.0136845038 81 0.0006315229 0.0011374665 5.007436e-05 0.0001020962 0.0003802979 82 -0.1389697069 -0.2829444232 2.798773e-01 0.2855962270 0.2832007760 83 -0.1199642681 -0.1139380335 -3.874836e-03 -0.0029066043 0.0054537971 84 -0.4681723050 -0.3692610821 -6.915058e-02 -0.0611471408 -0.0286774399 85 0.5868282269 0.6138842050 -4.618245e-02 -0.0093232438 -0.1687348360 86 -0.0335385306 -0.0121341311 3.955944e-02 0.0530269621 -0.0049516790 87 -0.1199323644 -0.0903358174 7.132870e-02 0.0441402079 0.0305846988 88 0.3030076280 0.4897405972 2.110757e-02 0.0520618321 0.1828859889 89 -0.1751107919 -0.2847075342 -1.578805e-02 -0.1009325245 0.0816716468 90 0.0055450581 -0.2720115784 -2.803760e-01 -0.3305994053 -0.2254900027 91 1.1629492149 0.1111057651 -3.399076e-01 -0.2295981894 -0.3032814817 92 0.0465882510 -0.3782722178 -1.398749e-01 -0.2168631833 -0.2674612094 93 -0.1751107919 -0.2847075342 -1.578805e-02 -0.1009325245 0.0816716468 TypeSporty TypeVan EngineSize DriveTrainFront DriveTrainRear 1 0.0588316568 -0.1244451013 -0.0384310410 0.0770280182 0.0308309135 2 -0.0008119071 -0.0929376586 -0.0169359479 0.0241959908 -0.0339336755 3 0.1122278579 0.2291762722 0.0640824206 -0.0374592418 -0.0063680596 4 -0.0076600464 -0.0180881612 -0.0224320460 0.0058289643 -0.0019669209 5 -0.3020816254 -0.2058571702 -0.3622619462 -0.0332177591 -0.4896133013 6 0.0174438088 0.1203009860 0.0149164277 -0.0095259785 -0.0123604155 7 0.0006330938 0.0018693765 0.0107797571 -0.0019362039 -0.0134263631 8 0.0888020681 -0.0981347691 0.5308561510 -0.0605205490 0.0622791836 9 0.0084422208 0.0641063586 -0.1438112041 0.0132369251 0.1231952988 10 -0.0453797315 0.1992829759 0.2094701125 -0.0711059699 -0.5860656544 11 0.0248173290 -0.1726730349 0.0307556826 0.0513955297 -0.2418132557 12 0.1493980797 -0.0158201826 -0.0533221135 0.0282944654 0.0228550025 13 0.1994088698 0.1348657122 -0.0134379474 -0.0212986235 0.0103552709 14 0.0454481137 -0.0247086389 -0.0005370853 0.0136434594 0.0759855468 15 0.0737344548 0.0705529631 -0.0350342542 0.0366749177 0.0023334058 16 -0.0098606591 -0.6464182823 -0.1570311735 -0.3099924798 -0.2432841941 17 -0.0121432263 0.2179211370 0.2426878264 -0.2268810389 -0.3003526507 18 -0.0012645247 0.0023497958 -0.0011648194 -0.0007816983 0.0031588791 19 -0.0601680504 -0.0271883474 -0.1686877849 0.0224897952 0.0378443211 20 -0.0039938145 0.0181201352 0.0439331331 -0.0137111692 0.0000888560 21 0.1294650212 0.2558709492 -0.1869157355 -0.0403252374 0.1039524785 22 -0.0110221099 0.0377992374 0.0616023114 -0.0236300001 -0.0027554274 23 0.0036748958 -0.0109040520 0.0047056340 -0.0027760031 -0.0075815300 24 0.1217218160 -0.2001221968 0.1453646196 0.1092627610 -0.0419265979 25 -0.0473791084 -0.0661671214 0.0174623161 0.0138168014 -0.0113597498 26 0.0343625250 -0.1263789642 0.0185185704 0.0899765460 0.0628671160 27 0.0521314845 0.1121866729 0.0452354145 0.0036741989 -0.0328558430 28 -0.1357733641 0.3598998278 0.0635427842 0.1408150632 0.2289697825 29 0.0032709010 -0.0102098982 0.0072097840 -0.0046929662 -0.0097593036 30 -0.0031503060 0.0096427335 0.0191501496 -0.0072782279 0.0183269440 31 0.0124966732 -0.0309659093 -0.0029315971 0.0080704811 -0.0032291174 32 0.0842166724 -0.1426179532 -0.0047149618 0.1266243473 0.0488025203 33 -0.2007361705 -0.0700394295 0.0650345678 -0.0076553978 -0.0323613407 34 0.1985477388 0.1317049456 -0.0379303148 0.0476640032 0.2557928936 35 -0.0241684660 -0.0063797023 0.0015970165 -0.0082742198 -0.0012845847 36 -0.2213615898 0.8328871713 -0.1490208173 -0.6045260895 -0.4274997860 37 0.0832688361 0.0526955171 0.0412992657 0.0057199017 0.0750539814 38 0.0381452581 -0.0364723376 0.1718996509 -0.0083216767 -0.1711269654 39 0.0126715370 -0.1319040895 0.0157246728 -0.1238552960 -0.1433995801 40 -0.6152814178 -0.4391609078 0.1925710081 -0.1848270831 -0.1257923223 41 -0.2136693396 -0.0102756220 -0.0187378955 -0.0760535877 0.0079050473 42 0.0115250441 -0.0626784733 0.1853115582 -0.1341403576 -0.1937539975 43 0.1223234350 0.2339351557 0.0477222207 -0.0703208756 -0.0131810299 44 0.0012062101 -0.0056275300 0.0138113326 -0.0099328213 -0.0147138005 45 0.1593529911 -0.3154119193 -0.0734215883 0.2186169305 0.0863564493 46 -0.0178306744 -0.0229394143 0.0050172709 -0.0032569785 -0.0040140299 47 0.0870826598 0.5764940782 -0.0661850124 -0.0160346100 0.0058237374 48 0.0351028466 0.0519540796 0.0730561863 -0.0117874040 -0.0875600533 49 -0.0118615751 -0.1170935139 -0.0664392527 0.0351943834 -0.0256500862 50 -0.0881348868 0.0099122018 -0.1427997802 -0.0154102445 0.2834351261 51 0.0341259919 -0.1980471170 0.1301931475 0.0329557292 -0.1390726822 52 0.0198930304 0.0233944834 0.2437424291 -0.0398986993 -0.2216521963 53 0.0026357380 -0.0124859669 0.0032736381 -0.0076038099 -0.0111780184 54 -0.0052948316 0.0043390590 -0.0062558306 -0.0100922249 -0.0036764450 55 0.3245941919 0.4533108376 -0.1196342985 -0.0946588832 0.0778256270 56 0.1438282891 -0.5411631576 0.0968253310 0.3927869929 0.2777652749 57 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 58 -0.5770947483 -0.1184054962 -0.1740228604 -0.0285545091 0.7693037902 59 0.0412280879 -0.0075198458 0.0438882586 0.0121450418 -0.1252262379 60 0.3533541160 0.2760694598 -0.1036620689 0.1001975219 0.0703124944 61 0.0813382295 -0.0073739718 -0.0680618001 0.0531536577 -0.2332865147 62 0.0032709010 -0.0102098982 0.0072097840 -0.0046929662 -0.0097593036 63 0.0180571278 -0.1370722536 -0.0731027259 0.0500357603 -0.0039945662 64 -0.0280219408 0.0596353403 0.0485330769 -0.0523499513 -0.0380625252 65 0.1445564205 0.2773146947 -0.0044527086 -0.0739571632 0.0145722623 66 0.0147554787 0.0493296285 -0.0390174812 0.0705967740 0.0634638159 67 0.1109162662 -0.0476703926 -0.0101172134 0.0463473545 0.0838855959 68 0.1228600624 0.1417644316 -0.0078297996 -0.0320462976 0.0093214403 69 -0.0117468402 -0.0753433644 -0.0087753330 0.0054190284 0.0076171833 70 -0.0098606591 -0.6464182823 -0.1570311735 -0.3099924798 -0.2432841941 71 0.0006330938 0.0018693765 0.0107797571 -0.0019362039 -0.0134263631 72 -0.0675185509 0.0151499809 -0.0006299133 0.1444639061 0.1463776010 73 0.0024427576 -0.0249870886 0.0183259078 -0.0314868930 -0.0391504393 74 -0.1684498617 -0.0211344382 0.0051450670 -0.0108665177 -0.0006733384 75 0.0454481137 -0.0247086389 -0.0005370853 0.0136434594 0.0759855468 76 0.0087561990 0.0294347022 -0.0243866906 0.0001777584 0.0361467380 77 0.0011372964 -0.0003003688 0.0071919929 -0.0007018973 -0.0096901840 78 -0.4998716808 -0.3342094594 -0.0381922269 0.0632770184 0.0098092574 79 -0.0142230621 0.0179025413 -0.0175009156 -0.0191510694 -0.0015333501 80 -0.0247650968 -0.1469466395 0.0130804686 -0.2728976699 -0.2592164502 81 -0.0001483293 -0.0004719821 0.0001778419 -0.0011917350 -0.0011218042 82 0.3679140434 0.7422456267 0.0018768183 0.7508948030 0.7730015531 83 0.0043841507 0.0024787823 0.0002320259 0.0183666140 0.0145190633 84 0.0640691059 -0.1711824885 -0.0312673044 0.0349340607 -0.0192550330 85 -0.4756750417 0.0452676883 0.0298336291 -0.1959168864 -0.0136381614 86 0.0135669048 0.0363260497 -0.0012178976 0.0026468538 -0.0024799878 87 0.0376963721 0.1229412256 -0.0225447495 -0.0488081493 -0.0417831082 88 -0.0360445039 0.1399780291 0.1137882315 -0.0178410448 -0.0105132722 89 0.0609817970 0.1720567027 -0.0724262979 0.1875627215 0.1892070773 90 -0.2273870236 -0.3709143259 -0.1506696521 0.1197628934 0.0586023325 91 0.4164006880 -0.1004183249 0.0323442452 0.1231599812 -0.1040204060 92 -0.2996222296 -0.1090340253 -0.1173564279 0.0035664196 0.4305799574 93 0.0609817970 0.1720567027 -0.0724262979 0.1875627215 0.1892070773 $sigma 1 2 3 4 5 6 7 8 3.591432 3.594883 3.598562 3.600558 3.522694 3.598166 3.600799 3.582363 9 10 11 12 13 14 15 16 3.590729 3.528259 3.589350 3.596037 3.584177 3.600028 3.593696 3.580547 17 18 19 20 21 22 23 24 3.590040 3.601220 3.599441 3.598460 3.584656 3.597078 3.600671 3.553725 25 26 27 28 29 30 31 32 3.599688 3.599193 3.595214 3.598433 3.600406 3.596419 3.601044 3.518649 33 34 35 36 37 38 39 40 3.587115 3.592663 3.601139 3.501762 3.560763 3.588001 3.592963 3.514670 41 42 43 44 45 46 47 48 3.595497 3.334292 3.589110 3.599718 3.471882 3.601133 3.521852 3.594122 49 50 51 52 53 54 55 56 3.588734 3.589710 3.583459 3.581755 3.599157 3.599895 3.528075 3.559578 57 58 59 60 61 62 63 64 3.601231 3.523963 3.598459 3.571771 3.582319 3.600406 3.596626 3.592960 65 66 67 68 69 70 71 72 3.583325 3.600828 3.569987 3.592482 3.599979 3.580547 3.600799 3.599768 73 74 75 76 77 78 79 80 3.579302 3.593475 3.600028 3.598895 3.600991 3.495965 3.597794 3.594229 81 82 83 84 85 86 87 88 3.601231 3.563077 3.601124 3.585986 3.575773 3.600658 3.599786 3.563954 89 90 91 92 93 3.594056 3.566216 3.484273 3.578056 3.594056 $wt.res 1 2 3 4 5 2.218439708 1.807326787 -1.093991760 0.585986462 -5.684589270 6 7 8 9 10 1.233522386 0.457950438 2.515990067 -2.287803728 5.535960625 11 12 13 14 15 2.178905651 -1.596117514 -2.967297860 0.745175851 1.933882824 16 17 18 19 20 -3.035594591 2.195009903 0.072527577 -0.753360641 -1.155059621 21 22 23 24 25 -2.847828869 -1.410703414 -0.540252474 4.877197398 0.890715640 26 27 28 29 30 -0.968642103 1.731771561 -0.993218102 -0.656454198 -1.529950693 31 32 33 34 35 -0.298424469 6.510112647 2.683267748 1.992954455 -0.214079423 36 37 38 39 40 6.735053083 -4.545792145 -2.399183444 -1.714795692 -6.472930954 41 42 43 44 45 -1.671169308 -11.585332803 -2.485888781 -0.888857647 8.068071025 46 47 48 49 50 -0.216046323 6.246829383 -1.747619081 2.530823032 2.314106628 51 52 53 54 55 2.974532942 -2.887230686 -1.041442666 -0.835536301 -6.102291353 56 57 58 59 60 -4.376058028 0.000000000 5.966190371 -1.147443467 3.788198306 61 62 63 64 65 -3.015807719 -0.656454198 1.508247858 -2.064017840 -3.023462268 66 67 68 69 70 0.407243898 -3.964783523 -2.127186213 -0.789242889 -3.035594591 71 72 73 74 75 0.457950438 -0.797900840 -3.382338495 1.978150290 0.745175851 76 77 78 79 80 -1.096455031 0.341748714 7.324729228 -1.336726492 1.519313995 81 82 83 84 85 0.005901292 -4.095330927 0.195481697 -2.773676266 -3.487375439 86 87 88 89 90 0.536312040 0.775871729 4.379791779 1.302710701 4.213228761 91 92 93 7.334576566 3.283113507 -1.302710701 Potentially influential observations of lm(formula = 1000/MPG.city ~ Weight + Cylinders + Type + EngineSize + DriveTrain, data = Cars93) : dfb.1_ dfb.Wght dfb.Cyl4 dfb.Cyl5 dfb.Cyl6 dfb.Cyl8 dfb.Cyln dfb.TypL 8 -0.16 0.00 -0.10 -0.07 -0.24 -0.44 0.01 0.12 19 -0.03 0.09 -0.01 -0.03 0.00 -0.01 -0.03 0.08 28 0.11 -0.15 0.04 0.02 0.02 0.02 0.04 0.07 39 -0.19 0.05 0.34 0.21 0.25 0.18 0.18 -0.01 42 0.12 -0.04 -0.30 -0.17 -0.28 -0.26 -0.11 -0.03 57 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 66 -0.03 0.04 -0.02 -0.03 -0.01 0.00 -0.02 -0.01 80 0.18 0.00 -0.31 -0.17 -0.24 -0.19 -0.15 0.00 83 0.01 0.01 -0.04 -0.03 -0.04 -0.03 -0.02 0.00 87 -0.03 0.04 -0.01 -0.04 -0.04 -0.03 -0.02 0.04 89 -0.11 0.11 -0.05 0.28 -0.06 -0.04 -0.06 -0.01 93 -0.11 0.11 -0.05 -0.45 -0.06 -0.04 -0.06 -0.01 dfb.TypM dfb.TypSm dfb.TypSp dfb.TypV dfb.EngS dfb.DrTF dfb.DrTR dffit 8 0.00 0.21 0.06 -0.04 0.47 -0.04 0.03 0.73 19 0.01 0.00 -0.04 -0.01 -0.15 0.01 0.02 -0.24 28 0.08 -0.08 -0.09 0.16 0.06 0.09 0.12 -0.26 39 -0.01 0.04 0.01 -0.06 0.01 -0.08 -0.08 -0.44 42 0.01 -0.42 0.01 -0.03 0.18 -0.10 -0.11 -0.89 57 0.00 0.00 0.00 0.00 0.00 0.00 0.00 NaN 66 -0.02 0.01 0.01 0.02 -0.03 0.05 0.03 0.08 80 0.01 0.01 -0.02 -0.07 0.01 -0.18 -0.14 0.45 83 0.00 0.00 0.00 0.00 0.00 0.01 0.01 0.05 87 0.03 0.02 0.03 0.06 -0.02 -0.03 -0.02 0.14 89 -0.07 0.05 0.04 0.08 -0.06 0.12 0.10 0.64 93 -0.07 0.05 0.04 0.08 -0.06 0.12 0.10 -0.64 cov.r cook.d hat 8 1.71_* 0.04 0.39 19 2.09_* 0.00 0.43 28 1.86_* 0.00 0.36 39 1.76_* 0.01 0.36 42 0.13_* 0.05 0.06 57 NaN NaN 1.00_* 66 1.63_* 0.00 0.26 80 1.92_* 0.01 0.40 83 1.88_* 0.00 0.36 87 1.60_* 0.00 0.25 89 2.68_* 0.03 0.57_* 93 2.68_* 0.03 0.57_* > ## only last two cols in row 57 should be influential > > > ## PR#6640 Zero weights in plot.lm > if(require(MASS)) { + fm1 <- lm(time~dist, data=hills, weights=c(0,0,rep(1,33))) + plot(fm1) + } > ## gave warnings in 1.8.1 > > > ## PR#7829 model.tables & replications > if(require(MASS)) { + oats.aov <- aov(Y ~ B + V + N + V:N, data=oats[-1,]) + model.tables(oats.aov, "means", cterms=c("N", "V:N")) + } Tables of means Grand mean 103.8732 N 0.0cwt 0.2cwt 0.4cwt 0.6cwt 78.74 98.51 113.8 123 rep 17.00 18.00 18.0 18 V:N N V 0.0cwt 0.2cwt 0.4cwt 0.6cwt Golden.rain 79.53 98.03 114.20 124.37 rep 6.00 6.00 6.00 6.00 Marvellous 86.20 108.03 116.70 126.37 rep 6.00 6.00 6.00 6.00 Victory 69.77 89.20 110.37 118.03 rep 5.00 6.00 6.00 6.00 > ## wrong printed output in 2.1.0 > > > ## drop1 on weighted lm() fits > if(require(MASS)) { + hills.lm <- lm(time ~ 0 + dist + climb, data=hills, weights=1/dist^2) + print(drop1(hills.lm)) + print(stats:::drop1.default(hills.lm)) + hills.lm2 <- lm(time/dist ~ 1 + I(climb/dist), data=hills) + drop1(hills.lm2) + } Single term deletions Model: time ~ 0 + dist + climb Df Sum of Sq RSS AIC 442.22 92.776 dist 1 330.92 773.14 110.329 climb 1 9.73 451.95 91.538 Single term deletions Model: time ~ 0 + dist + climb Df AIC 92.776 dist 1 110.329 climb 1 91.538 Single term deletions Model: time/dist ~ 1 + I(climb/dist) Df Sum of Sq RSS AIC 442.22 92.776 I(climb/dist) 1 9.7331 451.95 91.538 > ## quoted unweighted RSS etc in 2.2.1 > > > ## tests of ISO C99 compliance (Windows fails without a workaround) > sprintf("%g", 123456789) [1] "1.23457e+08" > sprintf("%8g", 123456789) [1] "1.23457e+08" > sprintf("%9.7g", 123456789) [1] "1.234568e+08" > sprintf("%10.9g", 123456789) [1] " 123456789" > sprintf("%g", 12345.6789) [1] "12345.7" > sprintf("%10.9g", 12345.6789) [1] "12345.6789" > sprintf("%10.7g", 12345.6789) [1] " 12345.68" > sprintf("%.7g", 12345.6789) [1] "12345.68" > sprintf("%.5g", 12345.6789) [1] "12346" > sprintf("%.4g", 12345.6789) [1] "1.235e+04" > sprintf("%9.4g", 12345.6789) [1] "1.235e+04" > sprintf("%10.4g", 12345.6789) [1] " 1.235e+04" > ## Windows used e+008 etc prior to 2.3.0 > > > ## weighted glm() fits > if(require(MASS)) { + hills.glm <- glm(time ~ 0 + dist + climb, data=hills, weights=1/dist^2) + print(AIC(hills.glm)) + print(extractAIC(hills.glm)) + print(drop1(hills.glm)) + stats:::drop1.default(hills.glm) + } [1] 322.2318 [1] 2.0000 322.2318 Single term deletions Model: time ~ 0 + dist + climb Df Deviance AIC 442.22 322.23 dist 1 773.14 339.78 climb 1 451.95 320.99 Single term deletions Model: time ~ 0 + dist + climb Df AIC 322.23 dist 1 339.78 climb 1 320.99 > ## wrong AIC() and drop1 prior to 2.3.0. > > ## calculating no of signif digits > print(1.001, digits=16) [1] 1.001 > ## 2.4.1 gave 1.001000000000000 > ## 2.5.0 errs on the side of caution. > > > ## as.matrix.data.frame with coercion > if(require("survival")) { + soa <- Surv(1:5, c(0, 0, 1, 0, 1)) + df.soa <- data.frame(soa) + print(as.matrix(df.soa)) # numeric result + df.soac <- data.frame(soa, letters[1:5]) + print(as.matrix(df.soac)) # character result + detach("package:survival", unload = TRUE) + } Loading required package: survival soa.time soa.status [1,] 1 0 [2,] 2 0 [3,] 3 1 [4,] 4 0 [5,] 5 1 soa letters.1.5. [1,] "1+" "a" [2,] "2+" "b" [3,] "3 " "c" [4,] "4+" "d" [5,] "5 " "e" > ## failed in 2.8.1 > > ## wish of PR#13505 > npk.aov <- aov(yield ~ block + N * P + K, npk) > foo <- proj(npk.aov) > cbind(npk, foo) block N P K yield (Intercept) block N P K 1 1 0 1 1 49.5 54.875 -0.850 -2.808333 -0.5916667 -1.991667 2 1 1 1 0 62.8 54.875 -0.850 2.808333 -0.5916667 1.991667 3 1 0 0 0 46.8 54.875 -0.850 -2.808333 0.5916667 1.991667 4 1 1 0 1 57.0 54.875 -0.850 2.808333 0.5916667 -1.991667 5 2 1 0 0 59.8 54.875 2.575 2.808333 0.5916667 1.991667 6 2 1 1 1 58.5 54.875 2.575 2.808333 -0.5916667 -1.991667 7 2 0 0 1 55.5 54.875 2.575 -2.808333 0.5916667 -1.991667 8 2 0 1 0 56.0 54.875 2.575 -2.808333 -0.5916667 1.991667 9 3 0 1 0 62.8 54.875 5.900 -2.808333 -0.5916667 1.991667 10 3 1 1 1 55.8 54.875 5.900 2.808333 -0.5916667 -1.991667 11 3 1 0 0 69.5 54.875 5.900 2.808333 0.5916667 1.991667 12 3 0 0 1 55.0 54.875 5.900 -2.808333 0.5916667 -1.991667 13 4 1 0 0 62.0 54.875 -4.750 2.808333 0.5916667 1.991667 14 4 1 1 1 48.8 54.875 -4.750 2.808333 -0.5916667 -1.991667 15 4 0 0 1 45.5 54.875 -4.750 -2.808333 0.5916667 -1.991667 16 4 0 1 0 44.2 54.875 -4.750 -2.808333 -0.5916667 1.991667 17 5 1 1 0 52.0 54.875 -4.350 2.808333 -0.5916667 1.991667 18 5 0 0 0 51.5 54.875 -4.350 -2.808333 0.5916667 1.991667 19 5 1 0 1 49.8 54.875 -4.350 2.808333 0.5916667 -1.991667 20 5 0 1 1 48.8 54.875 -4.350 -2.808333 -0.5916667 -1.991667 21 6 1 0 1 57.2 54.875 1.475 2.808333 0.5916667 -1.991667 22 6 1 1 0 59.0 54.875 1.475 2.808333 -0.5916667 1.991667 23 6 0 1 1 53.2 54.875 1.475 -2.808333 -0.5916667 -1.991667 24 6 0 0 0 56.0 54.875 1.475 -2.808333 0.5916667 1.991667 N:P Residuals 1 0.9416667 -0.0750000 2 -0.9416667 5.5083333 3 -0.9416667 -6.0583333 4 0.9416667 0.6250000 5 0.9416667 -3.9833333 6 -0.9416667 1.7666667 7 -0.9416667 3.2000000 8 0.9416667 -0.9833333 9 0.9416667 2.4916667 10 -0.9416667 -4.2583333 11 0.9416667 2.3916667 12 -0.9416667 -0.6250000 13 0.9416667 5.5416667 14 -0.9416667 -0.6083333 15 -0.9416667 0.5250000 16 0.9416667 -5.4583333 17 -0.9416667 -1.7916667 18 -0.9416667 2.1416667 19 0.9416667 -3.0750000 20 0.9416667 2.7250000 21 0.9416667 -1.5000000 22 -0.9416667 -0.6166667 23 0.9416667 1.3000000 24 -0.9416667 0.8166667 > ## failed in R < 2.10.0 > > > if(suppressMessages(require("Matrix"))) { + print(cS. <- contr.SAS(5, sparse = TRUE)) + stopifnot(all(contr.SAS(5) == cS.), + all(contr.helmert(5, sparse = TRUE) == contr.helmert(5))) + + x1 <- x2 <- c('a','b','a','b','c') + x3 <- x2; x3[4:5] <- x2[5:4] + print(xtabs(~ x1 + x2, sparse= TRUE, exclude = 'c')) + print(xtabs(~ x1 + x3, sparse= TRUE, exclude = 'c')) + detach("package:Matrix") + ## failed in R <= 2.13.1 + } 5 x 4 sparse Matrix of class "dgCMatrix" 1 2 3 4 1 1 . . . 2 . 1 . . 3 . . 1 . 4 . . . 1 5 . . . . 2 x 2 sparse Matrix of class "dgCMatrix" x2 x1 a b a 2 . b . 2 2 x 2 sparse Matrix of class "dgCMatrix" x3 x1 a b a 2 . b . 1 > > ## regression tests for dimnames (broken on 2009-07-31) > contr.sum(4) [,1] [,2] [,3] 1 1 0 0 2 0 1 0 3 0 0 1 4 -1 -1 -1 > contr.helmert(4) [,1] [,2] [,3] 1 -1 -1 -1 2 1 -1 -1 3 0 2 -1 4 0 0 3 > contr.sum(2) # needed drop=FALSE at one point. [,1] 1 1 2 -1 > > ## xtabs did not exclude levels from factors > x1 <- c('a','b','a','b','c', NA) > x2 <- factor(x1, exclude=NULL) > print(xtabs(~ x1 + x2, na.action = na.pass)) x2 x1 a b c a 2 0 0 0 b 0 2 0 0 c 0 0 1 0 > print(xtabs(~ x1 + x2, exclude = 'c', na.action = na.pass)) x2 x1 a b a 2 0 0 b 0 2 0 0 0 1 > > > ## median should work by default for a suitable S4 class. > ## adapted from adaptsmoFMRI > if(suppressMessages(require("Matrix"))) { + x <- matrix(c(1,2,3,4)) + print(median(x)) + print(median(as(x, "dgeMatrix"))) + detach("package:Matrix") + } [1] 2.5 [1] 2.5 > > ## Various arguments were not duplicated: PR#15352 to 15354 > x <- 5 > y <- 2 > f <- function (y) x > numericDeriv(f(y),"y") [1] 5 attr(,"gradient") [,1] [1,] 0 > x [1] 5 > > a<-list(1,2) > b<-rep.int(a,c(2,2)) > b[[1]][1]<-9 > a[[1]] [1] 1 > > a <- numeric(1) > x <- mget("a",as.environment(1)) > x $a [1] 0 > a[1] <- 9 > x $a [1] 0 > > > ## needs MASS installed > ## PR#2586 labelling in alias() > if(require("MASS")) { + Y <- c(0,1,2) + X1 <- c(0,1,0) + X2 <- c(0,1,0) + X3 <- c(0,0,1) + print(res <- alias(lm(Y ~ X1 + X2 + X3))) + stopifnot(identical(rownames(res[[2]]), "X2")) + } Model : Y ~ X1 + X2 + X3 Complete : (Intercept) X1 X3 X2 0 1 0 > ## the error was in lm.(w)fit > > if(require("Matrix")) { + m1 <- m2 <- m <- matrix(1:12, 3,4) + dimnames(m2) <- list(LETTERS[1:3], + letters[1:4]) + dimnames(m1) <- list(NULL,letters[1:4]) + M <- Matrix(m) + M1 <- Matrix(m1) + M2 <- Matrix(m2) + ## Now, with a new ideal cbind(), rbind(): + print(cbind(M, M1)) + stopifnot(identical(cbind (M, M1), + cbind2(M, M1))) + rm(M,M1,M2) + detach("package:Matrix", unload=TRUE) + }##{Matrix} Loading required package: Matrix 3 x 8 Matrix of class "dgeMatrix" a b c d [1,] 1 4 7 10 1 4 7 10 [2,] 2 5 8 11 2 5 8 11 [3,] 3 6 9 12 3 6 9 12 > > > ## Invalid UTF-8 strings > x <- c("Jetz", "no", "chli", "z\xc3\xbcrit\xc3\xbc\xc3\xbctsch:", + "(noch", "ein", "bi\xc3\x9fchen", "Z\xc3\xbc", "deutsch)", + "\xfa\xb4\xbf\xbf\x9f") > lapply(x, utf8ToInt) [[1]] [1] 74 101 116 122 [[2]] [1] 110 111 [[3]] [1] 99 104 108 105 [[4]] [1] 122 252 114 105 116 252 252 116 115 99 104 58 [[5]] [1] 40 110 111 99 104 [[6]] [1] 101 105 110 [[7]] [1] 98 105 223 99 104 101 110 [[8]] [1] 90 252 [[9]] [1] 100 101 117 116 115 99 104 41 [[10]] [1] NA > Encoding(x) <- "UTF-8" > nchar(x, "b") [1] 4 2 4 15 5 3 8 3 8 5 > try(nchar(x, "c")) Error in nchar(x, "c") : invalid multibyte string, element 10 > try(nchar(x, "w")) Error in nchar(x, "w") : invalid multibyte string, element 10 > nchar(x, "c", allowNA = TRUE) [1] 4 2 4 12 5 3 7 2 8 NA > nchar(x, "w", allowNA = TRUE) [1] 4 2 4 12 5 3 7 2 8 NA > ## Results differed by platform, but some gave incorrect results on string 10. > > > ## str() on large strings (in multibyte locales; changing locale may not work everywhere > oloc <- Sys.getlocale("LC_CTYPE") > mbyte.lc <- { + if(.Platform$OS.type == "windows") + "English_United States.28605" + else if(grepl("[.]UTF-8$", oloc, ignore.case=TRUE)) # typically nowadays + oloc + else + "en_US.UTF-8" # or rather "C.UTF-8" or from system("locale -a | fgrep .utf8") + } > identical(Sys.setlocale("LC_CTYPE", mbyte.lc), mbyte.lc) # "ok" if not [1] TRUE > cc <- "J\xf6reskog" # valid in "latin-1"; invalid multibyte string in UTF-8 > .tmp <- capture.output( + str(cc) # failed in some R-devel versions + ) > stopifnot(grepl("chr \"J.*reskog\"", .tmp)) > nchar(L <- strrep(paste(LETTERS, collapse="."), 100000), type="b")# 5.1 M [1] 5100000 > stopifnot(system.time( str(L) )[[1L]] < 0.10) # Sparc Solaris needed 0.052 chr "A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.ZA.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.ZA.B.C.D.E"| __truncated__ > if(mbyte.lc != oloc) Sys.setlocale("LC_CTYPE", oloc) [1] "C" > ## needed 1.6 sec in (some) R <= 3.3.0 in a multibyte locale > > if(require("Matrix", .Library)) { + M <- Matrix(diag(1:10), sparse=TRUE) # a "dsCMatrix" + setClass("TestM", slots = c(M='numeric')) + setMethod("+", c("TestM","TestM"), function(e1,e2) { + e1@M + e2@M + }) + M+M # works the first time + M+M # was error "object '.Generic' not found" + ## + stopifnot( + identical(pmin(2,M), pmin(2, as.matrix(M))), + identical(as.matrix(pmax(M, 7)), pmax(as.matrix(M), 7)) + ) + rm(M) + detach("package:Matrix", unload=TRUE) + }##{Matrix} Loading required package: Matrix [ ] : .M.sub.i.logical() maybe inefficient >