R version 4.0.3 Patched (2021-01-18 r79850) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2021 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.

> library(cluster)
> options(digits = 6)
> data(votes.repub)
> 
> ## IGNORE_RDIFF_BEGIN
> source(system.file("test-tools.R", package = "cluster"), keep.source = FALSE)
Loading required package: tools
doExtras <- cluster:::doExtras() :  TRUE
> ## IGNORE_RDIFF_END
> ## -> showProc.time() ...  & doExtras
> 
> agn1 <- agnes(votes.repub, metric = "manhattan", stand = TRUE)
> summary(agn1)
Object of class 'agnes' from call:
 agnes(x = votes.repub, metric = "manhattan", stand = TRUE) 
Agglomerative coefficient:  0.797756 
Order of objects:
 [1] Alabama        Georgia        Arkansas       Louisiana      Mississippi   
 [6] South Carolina Alaska         Vermont        Arizona        Montana       
[11] Nevada         Colorado       Idaho          Wyoming        Utah          
[16] California     Oregon         Washington     Minnesota      Connecticut   
[21] New York       New Jersey     Illinois       Ohio           Indiana       
[26] Michigan       Pennsylvania   New Hampshire  Wisconsin      Delaware      
[31] Kentucky       Maryland       Missouri       New Mexico     West Virginia 
[36] Iowa           South Dakota   North Dakota   Kansas         Nebraska      
[41] Maine          Massachusetts  Rhode Island   Florida        North Carolina
[46] Tennessee      Virginia       Oklahoma       Hawaii         Texas         
Merge:
      [,1] [,2]
 [1,]   -7  -32
 [2,]  -13  -35
 [3,]  -12  -50
 [4,]    1  -30
 [5,]    2  -14
 [6,]  -26  -28
 [7,]   -5  -37
 [8,]  -15  -41
 [9,]  -22  -38
[10,]  -25  -31
[11,]    7  -47
[12,]  -21  -39
[13,]  -16  -27
[14,]    4    5
[15,]  -42  -46
[16,]  -20   10
[17,]   14    9
[18,]   -3    6
[19,]   -6    3
[20,]  -33   15
[21,]   17  -29
[22,]  -17   16
[23,]    8  -34
[24,]   21  -49
[25,]   22  -48
[26,]   -8   25
[27,]   19  -44
[28,]   11  -23
[29,]   28   24
[30,]  -11  -43
[31,]   18   27
[32,]   23   13
[33,]   29   26
[34,]   20  -36
[35,]   -1  -10
[36,]   32  -19
[37,]   31   33
[38,]   -9   34
[39,]   37   36
[40,]   35   -4
[41,]   -2  -45
[42,]   40  -18
[43,]  -24  -40
[44,]   39   12
[45,]   44   38
[46,]   41   45
[47,]   42   43
[48,]   46   30
[49,]   47   48
Height:
 [1] 27.36345 31.15453 35.61832 51.44421 35.69152 87.45523 31.58222 47.53682
 [9] 16.34184 11.49397 22.11426 16.35662 10.46294 19.03961 28.41137 11.70132
[17] 12.72838 19.07671 20.90246  8.38200 11.10094 12.92659  9.23004 11.37867
[25] 15.97442 12.70819 16.91515 17.74499 24.83533 18.78225 17.03525 15.77893
[33] 12.71848 18.52818 30.74557 12.55524 17.14634 22.33846 12.80419 27.38835
[41] 37.23685 12.79160 38.76377 29.38432 16.63215 14.75762 25.59605 53.03627
[49] 21.07684

1225 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   8.38   25.54   34.51   45.06   56.02  167.60 
Metric :  manhattan 
Number of objects : 50

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab" "data"     
> Dvr <- daisy(votes.repub)
> agn2 <- agnes(Dvr, method = "complete")
> summary(agn2)
Object of class 'agnes' from call:
 agnes(x = Dvr, method = "complete") 
Agglomerative coefficient:  0.88084 
Order of objects:
 [1] Alabama        Georgia        Louisiana      Arkansas       Florida       
 [6] Texas          Mississippi    South Carolina Alaska         Michigan      
