The tibble S3 generic function pillar::glimpse() is implemented for prt objects as well. Inspired by the output of str() when applied to data.frames, this function is intended to display the structure of the data in terms of columns, irrespective of how the data is organized in terms of R objects. Similarly to format_dt(), the function providing the bulk of functionality, glimpse_dt(), is exported such that implementing a class specific pillar::glimpse() function for other classes that representing tabular data is straightforward.

# S3 method for prt
glimpse(x, width = NULL, ...)

glimpse_dt(x, width = NULL)

str_sum(x)

# S3 method for prt
str(object, ...)

str_dt(x, ...)

Arguments

x

An object to glimpse at.

width

Width of output: defaults to the setting of the width option (if finite) or the width of the console.

...

Unused, for extensibility.

object

any R object about which you want to have some information.

Details

Alongside a prt-specific pillar::glimpse() method, a str() method is provided as well for prt objects. However, breaking with base R expectations, it is not the structure of the object in terms of R objects that is shown, but in the same spirit as pillar::glimpse() it is the structure of the data that is printed. How this data is represents with respect to R objects is abstracted away as to show output as would be expected if the data were represented by a data.frame.

In similar spirit as format_dt() and glimpse_dt(), a str_dt() function is exported which provides the core functionality driving the prt implementation of str(). This function requires availability of a head() function for any object that is passed and output can be customized by implementing an optional str_sum() function.

Examples

cars <- as_prt(mtcars)

pillar::glimpse(cars)
#> Rows: 32
#> Columns: 11
#> Partitioning: [32] rows
#> $ mpg  <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8…
#> $ cyl  <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 8…
#> $ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8, 1…
#> $ hp   <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, 18…
#> $ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92…
#> $ wt   <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3…
#> $ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90, 1…
#> $ vs   <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0…
#> $ am   <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0…
#> $ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3…
#> $ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2…
pillar::glimpse(cars, width = 30)
#> Rows: 32
#> Columns: 11
#> Partitioning: [32] rows
#> $ mpg  <dbl> 21.0, 21.0, 22…
#> $ cyl  <dbl> 6, 6, 4, 6, 8,…
#> $ disp <dbl> 160.0, 160.0, …
#> $ hp   <dbl> 110, 110, 93, …
#> $ drat <dbl> 3.90, 3.90, 3.…
#> $ wt   <dbl> 2.620, 2.875, …
#> $ qsec <dbl> 16.46, 17.02, …
#> $ vs   <dbl> 0, 0, 1, 1, 0,…
#> $ am   <dbl> 1, 1, 1, 0, 0,…
#> $ gear <dbl> 4, 4, 4, 3, 3,…
#> $ carb <dbl> 4, 4, 1, 1, 2,…

str(cars)
#> 'prt':	32 obs. of 11 variables in 1 partition:
#>  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
#>  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
#>  $ disp: num  160 160 108 258 360 ...
#>  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
#>  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
#>  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
#>  $ qsec: num  16.5 17 18.6 19.4 17 ...
#>  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
#>  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
#>  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
#>  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
str(cars, vec.len = 1)
#> 'prt':	32 obs. of 11 variables in 1 partition:
#>  $ mpg : num  21 21 ...
#>  $ cyl : num  6 6 ...
#>  $ disp: num  160 160 ...
#>  $ hp  : num  110 110 ...
#>  $ drat: num  3.9 3.9 ...
#>  $ wt  : num  2.62 ...
#>  $ qsec: num  16.5 ...
#>  $ vs  : num  0 0 ...
#>  $ am  : num  1 1 ...
#>  $ gear: num  4 4 ...
#>  $ carb: num  4 4 ...

str(unclass(cars))
#> List of 1
#>  $ :List of 4
#>   ..$ meta         :List of 7
#>   .. ..$ path           : chr "/tmp/Rtmpp89cNw/file157ea5cd09b/1.fst"
#>   .. ..$ nrOfRows       : num 32
#>   .. ..$ keys           : NULL
#>   .. ..$ columnNames    : chr [1:11] "mpg" "cyl" "disp" "hp" ...
#>   .. ..$ columnBaseTypes: int [1:11] 5 5 5 5 5 5 5 5 5 5 ...
#>   .. ..$ keyColIndex    : NULL
#>   .. ..$ columnTypes    : int [1:11] 10 10 10 10 10 10 10 10 10 10 ...
#>   .. ..- attr(*, "class")= chr "fstmetadata"
#>   ..$ col_selection: NULL
#>   ..$ row_selection: NULL
#>   ..$ old_format   : logi FALSE

str_sum(cars)
#> [1] "'prt':\t32 obs. of 11 variables in 1 partition:\n"