The super useful function str() uses .. to indicate the level of sub-elements of an object, which may be difficult to read. This function uses vertical pipes to connect all sub-elements on the same level, so it is clearer which elements belong to the same parent element in an object with a nested structure (such as a nested list).

tree(...)

Arguments

...

Arguments to be passed to str() (note that the comp.str is hardcoded inside this function, and it is the only argument that you cannot customize).

Value

A character string as a raw_string().

Examples

fit = lsfit(1:9, 1:9)
str(fit)
#> List of 4
#>  $ coefficients: Named num [1:2] 1.11e-15 1.00
#>   ..- attr(*, "names")= chr [1:2] "Intercept" "X"
#>  $ residuals   : num [1:9] -7.86e-16 1.44e-15 -2.09e-16 -1.96e-16 -1.69e-16 ...
#>  $ intercept   : logi TRUE
#>  $ qr          :List of 6
#>   ..$ qt   : num [1:9] -1.50e+01 7.75 -1.81e-16 4.17e-32 1.95e-16 ...
#>   ..$ qr   : num [1:9, 1:2] -3 0.333 0.333 0.333 0.333 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : NULL
#>   .. .. ..$ : chr [1:2] "Intercept" "X"
#>   ..$ qraux: num [1:2] 1.33 1.26
#>   ..$ rank : int 2
#>   ..$ pivot: int [1:2] 1 2
#>   ..$ tol  : num 1e-07
#>   ..- attr(*, "class")= chr "qr"
xfun::tree(fit)
#> List of 4
#>  |-coefficients: Named num [1:2] 1.11e-15 1.00
#>  |  - attr(*, "names")= chr [1:2] "Intercept" "X"
#>  |-residuals   : num [1:9] -7.86e-16 1.44e-15 -2.09e-16 -1.96e-16 -1.69e-16 ...
#>  |-intercept   : logi TRUE
#>  |-qr          :List of 6
#>     |-qt   : num [1:9] -1.50e+01 7.75 -1.81e-16 4.17e-32 1.95e-16 ...
#>     |-qr   : num [1:9, 1:2] -3 0.333 0.333 0.333 0.333 ...
#>     |  - attr(*, "dimnames")=List of 2
#>     |     |-: NULL
#>     |     |-: chr [1:2] "Intercept" "X"
#>     |-qraux: num [1:2] 1.33 1.26
#>     |-rank : int 2
#>     |-pivot: int [1:2] 1 2
#>     |-tol  : num 1e-07
#>     - attr(*, "class")= chr "qr"