[11] Connecticut    New York       New Hampshire  Indiana        Ohio          
[16] Illinois       New Jersey     Pennsylvania   Minnesota      North Dakota  
[21] Wisconsin      Iowa           South Dakota   Kansas         Nebraska      
[26] Arizona        Nevada         Montana        Oklahoma       Colorado      
[31] Idaho          Wyoming        Utah           California     Oregon        
[36] Washington     Missouri       New Mexico     West Virginia  Delaware      
[41] Kentucky       Maryland       North Carolina Tennessee      Virginia      
[46] Hawaii         Maine          Massachusetts  Rhode Island   Vermont       
Merge:
      [,1] [,2]
 [1,]  -12  -50
 [2,]   -7  -32
 [3,]  -14  -35
 [4,]  -13  -30
 [5,]  -25  -31
 [6,]  -37  -47
 [7,]  -21  -39
 [8,]   -3  -28
 [9,]    4  -38
[10,]  -16  -27
[11,]  -15  -41
[12,]    8  -26
[13,]   -2  -22
[14,]  -33  -42
[15,]   14  -46
[16,]    1  -44
[17,]  -11  -19
[18,]    2  -29
[19,]   -5    6
[20,]  -17  -20
[21,]  -34  -49
[22,]    5  -48
[23,]   18    3
[24,]   11   10
[25,]   23    9
[26,]  -23   21
[27,]   -8   20
[28,]   12  -36
[29,]   -6   16
[30,]   13   25
[31,]   28   29
[32,]   -1  -10
[33,]   19   22
[34,]   17    7
[35,]   -4   -9
[36,]   30   26
[37,]   35  -43
[38,]   32  -18
[39,]  -24  -40
[40,]   36   24
[41,]   27   15
[42,]   31   33
[43,]   38   37
[44,]   40   42
[45,]   34  -45
[46,]   43   39
[47,]   44   41
[48,]   47   45
[49,]   46   48
Height:
 [1]  48.2397  60.8984  72.9221  56.1363  58.8227 116.7048  63.0951 281.9508
 [9]  28.1437  47.1690  19.4218  32.9438  36.7643  20.2258  39.1728  20.8792
[17]  25.3229  56.3813  42.2230  33.6978  64.5254  26.1547  37.4564  25.9221
[25]  80.4894  23.4206  27.8273  43.4492  48.0483  43.7055  17.1992  31.1988
[33]  70.4868  33.2328  22.1831  54.3057  21.1413  35.1129 121.4022  43.3829
[41]  33.4744  66.7591  29.5099  30.1541 178.4119  32.7611  55.3633  22.6334
[49]  83.1040

1225 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   17.2    48.3    64.7    82.2   105.5   282.0 
Metric :  euclidean 
Number of objects : 50

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab"
> ## almost same:
> (ag2. <- agnes(Dvr, method= "complete", keep.diss=FALSE))
Call:	 agnes(x = Dvr, method = "complete", keep.diss = FALSE) 
Agglomerative coefficient:  0.88084 
Order of objects:
 [1] Alabama        Georgia        Louisiana      Arkansas       Florida       
 [6] Texas          Mississippi    South Carolina Alaska         Michigan      
[11] Connecticut    New York       New Hampshire  Indiana        Ohio          
[16] Illinois       New Jersey     Pennsylvania   Minnesota      North Dakota  
[21] Wisconsin      Iowa           South Dakota   Kansas         Nebraska      
[26] Arizona        Nevada         Montana        Oklahoma       Colorado      
[31] Idaho          Wyoming        Utah           California     Oregon        
[36] Washington     Missouri       New Mexico     West Virginia  Delaware      
[41] Kentucky       Maryland       North Carolina Tennessee      Virginia      
[46] Hawaii         Maine          Massachusetts  Rhode Island   Vermont       
Height (summary):
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   17.2    28.1    39.2    52.3    58.8   282.0 

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab"
> ag22  <- agnes(votes.repub, method= "complete", keep.diss=FALSE,keep.data=FALSE)
> stopifnot(identical(agn2[-5:-6], ag2.[-5:-6]),
+           identical(Dvr, daisy(votes.repub)), # DUP=FALSE (!)
+           identical(ag2.[-6], ag22[-6])
+          )
> 
> data(agriculture)
> summary(agnes(agriculture))
Object of class 'agnes' from call:
 agnes(x = agriculture) 
