File: tree.Rd

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (271 lines) | stat: -rw-r--r-- 16,497 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tree.R
\name{tree}
\alias{tree}
\title{Draw a tree}
\usage{
tree(
  data,
  root = data[[1]][[1]],
  style = NULL,
  width = console_width(),
  trim = FALSE
)
}
\arguments{
\item{data}{Data frame that contains the tree structure.
The first column is an id, and the second column is a list column,
that contains the ids of the child nodes. The optional third column
may contain the text to print to annotate the node.}

\item{root}{The name of the root node.}

\item{style}{Optional box style list.}

\item{width}{Maximum width of the output. Defaults to the \code{width}
option, see \code{\link[base:options]{base::options()}}.}

\item{trim}{Whether to avoid traversing the same nodes multiple times.
If \code{TRUE} and \code{data} has a \code{trimmed} column, then that is used for
printing repeated nodes.}
}
\value{
Character vector, the lines of the tree drawing.
}
\description{
Draw a tree using box drawing characters. Unicode characters are
used if available. (Set the \code{cli.unicode} option if auto-detection
fails.)
}
\details{
A node might appear multiple times in the tree, or might not appear
at all.

\if{html}{\out{<div class="sourceCode r">}}\preformatted{data <- data.frame(
  stringsAsFactors = FALSE,
  package = c("processx", "backports", "assertthat", "Matrix",
    "magrittr", "rprojroot", "clisymbols", "prettyunits", "withr",
    "desc", "igraph", "R6", "crayon", "debugme", "digest", "irlba",
    "rcmdcheck", "callr", "pkgconfig", "lattice"),
  dependencies = I(list(
    c("assertthat", "crayon", "debugme", "R6"), character(0),
    character(0), "lattice", character(0), "backports", character(0),
    c("magrittr", "assertthat"), character(0),
    c("assertthat", "R6", "crayon", "rprojroot"),
    c("irlba", "magrittr", "Matrix", "pkgconfig"), character(0),
    character(0), "crayon", character(0), "Matrix",
    c("callr", "clisymbols", "crayon", "desc", "digest", "prettyunits",
      "R6", "rprojroot", "withr"),
    c("processx", "R6"), character(0), character(0)
  ))
)
tree(data)
}\if{html}{\out{</div>}}\if{html}{\out{
<div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre>
#> processx                                                                        
#> ├─assertthat                                                                    
#> ├─crayon                                                                        
#> ├─debugme                                                                       
#> │ └─crayon                                                                      
#> └─R6                                                                            
</pre></div>
}}


\if{html}{\out{<div class="sourceCode r">}}\preformatted{tree(data, root = "rcmdcheck")
}\if{html}{\out{</div>}}\if{html}{\out{
<div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre>
#> rcmdcheck                                                                       
#> ├─callr                                                                         
#> │ ├─processx                                                                    
#> │ │ ├─assertthat                                                                
#> │ │ ├─crayon                                                                    
#> │ │ ├─debugme                                                                   
#> │ │ │ └─crayon                                                                  
#> │ │ └─R6                                                                        
#> │ └─R6                                                                          
#> ├─clisymbols                                                                    
#> ├─crayon                                                                        
#> ├─desc                                                                          
#> │ ├─assertthat                                                                  
#> │ ├─R6                                                                          
#> │ ├─crayon                                                                      
#> │ └─rprojroot                                                                   
#> │   └─backports                                                                 
#> ├─digest                                                                        
#> ├─prettyunits                                                                   
#> │ ├─magrittr                                                                    
#> │ └─assertthat                                                                  
#> ├─R6                                                                            
#> ├─rprojroot                                                                     
#> │ └─backports                                                                   
#> └─withr                                                                         
</pre></div>
}}

\subsection{Colored nodes}{

\if{html}{\out{<div class="sourceCode r">}}\preformatted{data$label <- paste(data$package,
  style_dim(paste0("(", c("2.0.0.1", "1.1.1", "0.2.0", "1.2-11",
    "1.5", "1.2", "1.2.0", "1.0.2", "2.0.0", "1.1.1.9000", "1.1.2",
    "2.2.2", "1.3.4", "1.0.2", "0.6.12", "2.2.1", "1.2.1.9002",
    "1.0.0.9000", "2.0.1", "0.20-35"), ")"))
  )
roots <- ! data$package \%in\% unlist(data$dependencies)
data$label[roots] <- col_cyan(style_italic(data$label[roots]))
tree(data, root = "rcmdcheck")
}\if{html}{\out{</div>}}\if{html}{\out{
<div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre>
#> <span style="font-style: italic;color: #2AA198;">rcmdcheck (1.2.1.9002)</span>                                                          
#> ├─callr (1.0.0.9000)                                                            
#> │ ├─processx (2.0.0.1)                                                          
#> │ │ ├─assertthat (0.2.0)                                                        
#> │ │ ├─crayon (1.3.4)                                                            
#> │ │ ├─debugme (1.0.2)                                                           
#> │ │ │ └─crayon (1.3.4)                                                          
#> │ │ └─R6 (2.2.2)                                                                
#> │ └─R6 (2.2.2)                                                                  
#> ├─clisymbols (1.2.0)                                                            
#> ├─crayon (1.3.4)                                                                
#> ├─desc (1.1.1.9000)                                                             
#> │ ├─assertthat (0.2.0)                                                          
#> │ ├─R6 (2.2.2)                                                                  
#> │ ├─crayon (1.3.4)                                                              
#> │ └─rprojroot (1.2)                                                             
#> │   └─backports (1.1.1)                                                         
#> ├─digest (0.6.12)                                                               
#> ├─prettyunits (1.0.2)                                                           
#> │ ├─magrittr (1.5)                                                              
#> │ └─assertthat (0.2.0)                                                          
#> ├─R6 (2.2.2)                                                                    
#> ├─rprojroot (1.2)                                                               
#> │ └─backports (1.1.1)                                                           
#> └─withr (2.0.0)                                                                 
</pre></div>
}}

}

\subsection{Trimming}{

\if{html}{\out{<div class="sourceCode r">}}\preformatted{pkgdeps <- list(
  "dplyr@0.8.3" = c("assertthat@0.2.1", "glue@1.3.1", "magrittr@1.5",
    "R6@2.4.0", "Rcpp@1.0.2", "rlang@0.4.0", "tibble@2.1.3",
    "tidyselect@0.2.5"),
  "assertthat@0.2.1" = character(),
  "glue@1.3.1" = character(),
  "magrittr@1.5" = character(),
  "pkgconfig@2.0.3" = character(),
  "R6@2.4.0" = character(),
  "Rcpp@1.0.2" = character(),
  "rlang@0.4.0" = character(),
  "tibble@2.1.3" = c("cli@1.1.0", "crayon@1.3.4", "fansi@0.4.0",
     "pillar@1.4.2", "pkgconfig@2.0.3", "rlang@0.4.0"),
  "cli@1.1.0" = c("assertthat@0.2.1", "crayon@1.3.4"),
  "crayon@1.3.4" = character(),
  "fansi@0.4.0" = character(),
  "pillar@1.4.2" = c("cli@1.1.0", "crayon@1.3.4", "fansi@0.4.0",
     "rlang@0.4.0", "utf8@1.1.4", "vctrs@0.2.0"),
  "utf8@1.1.4" = character(),
  "vctrs@0.2.0" = c("backports@1.1.5", "ellipsis@0.3.0",
     "digest@0.6.21", "glue@1.3.1", "rlang@0.4.0", "zeallot@0.1.0"),
  "backports@1.1.5" = character(),
  "ellipsis@0.3.0" = c("rlang@0.4.0"),
  "digest@0.6.21" = character(),
  "glue@1.3.1" = character(),
  "zeallot@0.1.0" = character(),
  "tidyselect@0.2.5" = c("glue@1.3.1", "purrr@1.3.1", "rlang@0.4.0",
     "Rcpp@1.0.2"),
  "purrr@0.3.3" = c("magrittr@1.5", "rlang@0.4.0")
)

pkgs <- data.frame(
  stringsAsFactors = FALSE,
  name = names(pkgdeps),
  deps = I(unname(pkgdeps))
)

tree(pkgs, trim = TRUE)
}\if{html}{\out{</div>}}\if{html}{\out{
<div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre>
#> dplyr@0.8.3                                                                     
#> ├─assertthat@0.2.1                                                              
#> ├─glue@1.3.1                                                                    
#> ├─magrittr@1.5                                                                  
#> ├─R6@2.4.0                                                                      
#> ├─Rcpp@1.0.2                                                                    
#> ├─rlang@0.4.0                                                                   
#> ├─tibble@2.1.3                                                                  
#> │ ├─cli@1.1.0                                                                   
#> │ │ ├─assertthat@0.2.1                                                          
#> │ │ └─crayon@1.3.4                                                              
#> │ ├─crayon@1.3.4                                                                
#> │ ├─fansi@0.4.0                                                                 
#> │ ├─pillar@1.4.2                                                                
#> │ │ ├─cli@1.1.0                                                                 
#> │ │ ├─crayon@1.3.4                                                              
#> │ │ ├─fansi@0.4.0                                                               
#> │ │ ├─rlang@0.4.0                                                               
#> │ │ ├─utf8@1.1.4                                                                
#> │ │ └─vctrs@0.2.0                                                               
#> │ │   ├─backports@1.1.5                                                         
#> │ │   ├─ellipsis@0.3.0                                                          
#> │ │   │ └─rlang@0.4.0                                                           
#> │ │   ├─digest@0.6.21                                                           
#> │ │   ├─glue@1.3.1                                                              
#> │ │   ├─rlang@0.4.0                                                             
#> │ │   └─zeallot@0.1.0                                                           
#> │ ├─pkgconfig@2.0.3                                                             
#> │ └─rlang@0.4.0                                                                 
#> └─tidyselect@0.2.5                                                              
#>   ├─glue@1.3.1                                                                  
#>   ├─rlang@0.4.0                                                                 
#>   └─Rcpp@1.0.2                                                                  
</pre></div>
}}


\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Mark the trimmed nodes
pkgs$label <- pkgs$name
pkgs$trimmed <- paste(pkgs$name, " (trimmed)")
tree(pkgs, trim = TRUE)
}\if{html}{\out{</div>}}\if{html}{\out{
<div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre>
#> dplyr@0.8.3                                                                     
#> ├─assertthat@0.2.1                                                              
#> ├─glue@1.3.1                                                                    
#> ├─magrittr@1.5                                                                  
#> ├─R6@2.4.0                                                                      
#> ├─Rcpp@1.0.2                                                                    
#> ├─rlang@0.4.0                                                                   
#> ├─tibble@2.1.3                                                                  
#> │ ├─cli@1.1.0                                                                   
#> │ │ ├─assertthat@0.2.1  (trimmed)                                               
#> │ │ └─crayon@1.3.4                                                              
#> │ ├─crayon@1.3.4  (trimmed)                                                     
#> │ ├─fansi@0.4.0                                                                 
#> │ ├─pillar@1.4.2                                                                
#> │ │ ├─cli@1.1.0  (trimmed)                                                      
#> │ │ ├─crayon@1.3.4  (trimmed)                                                   
#> │ │ ├─fansi@0.4.0  (trimmed)                                                    
#> │ │ ├─rlang@0.4.0  (trimmed)                                                    
#> │ │ ├─utf8@1.1.4                                                                
#> │ │ └─vctrs@0.2.0                                                               
#> │ │   ├─backports@1.1.5                                                         
#> │ │   ├─ellipsis@0.3.0                                                          
#> │ │   │ └─rlang@0.4.0  (trimmed)                                                
#> │ │   ├─digest@0.6.21                                                           
#> │ │   ├─glue@1.3.1  (trimmed)                                                   
#> │ │   ├─rlang@0.4.0  (trimmed)                                                  
#> │ │   └─zeallot@0.1.0                                                           
#> │ ├─pkgconfig@2.0.3                                                             
#> │ └─rlang@0.4.0  (trimmed)                                                      
#> └─tidyselect@0.2.5                                                              
#>   ├─glue@1.3.1  (trimmed)                                                       
#>   ├─rlang@0.4.0  (trimmed)                                                      
#>   └─Rcpp@1.0.2  (trimmed)                                                       
</pre></div>
}}

}
}