Print a Node in a human-readable fashion.

# S3 method for class 'Node'
print(
  x,
  ...,
  pruneMethod = c("simple", "dist", NULL),
  limit = 100,
  pruneFun = NULL,
  row.names = T
)

Arguments

x

The Node

...

Node attributes to be printed. Can be either a character (i.e. the name of a Node field), a Node method, or a function taking a Node as a single argument. See Get for details on the meaning of attribute.

pruneMethod

The method can be used to prune for printing in a simple way. If NULL, the entire tree is displayed. If "simple", then only the first limit nodes are displayed. If "dist", then Nodes are removed everywhere in the tree, according to their level. If pruneFun is provided, then pruneMethod is ignored.

limit

The maximum number of nodes to print. Can be NULL if the entire tree should be printed.

pruneFun

allows providing a prune criteria, i.e. a function taking a Node as an input, and returning TRUE or FALSE. If the pruneFun returns FALSE for a Node, then the Node and its entire sub-tree will not be considered.

row.names

If TRUE (default), then the row names are printed out. Else, they are not.

Examples

data(acme)
print(acme, "cost", "p")
#>                           levelName    cost    p
#> 1  Acme Inc.                             NA   NA
#> 2   ¦--Accounting                        NA   NA
#> 3   ¦   ¦--New Software             1000000 0.50
#> 4   ¦   °--New Accounting Standards  500000 0.75
#> 5   ¦--Research                          NA   NA
#> 6   ¦   ¦--New Product Line         2000000 0.25
#> 7   ¦   °--New Labs                  750000 0.90
#> 8   °--IT                                NA   NA
#> 9       ¦--Outsource                 400000 0.20
#> 10      ¦--Go agile                  250000 0.05
#> 11      °--Switch to R                50000 1.00
print(acme, "cost", probability = "p")
#>                           levelName    cost probability
#> 1  Acme Inc.                             NA          NA
#> 2   ¦--Accounting                        NA          NA
#> 3   ¦   ¦--New Software             1000000        0.50
#> 4   ¦   °--New Accounting Standards  500000        0.75
#> 5   ¦--Research                          NA          NA
#> 6   ¦   ¦--New Product Line         2000000        0.25
#> 7   ¦   °--New Labs                  750000        0.90
#> 8   °--IT                                NA          NA
#> 9       ¦--Outsource                 400000        0.20
#> 10      ¦--Go agile                  250000        0.05
#> 11      °--Switch to R                50000        1.00
print(acme, expectedCost = function(x) x$cost * x$p)
#>                           levelName expectedCost
#> 1  Acme Inc.                                  NA
#> 2   ¦--Accounting                             NA
#> 3   ¦   ¦--New Software                   500000
#> 4   ¦   °--New Accounting Standards       375000
#> 5   ¦--Research                               NA
#> 6   ¦   ¦--New Product Line               500000
#> 7   ¦   °--New Labs                       675000
#> 8   °--IT                                     NA
#> 9       ¦--Outsource                       80000
#> 10      ¦--Go agile                        12500
#> 11      °--Switch to R                     50000
do.call(print, c(acme, acme$attributesAll))
#>                           levelName    cost    p
#> 1  Acme Inc.                             NA   NA
#> 2   ¦--Accounting                        NA   NA
#> 3   ¦   ¦--New Software             1000000 0.50
#> 4   ¦   °--New Accounting Standards  500000 0.75
#> 5   ¦--Research                          NA   NA
#> 6   ¦   ¦--New Product Line         2000000 0.25
#> 7   ¦   °--New Labs                  750000 0.90
#> 8   °--IT                                NA   NA
#> 9       ¦--Outsource                 400000 0.20
#> 10      ¦--Go agile                  250000 0.05
#> 11      °--Switch to R                50000 1.00