Agglomerative coefficient:  0.781893 
Order of objects:
 [1] B   NL  D   F   UK  DK  L   I   GR  P   E   IRL
Merge:
      [,1] [,2]
 [1,]   -1  -10
 [2,]   -2   -9
 [3,]    1   -3
 [4,]    3   -6
 [5,]   -5   -7
 [6,]    4  -12
 [7,]    6    2
 [8,]   -4  -11
 [9,]    7   -8
[10,]    8    5
[11,]    9   10
Height:
 [1]  1.64924  2.24836  2.76918  4.02677  4.78835  2.22036  5.29409 14.77963
 [9]  5.16236  8.55075  3.14006

66 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   1.65    4.36    7.99    9.59   13.25   24.04 
Metric :  euclidean 
Number of objects : 12

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab" "data"     
> 
> data(ruspini)
> summary(ar0 <- agnes(ruspini, keep.diss=FALSE, keep.data=FALSE))
Object of class 'agnes' from call:
 agnes(x = ruspini, keep.diss = FALSE, keep.data = FALSE) 
Agglomerative coefficient:  0.947954 
Order of objects:
 [1] 1  2  3  5  4  6  8  7  9  10 14 15 17 16 18 19 11 12 13 20 61 62 66 63 64
[26] 68 65 67 69 70 71 72 75 73 74 21 22 23 24 27 28 29 30 25 26 32 35 31 36 39
[51] 40 33 34 37 38 41 42 43 44 45 49 51 53 50 54 52 55 56 57 59 60 58 46 47 48
Merge:
      [,1] [,2]
 [1,]  -18  -19
 [2,]  -55  -56
 [3,]  -27  -28
 [4,]  -49  -51
 [5,]  -33  -34
 [6,]  -23  -24
 [7,]  -67  -69
 [8,]  -59  -60
 [9,]  -29  -30
[10,]  -36  -39
[11,]  -32  -35
[12,]  -50  -54
[13,]  -25  -26
[14,]  -16    1
[15,]  -70  -71
[16,]  -64  -68
[17,]  -37  -38
[18,]   12  -52
[19,]  -62  -66
[20,]  -12  -13
[21,]   -9  -10
[22,]  -42  -43
[23,]  -15  -17
[24,]  -47  -48
[25,]  -21  -22
[26,]    7   15
[27,]    2  -57
[28,]    4  -53
[29,]   10  -40
[30,]    3    9
[31,]  -73  -74
[32,]  -72  -75
[33,]  -11   20
[34,]   13   11
[35,]   -6   -8
[36,]  -14   23
[37,]   -2   -3
[38,]  -65   26
[39,]    5   17
[40,]   25    6
[41,]   36   14
[42,]   34  -31
[43,]   -4   35
[44,]   28   18
[45,]   27    8
[46,]   19  -63
[47,]  -46   24
[48,]   -1   37
[49,]   16   38
[50,]   40   30
[51,]   42   29
[52,]   33  -20
[53,]   49   32
[54,]   51   39
[55,]   21   41
[56,]   48   -5
[57,]   45  -58
[58,]   53   31
[59,]   43   -7
[60,]   50   54
[61,]   44   57
[62,]  -41   22
[63,]  -61   46
[64,]   55   52
[65,]   63   58
[66,]  -44  -45
[67,]   59   64
[68,]   56   67
[69,]   66   61
[70,]   60   62
[71,]   69   47
[72,]   70   71
[73,]   68   65
[74,]   73   72
Height:
 [1]   9.26758   6.40312  12.13789  22.37868   7.63441   6.32456  14.58991
 [8]  21.63544   4.12311  12.07902   6.36396   4.24264   7.23741   3.56155
