pillar() creates an object that formats a vector. The output uses one row for a title (if given), one row for the type, and vec_size(x) rows for the data.

pillar(x, title = NULL, width = NULL, ...)

Arguments

x

A vector to format.

title

An optional title for the column. The title will be used "as is", no quoting will be applied.

width

Default width, optional.

...

Passed on to pillar_shaft().

Details

A pillar consists of arbitrary components. The pillar() constructor uses title, type, and data.

All components are formatted via format() when displaying the pillar. A width argument is passed to each format() call.

As of pillar 1.5.0, pillar() returns NULL if the width is insufficient to display the data.

Examples

x <- 123456789 * (10^c(-1, -3, -5, NA, -8, -10))
pillar(x)
#> <pillar>
#>         <dbl>
#> 12345679.    
#>   123457.    
#>     1235.    
#>       NA     
#>        1.23  
#>        0.0123
pillar(-x)
#> <pillar>
#>    <dbl>
#> -1.23e+7
#> -1.23e+5
#> -1.23e+3
#> NA      
#> -1.23e+0
#> -1.23e-2
pillar(runif(10))
#> <pillar>
#> <dbl>
#> 0.222
#> 0.121
#> 0.531
#> 0.795
#> 0.353
#> 0.937
#> 0.633
#> 0.657
#> 0.900
#> 0.617
pillar(rcauchy(20))
#> <pillar>
#>   <dbl>
#> -1.34  
#> -6.88  
#> -0.695 
#>  0.652 
#> -1.17  
#> -2.46  
#>  0.182 
#> -2.19  
#>  3.58  
#>  0.0878
#> -1.09  
#>  0.0877
#>  1.23  
#>  1.30  
#>  1.62  
#>  1.08  
#>  8.26  
#>  2.44  
#>  0.177 
#> -0.887 

# Special values are highlighted
pillar(c(runif(5), NA, NaN, Inf, -Inf))
#> <pillar>
#>    <dbl>
#>    0.869
#>    0.871
#>    0.623
#>    0.297
#>    0.449
#>   NA    
#>  NaN    
#>  Inf    
#> -Inf    

# Very wide ranges will be displayed in scientific format
pillar(c(1e10, 1e-10), width = 20)
#> <pillar>
#>                <dbl>
#>                1e+10
#>                1e-10
pillar(c(1e10, 1e-10))
#> <pillar>
#> <dbl>
#> 1e+10
#> 1e-10

x <- c(FALSE, NA, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE)
pillar(x)
#> <pillar>
#> <lgl>
#> FALSE
#> NA   
#> FALSE
#> FALSE
#> TRUE 
#> FALSE
#> FALSE
#> TRUE 
#> FALSE
#> TRUE 

x <- c("This is string is rather long", NA, "?", "Short")
pillar(x)
#> <pillar>
#> <chr>                        
#> This is string is rather long
#> NA                           
#> ?                            
#> Short                        
pillar(x, width = 30)
#> <pillar>
#> <chr>                         
#> This is string is rather long 
#> NA                            
#> ?                             
#> Short                         
pillar(x, width = 5)
#> <pillar>
#> <chr>
#> This…
#> NA   
#> ?    
#> Short

date <- as.Date("2017-05-15")
pillar(date + c(1, NA, 3:5))
#> <pillar>
#> <date>    
#> 2017-05-16
#> NA        
#> 2017-05-18
#> 2017-05-19
#> 2017-05-20
pillar(as.POSIXct(date) + c(30, NA, 600, 3600, 86400))
#> <pillar>
#> <dttm>             
#> 2017-05-15 00:00:30
#> NA                 
#> 2017-05-15 00:10:00
#> 2017-05-15 01:00:00
#> 2017-05-16 00:00:00