fit = lm(dist ~ speed, data = cars)
str(fit)
#> List of 12
#>  $ coefficients : Named num [1:2] -17.58 3.93
#>   ..- attr(*, "names")= chr [1:2] "(Intercept)" "speed"
#>  $ residuals    : Named num [1:50] 3.85 11.85 -5.95 12.05 2.12 ...
#>   ..- attr(*, "names")= chr [1:50] "1" "2" "3" "4" ...
#>  $ effects      : Named num [1:50] -303.914 145.552 -8.115 9.885 0.194 ...
#>   ..- attr(*, "names")= chr [1:50] "(Intercept)" "speed" "" "" ...
#>  $ rank         : int 2
#>  $ fitted.values: Named num [1:50] -1.85 -1.85 9.95 9.95 13.88 ...
#>   ..- attr(*, "names")= chr [1:50] "1" "2" "3" "4" ...
#>  $ assign       : int [1:2] 0 1
#>  $ qr           :List of 5
#>   ..$ qr   : num [1:50, 1:2] -7.071 0.141 0.141 0.141 0.141 ...
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : chr [1:50] "1" "2" "3" "4" ...
#>   .. .. ..$ : chr [1:2] "(Intercept)" "speed"
#>   .. ..- attr(*, "assign")= int [1:2] 0 1
#>   ..$ qraux: num [1:2] 1.14 1.27
#>   ..$ pivot: int [1:2] 1 2
#>   ..$ tol  : num 1e-07
#>   ..$ rank : int 2
#>   ..- attr(*, "class")= chr "qr"
#>  $ df.residual  : int 48
#>  $ xlevels      : Named list()
#>  $ call         : language lm(formula = dist ~ speed, data = cars)
#>  $ terms        :Classes 'terms', 'formula'  language dist ~ speed
#>   .. ..- attr(*, "variables")= language list(dist, speed)
#>   .. ..- attr(*, "factors")= int [1:2, 1] 0 1
#>   .. .. ..- attr(*, "dimnames")=List of 2
#>   .. .. .. ..$ : chr [1:2] "dist" "speed"
#>   .. .. .. ..$ : chr "speed"
#>   .. ..- attr(*, "term.labels")= chr "speed"
#>   .. ..- attr(*, "order")= int 1
#>   .. ..- attr(*, "intercept")= int 1
#>   .. ..- attr(*, "response")= int 1
#>   .. ..- attr(*, ".Environment")=<environment: 0x5561e5fa4db8> 
#>   .. ..- attr(*, "predvars")= language list(dist, speed)
#>   .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
#>   .. .. ..- attr(*, "names")= chr [1:2] "dist" "speed"
#>  $ model        :'data.frame':	50 obs. of  2 variables:
#>   ..$ dist : num [1:50] 2 10 4 22 16 10 18 26 34 17 ...
#>   ..$ speed: num [1:50] 4 4 7 7 8 9 10 10 10 11 ...
#>   ..- attr(*, "terms")=Classes 'terms', 'formula'  language dist ~ speed
#>   .. .. ..- attr(*, "variables")= language list(dist, speed)
#>   .. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
#>   .. .. .. ..- attr(*, "dimnames")=List of 2
#>   .. .. .. .. ..$ : chr [1:2] "dist" "speed"
#>   .. .. .. .. ..$ : chr "speed"
#>   .. .. ..- attr(*, "term.labels")= chr "speed"
#>   .. .. ..- attr(*, "order")= int 1
#>   .. .. ..- attr(*, "intercept")= int 1
#>   .. .. ..- attr(*, "response")= int 1
#>   .. .. ..- attr(*, ".Environment")=<environment: 0x5561e5fa4db8> 
#>   .. .. ..- attr(*, "predvars")= language list(dist, speed)
#>   .. .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
#>   .. .. .. ..- attr(*, "names")= chr [1:2] "dist" "speed"
#>  - attr(*, "class")= chr "lm"
xfun::tree(fit)
#> List of 12
#>  |-coefficients : Named num [1:2] -17.58 3.93
#>  |  - attr(*, "names")= chr [1:2] "(Intercept)" "speed"
#>  |-residuals    : Named num [1:50] 3.85 11.85 -5.95 12.05 2.12 ...
#>  |  - attr(*, "names")= chr [1:50] "1" "2" "3" "4" ...
#>  |-effects      : Named num [1:50] -303.914 145.552 -8.115 9.885 0.194 ...
#>  |  - attr(*, "names")= chr [1:50] "(Intercept)" "speed" "" "" ...
#>  |-rank         : int 2
#>  |-fitted.values: Named num [1:50] -1.85 -1.85 9.95 9.95 13.88 ...
#>  |  - attr(*, "names")= chr [1:50] "1" "2" "3" "4" ...
#>  |-assign       : int [1:2] 0 1
#>  |-qr           :List of 5
#>  |  |-qr   : num [1:50, 1:2] -7.071 0.141 0.141 0.141 0.141 ...
#>  |  |  - attr(*, "dimnames")=List of 2
#>  |  |     |-: chr [1:50] "1" "2" "3" "4" ...
#>  |  |     |-: chr [1:2] "(Intercept)" "speed"
#>  |  |  - attr(*, "assign")= int [1:2] 0 1
#>  |  |-qraux: num [1:2] 1.14 1.27
#>  |  |-pivot: int [1:2] 1 2
#>  |  |-tol  : num 1e-07
#>  |  |-rank : int 2
#>  |  - attr(*, "class")= chr "qr"
#>  |-df.residual  : int 48
#>  |-xlevels      : Named list()
#>  |-call         : language lm(formula = dist ~ speed, data = cars)
#>  |-terms        :Classes 'terms', 'formula'  language dist ~ speed
#>  |     - attr(*, "variables")= language list(dist, speed)
#>  |     - attr(*, "factors")= int [1:2, 1] 0 1
#>  |        - attr(*, "dimnames")=List of 2
#>  |           |-: chr [1:2] "dist" "speed"
#>  |           |-: chr "speed"
#>  |     - attr(*, "term.labels")= chr "speed"
#>  |     - attr(*, "order")= int 1
#>  |     - attr(*, "intercept")= int 1
#>  |     - attr(*, "response")= int 1
#>  |     - attr(*, ".Environment")=<environment: 0x5561e5fa4db8> 
#>  |     - attr(*, "predvars")= language list(dist, speed)
#>  |     - attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
#>  |        - attr(*, "names")= chr [1:2] "dist" "speed"
#>  |-model        :'data.frame':	50 obs. of  2 variables:
#>     |-dist : num [1:50] 2 10 4 22 16 10 18 26 34 17 ...
#>     |-speed: num [1:50] 4 4 7 7 8 9 10 10 10 11 ...
#>     - attr(*, "terms")=Classes 'terms', 'formula'  language dist ~ speed
#>           - attr(*, "variables")= language list(dist, speed)
#>           - attr(*, "factors")= int [1:2, 1] 0 1
#>              - attr(*, "dimnames")=List of 2
#>                 |-: chr [1:2] "dist" "speed"
#>                 |-: chr "speed"
#>           - attr(*, "term.labels")= chr "speed"
#>           - attr(*, "order")= int 1
#>           - attr(*, "intercept")= int 1
#>           - attr(*, "response")= int 1
#>           - attr(*, ".Environment")=<environment: 0x5561e5fa4db8> 
#>           - attr(*, "predvars")= language list(dist, speed)
#>           - attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
#>              - attr(*, "names")= chr [1:2] "dist" "speed"
#>  - attr(*, "class")= chr "lm"

# some trivial examples
xfun::tree(1:10)
#>  int [1:10] 1 2 3 4 5 6 7 8 9 10
xfun::tree(iris)
#> 'data.frame':	150 obs. of  5 variables:
#>  |-Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#>  |-Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#>  |-Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#>  |-Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#>  |-Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...