[15]   1.41421  16.38921   5.85486   4.12311  10.69547  67.75052  15.48443
[22]   4.12311   8.94386  17.00500   3.60555   9.53375   6.46443   2.82843
[29]   4.48680   3.60555  10.91541   5.83095  14.34411   5.65685 101.14200
[36]   4.47214   6.98022   2.23607   9.56136   2.00000   5.61339   2.82843
[43]  14.95692   3.16228   6.19728   3.00000   7.28356   9.97147   3.00000
[50]   5.47542  11.07404   2.23607   6.60456   3.60555  24.90532  15.45463
[57]   4.24264  64.42555  17.02939  22.56493   2.23607   5.22383   8.28122
[64]   3.16228   3.81721  15.20808   2.00000   5.19258   8.51123   2.82843
[71]  12.62990  34.72475   9.14005   4.47214

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab"
> summary(ar1 <- agnes(ruspini, metric = "manhattan"))
Object of class 'agnes' from call:
 agnes(x = ruspini, metric = "manhattan") 
Agglomerative coefficient:  0.946667 
Order of objects:
 [1] 1  2  3  5  4  6  8  7  9  10 14 16 18 19 15 17 11 12 13 20 61 62 66 63 73
[26] 74 64 68 65 67 69 70 71 72 75 21 22 23 24 27 28 29 30 25 26 32 35 31 36 39
[51] 40 33 34 37 38 41 42 43 44 45 49 51 53 50 54 52 55 56 57 59 60 58 46 47 48
Merge:
      [,1] [,2]
 [1,]  -55  -56
 [2,]  -27  -28
 [3,]  -18  -19
 [4,]  -49  -51
 [5,]  -36  -39
 [6,]  -33  -34
 [7,]  -32  -35
 [8,]  -23  -24
 [9,]  -67  -69
[10,]  -59  -60
[11,]  -50  -54
[12,]  -29  -30
[13,]  -25  -26
[14,]  -16    3
[15,]  -70  -71
[16,]  -64  -68
[17,]  -62  -66
[18,]   11  -52
[19,]  -37  -38
[20,]  -12  -13
[21,]   -9  -10
[22,]    9   15
[23,]    1  -57
[24,]  -47  -48
[25,]  -42  -43
[26,]  -21  -22
[27,]  -15  -17
[28,]    4  -53
[29,]    2   12
[30,]    5  -40
[31,]    6   19
[32,]   13    7
[33,]  -11   20
[34,]  -73  -74
[35,]  -72  -75
[36,]   -6   -8
[37,]  -65   22
[38,]  -14   14
[39,]   -2   -3
[40,]   32  -31
[41,]   38   27
[42,]   26    8
[43,]   28   18
[44,]  -46   24
[45,]   -4   36
[46,]   23   10
[47,]   -1   39
[48,]   42   29
[49,]   33  -20
[50,]   37   35
[51,]   40   30
[52,]   17  -63
[53,]   16   50
[54,]   51   31
[55,]   46  -58
[56,]   21   41
[57,]   47   -5
[58,]   45   -7
[59,]   52   34
[60,]  -44  -45
[61,]   48   54
[62,]   43   55
[63,]   59   53
[64,]   56   49
[65,]  -41   25
[66,]  -61   63
[67,]   57   58
[68,]   67   64
[69,]   60   62
[70,]   61   65
[71,]   69   44
[72,]   70   71
[73,]   68   66
[74,]   73   72
Height:
 [1]  11.50000   9.00000  16.00000  26.25000  10.00000   8.00000  16.66667
 [8]  28.70833   5.00000  15.50000   8.66667   4.00000   2.00000   9.25000
[15]   6.00000  20.50000   7.50000   5.00000  12.33333  94.33333  22.78571
[22]   5.00000  12.50000  18.00000   8.00000  20.20000   5.00000  13.78571
[29]   8.25000   4.00000   5.50000   5.00000  12.40000   8.00000 125.71357
[36]   6.00000   9.50000   3.00000  11.87500   2.00000   7.00000   4.00000
[43]  18.72917   4.00000   7.50000   3.00000   9.25000  12.40000   3.00000
[50]   7.50000  14.43750   3.00000   7.50000   5.00000  32.38333  21.00000
[57]   6.00000  85.49616  18.00000  28.75000   3.00000   6.50000   9.55556
[64]   4.00000   5.00000  19.61111   2.00000   6.00000  11.00000   4.00000
[71]  15.40000  47.02381  10.00000   6.00000