tree <- CreateRegularTree(4, 5)
# print entire tree:
print(tree, pruneMethod = NULL)
#>               levelName
#> 1   1                  
#> 2    ¦--1.1            
#> 3    ¦   ¦--1.1.1      
#> 4    ¦   ¦   ¦--1.1.1.1
#> 5    ¦   ¦   ¦--1.1.1.2
#> 6    ¦   ¦   ¦--1.1.1.3
#> 7    ¦   ¦   ¦--1.1.1.4
#> 8    ¦   ¦   °--1.1.1.5
#> 9    ¦   ¦--1.1.2      
#> 10   ¦   ¦   ¦--1.1.2.1
#> 11   ¦   ¦   ¦--1.1.2.2
#> 12   ¦   ¦   ¦--1.1.2.3
#> 13   ¦   ¦   ¦--1.1.2.4
#> 14   ¦   ¦   °--1.1.2.5
#> 15   ¦   ¦--1.1.3      
#> 16   ¦   ¦   ¦--1.1.3.1
#> 17   ¦   ¦   ¦--1.1.3.2
#> 18   ¦   ¦   ¦--1.1.3.3
#> 19   ¦   ¦   ¦--1.1.3.4
#> 20   ¦   ¦   °--1.1.3.5
#> 21   ¦   ¦--1.1.4      
#> 22   ¦   ¦   ¦--1.1.4.1
#> 23   ¦   ¦   ¦--1.1.4.2
#> 24   ¦   ¦   ¦--1.1.4.3
#> 25   ¦   ¦   ¦--1.1.4.4
#> 26   ¦   ¦   °--1.1.4.5
#> 27   ¦   °--1.1.5      
#> 28   ¦       ¦--1.1.5.1
#> 29   ¦       ¦--1.1.5.2
#> 30   ¦       ¦--1.1.5.3
#> 31   ¦       ¦--1.1.5.4
#> 32   ¦       °--1.1.5.5
#> 33   ¦--1.2            
#> 34   ¦   ¦--1.2.1      
#> 35   ¦   ¦   ¦--1.2.1.1
#> 36   ¦   ¦   ¦--1.2.1.2
#> 37   ¦   ¦   ¦--1.2.1.3
#> 38   ¦   ¦   ¦--1.2.1.4
#> 39   ¦   ¦   °--1.2.1.5
#> 40   ¦   ¦--1.2.2      
#> 41   ¦   ¦   ¦--1.2.2.1
#> 42   ¦   ¦   ¦--1.2.2.2
#> 43   ¦   ¦   ¦--1.2.2.3
#> 44   ¦   ¦   ¦--1.2.2.4
#> 45   ¦   ¦   °--1.2.2.5
#> 46   ¦   ¦--1.2.3      
#> 47   ¦   ¦   ¦--1.2.3.1
#> 48   ¦   ¦   ¦--1.2.3.2
#> 49   ¦   ¦   ¦--1.2.3.3
#> 50   ¦   ¦   ¦--1.2.3.4
#> 51   ¦   ¦   °--1.2.3.5
#> 52   ¦   ¦--1.2.4      
#> 53   ¦   ¦   ¦--1.2.4.1
#> 54   ¦   ¦   ¦--1.2.4.2
#> 55   ¦   ¦   ¦--1.2.4.3
#> 56   ¦   ¦   ¦--1.2.4.4
#> 57   ¦   ¦   °--1.2.4.5
#> 58   ¦   °--1.2.5      
#> 59   ¦       ¦--1.2.5.1
#> 60   ¦       ¦--1.2.5.2
#> 61   ¦       ¦--1.2.5.3
#> 62   ¦       ¦--1.2.5.4
#> 63   ¦       °--1.2.5.5
#> 64   ¦--1.3            
#> 65   ¦   ¦--1.3.1      
#> 66   ¦   ¦   ¦--1.3.1.1
#> 67   ¦   ¦   ¦--1.3.1.2
#> 68   ¦   ¦   ¦--1.3.1.3
#> 69   ¦   ¦   ¦--1.3.1.4
#> 70   ¦   ¦   °--1.3.1.5
#> 71   ¦   ¦--1.3.2      
#> 72   ¦   ¦   ¦--1.3.2.1
#> 73   ¦   ¦   ¦--1.3.2.2
#> 74   ¦   ¦   ¦--1.3.2.3
#> 75   ¦   ¦   ¦--1.3.2.4
#> 76   ¦   ¦   °--1.3.2.5
#> 77   ¦   ¦--1.3.3      
#> 78   ¦   ¦   ¦--1.3.3.1
#> 79   ¦   ¦   ¦--1.3.3.2
#> 80   ¦   ¦   ¦--1.3.3.3
#> 81   ¦   ¦   ¦--1.3.3.4
#> 82   ¦   ¦   °--1.3.3.5
#> 83   ¦   ¦--1.3.4      
#> 84   ¦   ¦   ¦--1.3.4.1
#> 85   ¦   ¦   ¦--1.3.4.2
#> 86   ¦   ¦   ¦--1.3.4.3
#> 87   ¦   ¦   ¦--1.3.4.4
#> 88   ¦   ¦   °--1.3.4.5
#> 89   ¦   °--1.3.5      
#> 90   ¦       ¦--1.3.5.1
#> 91   ¦       ¦--1.3.5.2
#> 92   ¦       ¦--1.3.5.3
#> 93   ¦       ¦--1.3.5.4
#> 94   ¦       °--1.3.5.5
#> 95   ¦--1.4            
#> 96   ¦   ¦--1.4.1      
#> 97   ¦   ¦   ¦--1.4.1.1
#> 98   ¦   ¦   ¦--1.4.1.2
#> 99   ¦   ¦   ¦--1.4.1.3
#> 100  ¦   ¦   ¦--1.4.1.4
#> 101  ¦   ¦   °--1.4.1.5
#> 102  ¦   ¦--1.4.2      
#> 103  ¦   ¦   ¦--1.4.2.1
#> 104  ¦   ¦   ¦--1.4.2.2
#> 105  ¦   ¦   ¦--1.4.2.3
#> 106  ¦   ¦   ¦--1.4.2.4
#> 107  ¦   ¦   °--1.4.2.5
#> 108  ¦   ¦--1.4.3      
#> 109  ¦   ¦   ¦--1.4.3.1
#> 110  ¦   ¦   ¦--1.4.3.2
#> 111  ¦   ¦   ¦--1.4.3.3
#> 112  ¦   ¦   ¦--1.4.3.4
#> 113  ¦   ¦   °--1.4.3.5
#> 114  ¦   ¦--1.4.4      
#> 115  ¦   ¦   ¦--1.4.4.1
#> 116  ¦   ¦   ¦--1.4.4.2
#> 117  ¦   ¦   ¦--1.4.4.3
#> 118  ¦   ¦   ¦--1.4.4.4
#> 119  ¦   ¦   °--1.4.4.5
#> 120  ¦   °--1.4.5      
#> 121  ¦       ¦--1.4.5.1
#> 122  ¦       ¦--1.4.5.2
#> 123  ¦       ¦--1.4.5.3
#> 124  ¦       ¦--1.4.5.4
#> 125  ¦       °--1.4.5.5
#> 126  °--1.5            
#> 127      ¦--1.5.1      
#> 128      ¦   ¦--1.5.1.1
#> 129      ¦   ¦--1.5.1.2
#> 130      ¦   ¦--1.5.1.3
#> 131      ¦   ¦--1.5.1.4
#> 132      ¦   °--1.5.1.5
#> 133      ¦--1.5.2      
#> 134      ¦   ¦--1.5.2.1
#> 135      ¦   ¦--1.5.2.2
#> 136      ¦   ¦--1.5.2.3
#> 137      ¦   ¦--1.5.2.4
#> 138      ¦   °--1.5.2.5
#> 139      ¦--1.5.3      
#> 140      ¦   ¦--1.5.3.1
#> 141      ¦   ¦--1.5.3.2
#> 142      ¦   ¦--1.5.3.3
#> 143      ¦   ¦--1.5.3.4
#> 144      ¦   °--1.5.3.5
#> 145      ¦--1.5.4      
#> 146      ¦   ¦--1.5.4.1
#> 147      ¦   ¦--1.5.4.2
#> 148      ¦   ¦--1.5.4.3
#> 149      ¦   ¦--1.5.4.4
#> 150      ¦   °--1.5.4.5
#> 151      °--1.5.5      
#> 152          ¦--1.5.5.1
#> 153          ¦--1.5.5.2
#> 154          ¦--1.5.5.3
#> 155          ¦--1.5.5.4
#> 156          °--1.5.5.5
# print first 20 nodes:
print(tree, pruneMethod = "simple", limit = 20)
#>                           levelName
#> 1  1                               
#> 2   ¦--1.1                         
#> 3   ¦   ¦--1.1.1                   
#> 4   ¦   ¦   ¦--1.1.1.1             
#> 5   ¦   ¦   ¦--1.1.1.2             
#> 6   ¦   ¦   ¦--1.1.1.3             
#> 7   ¦   ¦   ¦--1.1.1.4             
#> 8   ¦   ¦   °--1.1.1.5             
#> 9   ¦   ¦--1.1.2                   
#> 10  ¦   ¦   ¦--1.1.2.1             
#> 11  ¦   ¦   ¦--1.1.2.2             
#> 12  ¦   ¦   ¦--1.1.2.3             
#> 13  ¦   ¦   ¦--1.1.2.4             
#> 14  ¦   ¦   °--1.1.2.5             
#> 15  ¦   ¦--1.1.3                   
#> 16  ¦   ¦   ¦--1.1.3.1             
#> 17  ¦   ¦   ¦--1.1.3.2             
#> 18  ¦   ¦   ¦--1.1.3.3             
#> 19  ¦   ¦   ¦--1.1.3.4             
#> 20  ¦   ¦   °--... 1 nodes w/ 0 sub
#> 21  ¦   °--... 2 nodes w/ 11 sub   
#> 22  °--... 4 nodes w/ 133 sub      
# print 20 nodes, removing leafs first:
print(tree, pruneMethod = "dist", limit = 20)
#>                           levelName
#> 1  1                               
#> 2   ¦--1.1                         
#> 3   ¦   ¦--1.1.1                   
#> 4   ¦   ¦   °--... 5 nodes w/ 0 sub
#> 5   ¦   ¦--1.1.2                   
#> 6   ¦   ¦   °--... 5 nodes w/ 0 sub
#> 7   ¦   ¦--1.1.3                   
#> 8   ¦   ¦   °--... 5 nodes w/ 0 sub
#> 9   ¦   ¦--1.1.4                   
#> 10  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 11  ¦   °--1.1.5                   
#> 12  ¦       °--... 5 nodes w/ 0 sub
#> 13  ¦--1.2                         
#> 14  ¦   ¦--1.2.1                   
#> 15  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 16  ¦   ¦--1.2.2                   
#> 17  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 18  ¦   ¦--1.2.3                   
#> 19  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 20  ¦   °--... 2 nodes w/ 25 sub   
#> 21  ¦--1.3                         
#> 22  ¦   ¦--1.3.1                   
#> 23  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 24  ¦   ¦--1.3.2                   
#> 25  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 26  ¦   °--... 3 nodes w/ 25 sub   
#> 27  ¦--1.4                         
#> 28  ¦   ¦--1.4.1                   
#> 29  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 30  ¦   ¦--1.4.2                   
#> 31  ¦   ¦   °--... 5 nodes w/ 0 sub
#> 32  ¦   °--... 3 nodes w/ 25 sub   
#> 33  °--1.5                         
#> 34      ¦--1.5.1                   
#> 35      ¦   °--... 5 nodes w/ 0 sub
#> 36      ¦--1.5.2                   
#> 37      ¦   °--... 5 nodes w/ 0 sub
#> 38      °--... 3 nodes w/ 25 sub   
# provide your own pruning function:
print(tree, pruneFun = function(node) node$position != 2)
#>              levelName
#> 1  1                  
#> 2   ¦--1.1            
#> 3   ¦   ¦--1.1.1      
#> 4   ¦   ¦   ¦--1.1.1.1
#> 5   ¦   ¦   ¦--1.1.1.3
#> 6   ¦   ¦   ¦--1.1.1.4
#> 7   ¦   ¦   °--1.1.1.5
#> 8   ¦   ¦--1.1.3      
#> 9   ¦   ¦   ¦--1.1.3.1
#> 10  ¦   ¦   ¦--1.1.3.3
#> 11  ¦   ¦   ¦--1.1.3.4
#> 12  ¦   ¦   °--1.1.3.5
#> 13  ¦   ¦--1.1.4      
#> 14  ¦   ¦   ¦--1.1.4.1
#> 15  ¦   ¦   ¦--1.1.4.3
#> 16  ¦   ¦   ¦--1.1.4.4
#> 17  ¦   ¦   °--1.1.4.5
#> 18  ¦   °--1.1.5      
#> 19  ¦       ¦--1.1.5.1
#> 20  ¦       ¦--1.1.5.3
#> 21  ¦       ¦--1.1.5.4
#> 22  ¦       °--1.1.5.5
#> 23  ¦--1.3            
#> 24  ¦   ¦--1.3.1      
#> 25  ¦   ¦   ¦--1.3.1.1
#> 26  ¦   ¦   ¦--1.3.1.3
#> 27  ¦   ¦   ¦--1.3.1.4
#> 28  ¦   ¦   °--1.3.1.5
#> 29  ¦   ¦--1.3.3      
#> 30  ¦   ¦   ¦--1.3.3.1
#> 31  ¦   ¦   ¦--1.3.3.3
#> 32  ¦   ¦   ¦--1.3.3.4
#> 33  ¦   ¦   °--1.3.3.5
#> 34  ¦   ¦--1.3.4      
#> 35  ¦   ¦   ¦--1.3.4.1
#> 36  ¦   ¦   ¦--1.3.4.3
#> 37  ¦   ¦   ¦--1.3.4.4
#> 38  ¦   ¦   °--1.3.4.5
#> 39  ¦   °--1.3.5      
#> 40  ¦       ¦--1.3.5.1
#> 41  ¦       ¦--1.3.5.3
#> 42  ¦       ¦--1.3.5.4
#> 43  ¦       °--1.3.5.5
#> 44  ¦--1.4            
#> 45  ¦   ¦--1.4.1      
#> 46  ¦   ¦   ¦--1.4.1.1
#> 47  ¦   ¦   ¦--1.4.1.3
#> 48  ¦   ¦   ¦--1.4.1.4
#> 49  ¦   ¦   °--1.4.1.5
#> 50  ¦   ¦--1.4.3      
#> 51  ¦   ¦   ¦--1.4.3.1
#> 52  ¦   ¦   ¦--1.4.3.3
#> 53  ¦   ¦   ¦--1.4.3.4
#> 54  ¦   ¦   °--1.4.3.5
#> 55  ¦   ¦--1.4.4      
#> 56  ¦   ¦   ¦--1.4.4.1
#> 57  ¦   ¦   ¦--1.4.4.3
#> 58  ¦   ¦   ¦--1.4.4.4
#> 59  ¦   ¦   °--1.4.4.5
#> 60  ¦   °--1.4.5      
#> 61  ¦       ¦--1.4.5.1
#> 62  ¦       ¦--1.4.5.3
#> 63  ¦       ¦--1.4.5.4
#> 64  ¦       °--1.4.5.5
#> 65  °--1.5            
#> 66      ¦--1.5.1      
#> 67      ¦   ¦--1.5.1.1
#> 68      ¦   ¦--1.5.1.3
#> 69      ¦   ¦--1.5.1.4
#> 70      ¦   °--1.5.1.5
#> 71      ¦--1.5.3      
#> 72      ¦   ¦--1.5.3.1
#> 73      ¦   ¦--1.5.3.3
#> 74      ¦   ¦--1.5.3.4
#> 75      ¦   °--1.5.3.5
#> 76      ¦--1.5.4      
#> 77      ¦   ¦--1.5.4.1
#> 78      ¦   ¦--1.5.4.3
#> 79      ¦   ¦--1.5.4.4
#> 80      ¦   °--1.5.4.5
#> 81      °--1.5.5      
#> 82          ¦--1.5.5.1
#> 83          ¦--1.5.5.3
#> 84          ¦--1.5.5.4
#> 85          °--1.5.5.5