2775 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    2.0    52.5    97.0    91.0   128.0   187.0 
Metric :  manhattan 
Number of objects : 75

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab" "data"     
> str(ar1)
List of 9
 $ order    : int [1:75] 1 2 3 5 4 6 8 7 9 10 ...
 $ height   : num [1:74] 11.5 9 16 26.2 10 ...
 $ ac       : num 0.947
 $ merge    : int [1:74, 1:2] -55 -27 -18 -49 -36 -33 -32 -23 -67 -59 ...
 $ diss     : 'dissimilarity' num [1:2775] 11 12 29 13 25 43 33 22 27 39 ...
  ..- attr(*, "Size")= int 75
  ..- attr(*, "Metric")= chr "manhattan"
  ..- attr(*, "Labels")= chr [1:75] "1" "2" "3" "4" ...
 $ call     : language agnes(x = ruspini, metric = "manhattan")
 $ method   : chr "average"
 $ order.lab: chr [1:75] "1" "2" "3" "5" ...
 $ data     : num [1:75, 1:2] 4 5 10 9 13 13 12 15 18 19 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:75] "1" "2" "3" "4" ...
  .. ..$ : chr [1:2] "x" "y"
 - attr(*, "class")= chr [1:2] "agnes" "twins"
> 
> showProc.time()
Time (user system elapsed): 0.602 0.061 0.667 
> 
> summary(ar2 <- agnes(ruspini, metric="manhattan", method = "weighted"))
Object of class 'agnes' from call:
 agnes(x = ruspini, metric = "manhattan", method = "weighted") 
Agglomerative coefficient:  0.942387 
Order of objects:
 [1] 1  2  3  5  9  10 14 16 18 19 15 17 4  6  8  7  11 12 13 20 61 64 68 65 67
[26] 69 70 71 62 66 63 72 75 73 74 21 22 23 24 27 28 29 30 25 26 32 35 31 36 39
[51] 40 33 34 37 38 41 42 43 44 45 49 51 53 50 54 52 55 56 57 59 60 58 46 47 48
Merge:
      [,1] [,2]
 [1,]  -55  -56
 [2,]  -27  -28
 [3,]  -18  -19
 [4,]  -49  -51
 [5,]  -36  -39
 [6,]  -33  -34
 [7,]  -32  -35
 [8,]  -23  -24
 [9,]  -67  -69
[10,]  -59  -60
[11,]  -50  -54
[12,]  -29  -30
[13,]  -25  -26
[14,]  -16    3
[15,]  -70  -71
[16,]  -64  -68
[17,]  -62  -66
[18,]   11  -52
[19,]  -37  -38
[20,]  -12  -13
[21,]   -9  -10
[22,]    9   15
[23,]    1  -57
[24,]  -47  -48
[25,]  -42  -43
[26,]  -21  -22
[27,]  -15  -17
[28,]    4  -53
[29,]    2   12
[30,]    5  -40
[31,]    6   19
[32,]   13    7
[33,]  -11   20
[34,]  -73  -74
[35,]  -72  -75
[36,]  -14   14
[37,]   -6   -8
[38,]  -65   22
[39,]   36   27
[40,]   -2   -3
[41,]   32  -31
[42,]   28   18
[43,]   26    8
[44,]  -46   24
[45,]   -4   37
[46,]   23   10
[47,]   -1   40
[48,]   16   38
[49,]   43   29
[50,]   17  -63
[51,]   41   30
[52,]   33  -20
[53,]   35   34
[54,]   46  -58
[55,]   47   -5
[56,]   51   31
[57,]   21   39
[58,]   45   -7
[59,]  -44  -45
[60,]  -61   48
[61,]   42   54
[62,]   49   56
[63,]  -41   25
[64,]   55   57
[65,]   60   50
[66,]   65   53
[67,]   58   52
[68,]   59   61
[69,]   64   67
[70,]   62   63
[71,]   68   44
[72,]   70   71
[73,]   69   66
[74,]   73   72
Height:
 [1]  11.5000   9.0000  15.2500  21.7734   5.0000  15.8750   8.0000   4.0000
 [9]   2.0000   9.0000   6.0000  32.1172  10.0000   8.0000  16.0000  27.9062
[17]   7.5000   5.0000  13.2500  97.9766  18.3125   5.0000  11.8750   8.2500
[25]   4.0000   5.5000   5.0000  22.3438   5.0000  12.5000  23.7812   8.0000
[33]  14.5000   8.0000 114.9764   6.0000   9.5000   3.0000  11.8750   2.0000
[41]   7.0000   4.0000  20.2031   4.0000   7.5000   3.0000   9.2500  12.6250
[49]   3.0000   7.5000  15.6875   3.0000   7.5000   5.0000  33.5469  21.0000
[57]   6.0000  69.4453  18.0000  28.4375   3.0000   6.5000   9.5000   4.0000
[65]   5.0000  19.1250   2.0000   6.0000  10.5000   4.0000  15.0000  41.5312
[73]  10.0000   6.0000

2775 dissimilarities, summarized :
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    2.0    52.5    97.0    91.0   128.0   187.0 
Metric :  manhattan 
Number of objects : 75

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab" "data"     
> print  (ar3 <- agnes(ruspini, metric="manhattan", method = "flexible",
+                      par.meth = 0.5))
Call:	 agnes(x = ruspini, metric = "manhattan", method = "flexible",      par.method = 0.5) 
Agglomerative coefficient:  0.942387 
Order of objects:
 [1] 1  2  3  5  9  10 14 16 18 19 15 17 4  6  8  7  11 12 13 20 61 64 68 65 67
[26] 69 70 71 62 66 63 72 75 73 74 21 22 23 24 27 28 29 30 25 26 32 35 31 36 39
[51] 40 33 34 37 38 41 42 43 44 45 49 51 53 50 54 52 55 56 57 59 60 58 46 47 48
Height (summary):
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   2.00    5.00    8.12   14.22   15.58  114.98 

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab" "data"     
> stopifnot(all.equal(ar2[1:4], ar3[1:4], tol=1e-12))
> 
> showProc.time()
Time (user system elapsed): 0.003 0.001 0.004 
> 
> ## Small example, testing "flexible" vs "single"
> i8 <- -c(1:2, 9:10)
> dim(agr8 <- agriculture[i8, ])
[1] 8 2
> i5 <- -c(1:2, 8:12)
> dim(agr5 <- agriculture[i5, ])
[1] 5 2
> 
> ##' Check equivalence of method "flexible" (par=...)  with one
> ##' of ("single", "complete", "weighted")
> chk <- function(d, method=c("single", "complete", "weighted"),
+                 trace.lev = 1,
+                 iC = -(6:7), # <- not using 'call' and 'method' for comparisons
+                 doplot = FALSE, tol = 1e-12)
+ {
+     if(!inherits(d, "dist")) d <- daisy(d, "manhattan")
+     method <- match.arg(method)
+     par.meth <- list("single" =  c(.5, .5, 0, -.5),
+                      "complete"= c(.5, .5, 0, +.5),
+                      "weighted"= c(0.5))
+     a.s <- agnes(d, method=method, trace.lev=trace.lev)
+     ## From theory, this should give the same, but it does not --- why ???
+     a.f <- agnes(d, method="flex", par.method = par.meth[[method]], trace.lev=trace.lev)
+ 
+     if(doplot) {
+ 	op <- par(mfrow = c(2,2), mgp = c(1.6, 0.6, 0), mar = .1 + c(4,4,2,1))
+         on.exit(par(op))
+         plot(a.s)
+         plot(a.f)
+     }
+     structure(all.equal(a.s[iC], a.f[iC], tolerance = tol),
+               fits = list(s = a.s, f = a.f))
+ }
> 
> chk(agr5, trace = 3)
C agnes(n=5, method = 2, ..): 4 merging steps
 nmerge=0, j=2, d_min = D(1,4) = 3.40000;  -> (-1,-4); last=4; upd(n,b);
 old D(A, j), D(B, j), j=2  = (31.5,28.1);  new D(A', 2) = 28.1
 old D(A, j), D(B, j), j=3  = (14.7,11.3);  new D(A', 3) = 11.3
 old D(A, j), D(B, j), j=5  = (18.3,14.9);  new D(A', 5) = 14.9
 -->  size(A_new)= 2
 nmerge=1, j=2, d_min = D(3,5) = 3.60000;  -> (-3,-5); last=5;
 old D(A, j), D(B, j), j=1  = (11.3,14.9);  new D(A', 1) = 11.3
 old D(A, j), D(B, j), j=2  = (16.8,13.2);  new D(A', 2) = 13.2
 -->  size(A_new)= 2
 nmerge=2, j=2, d_min = D(1,3) = 11.3000;  -> (1,2); last=4; upd(n,b);
 old D(A, j), D(B, j), j=2  = (28.1,13.2);  new D(A', 2) = 13.2
 -->  size(A_new)= 4
 nmerge=3, j=2, d_min = D(1,2) = 13.2000;  -> (3,-2); last=5;
 -->  size(A_new)= 5
C agnes(n=5, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,-0.5); 4 merging steps
 nmerge=0, j=2, d_min = D(1,4) = 3.40000;  -> (-1,-4); last=4; upd(n,b);
 old D(A, j), D(B, j), j=2  = (31.5,28.1);  new D(A', 2) = 28.1
 old D(A, j), D(B, j), j=3  = (14.7,11.3);  new D(A', 3) = 11.3
 old D(A, j), D(B, j), j=5  = (18.3,14.9);  new D(A', 5) = 14.9
 -->  size(A_new)= 2
 nmerge=1, j=2, d_min = D(3,5) = 3.60000;  -> (-3,-5); last=5;
 old D(A, j), D(B, j), j=1  = (11.3,14.9);  new D(A', 1) = 11.3
 old D(A, j), D(B, j), j=2  = (16.8,13.2);  new D(A', 2) = 13.2
 -->  size(A_new)= 2
 nmerge=2, j=2, d_min = D(1,3) = 11.3000;  -> (1,2); last=4; upd(n,b);
 old D(A, j), D(B, j), j=2  = (28.1,13.2);  new D(A', 2) = 13.2
 -->  size(A_new)= 4
 nmerge=3, j=2, d_min = D(1,2) = 13.2000;  -> (3,-2); last=5;
 -->  size(A_new)= 5
[1] TRUE
attr(,"fits")
attr(,"fits")$s
Call:	 agnes(x = d, method = method, trace.lev = trace.lev) 
Agglomerative coefficient:  0.587879 
Order of objects:
[1] D   F   E   IRL GR 
Height (summary):
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   3.40    3.55    7.45    7.88   11.78   13.20 

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab"

attr(,"fits")$f
Call:	 agnes(x = d, method = "flex", par.method = par.meth[[method]],      trace.lev = trace.lev) 
Agglomerative coefficient:  0.587879 
Order of objects:
[1] D   F   E   IRL GR 
Height (summary):
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   3.40    3.55    7.45    7.88   11.78   13.20 

Available components:
[1] "order"     "height"    "ac"        "merge"     "diss"      "call"     
[7] "method"    "order.lab"

> 
> stopifnot(chk(agr5), chk(agr5, "complete", trace = 2), chk(agr5, "weighted"),
+           chk(agr8), chk(agr8, "complete"), chk(agr8, "weighted", trace.lev=2),
+           chk(agriculture), chk(agriculture, "complete"),
+           chk(ruspini), chk(ruspini, "complete"), chk(ruspini, "weighted"))
C agnes(n=5, method = 2, ..): 4 merging steps
C agnes(n=5, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,-0.5); 4 merging steps
C agnes(n=5, method = 3, ..): 4 merging steps
 nmerge=0, j=2, d_min = D(1,4) = 3.40000; last=4; upd(n,b); size(A_new)= 2
 nmerge=1, j=2, d_min = D(3,5) = 3.60000; last=5; size(A_new)= 2
 nmerge=2, j=2, d_min = D(2,3) = 16.8000; last=4; size(A_new)= 3
 nmerge=3, j=2, d_min = D(1,2) = 31.5000; last=3; size(A_new)= 5
C agnes(n=5, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,0.5); 4 merging steps
 nmerge=0, j=2, d_min = D(1,4) = 3.40000; last=4; upd(n,b); size(A_new)= 2
 nmerge=1, j=2, d_min = D(3,5) = 3.60000; last=5; size(A_new)= 2
 nmerge=2, j=2, d_min = D(2,3) = 16.8000; last=4; size(A_new)= 3
 nmerge=3, j=2, d_min = D(1,2) = 31.5000; last=3; size(A_new)= 5
C agnes(n=5, method = 5, ..): 4 merging steps
C agnes(n=5, method = 6, ..): 4 merging steps
C agnes(n=8, method = 2, ..): 7 merging steps
C agnes(n=8, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,-0.5); 7 merging steps
C agnes(n=8, method = 3, ..): 7 merging steps
C agnes(n=8, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,0.5); 7 merging steps
C agnes(n=8, method = 5, ..): 7 merging steps
 nmerge=0, j=2, d_min = D(1,4) = 3.40000; last=4; upd(n,b); size(A_new)= 2
 nmerge=1, j=2, d_min = D(3,5) = 3.60000; last=5; size(A_new)= 2
 nmerge=2, j=2, d_min = D(1,6) = 5.40000; last=6; upd(n,b); size(A_new)= 3
 nmerge=3, j=2, d_min = D(2,7) = 6.70000; last=7; upd(n,b); size(A_new)= 2
 nmerge=4, j=2, d_min = D(1,8) = 7.75000; last=8; upd(n,b); size(A_new)= 4
 nmerge=5, j=2, d_min = D(2,3) = 11.6500; last=7; size(A_new)= 4
 nmerge=6, j=2, d_min = D(1,2) = 18.3750; last=5; size(A_new)= 8
C agnes(n=8, method = 6, ..): 7 merging steps
 nmerge=0, j=2, d_min = D(1,4) = 3.40000; last=4; upd(n,b); size(A_new)= 2
 nmerge=1, j=2, d_min = D(3,5) = 3.60000; last=5; size(A_new)= 2
 nmerge=2, j=2, d_min = D(1,6) = 5.40000; last=6; upd(n,b); size(A_new)= 3
 nmerge=3, j=2, d_min = D(2,7) = 6.70000; last=7; upd(n,b); size(A_new)= 2
 nmerge=4, j=2, d_min = D(1,8) = 7.75000; last=8; upd(n,b); size(A_new)= 4
 nmerge=5, j=2, d_min = D(2,3) = 11.6500; last=7; size(A_new)= 4
 nmerge=6, j=2, d_min = D(1,2) = 18.3750; last=5; size(A_new)= 8
C agnes(n=12, method = 2, ..): 11 merging steps
C agnes(n=12, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,-0.5); 11 merging steps
C agnes(n=12, method = 3, ..): 11 merging steps
C agnes(n=12, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,0.5); 11 merging steps
C agnes(n=75, method = 2, ..): 74 merging steps
C agnes(n=75, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,-0.5); 74 merging steps
C agnes(n=75, method = 3, ..): 74 merging steps
C agnes(n=75, method = 6, ..): |par| = 4, alpha[1:4] = (0.5,0.5,0,0.5); 74 merging steps
C agnes(n=75, method = 5, ..): 74 merging steps
C agnes(n=75, method = 6, ..): 74 merging steps
> 
> showProc.time()
Time (user system elapsed): 0.04 0.001 0.041 
> 
> ## an invalid "flexible" case - now must give error early:
> x <- rbind(c( -6, -9), c(  0, 13),
+            c(-15,  6), c(-14,  0), c(12,-10))
> (dx <- daisy(x, "manhattan"))
Dissimilarities :
   1  2  3  4
2 28         
3 24 22      
4 17 27  7   
5 19 35 43 36

Metric :  manhattan 
Number of objects : 5
> a.x <- tryCatch(agnes(dx, method="flexible", par = -.2),
+                 error = function(e)e)
> ##  agnes(method=6, par.method=*) lead to invalid merge; step 4, D(.,.)=-26.1216
> if(!inherits(a.x, "error")) stop("invalid 'par' in \"flexible\" did not give error")
> if(!all(vapply(c("par[.]method", "merge"), grepl, NA, x=a.x$message)))
+    stop("error message did not contain expected words")
> 
> 
> proc.time()
   user  system elapsed 
  0.767   0.094   0.859