Skip to contents

This function prints a (possibly abbreviated) data.frame.

Usage

print_data.frame(
  x,
  rows = NULL,
  cols = NULL,
  digits = NULL,
  row.names = TRUE,
  col.names = TRUE
)

Arguments

x

[data.frame]
A data.frame.

rows, cols

[integer(1) | NULL ]
The number of rows or columns to be printed, greater or equal 2.

Printing is abbreviated in the middle.

Can be NULL to print everything.

digits

[integer(1) | NULL ]
The number of decimal places to be used.

Negative values are allowed, resulting in rounding to a power of ten.

Can be NULL to not round.

row.names, col.names

[logical(1)]
Print row names or column names?

Value

Invisibly returns x.

Examples

x <- data.frame(1:10, LETTERS[1:10], stats::rnorm(10))
print_data.frame(x, rows = 7)
#>    X1.10 LETTERS.1.10. stats..rnorm.10.
#> 1   1    A             -0.73142807     
#> 2   2    B             -0.47149498     
#> 3   3    C             -0.58751419     
#> 4   4    D              0.03818978     
#> 
#> <3 rows hidden>
#>                                        
#> 8   8    H              1.58779197     
#> 9   9    I             -0.67494786     
#> 10 10    J             -1.26820210     
print_data.frame(x, rows = 7, cols = 2)
#>    X1.10 <1 col hidden> stats..rnorm.10.
#> 1   1          -        -0.73142807     
#> 2   2          -        -0.47149498     
#> 3   3          -        -0.58751419     
#> 4   4          -         0.03818978     
#> 
#> <3 rows hidden>
#>                                         
#> 8   8          -         1.58779197     
#> 9   9          -        -0.67494786     
#> 10 10          -        -1.26820210     
print_data.frame(x, rows = 7, cols = 2, digits = 1)
#>    X1.10 <1 col hidden> stats..rnorm.10.
#> 1   1          -        -0.7            
#> 2   2          -        -0.5            
#> 3   3          -        -0.6            
#> 4   4          -         0.0            
#> 
#> <3 rows hidden>
#>                                         
#> 8   8          -         1.6            
#> 9   9          -        -0.7            
#> 10 10          -        -1.3            
print_data.frame(x, rows = 7, cols = 2, digits = 1, row.names = FALSE)
#>  X1.10 <1 col hidden> stats..rnorm.10.
#>   1          -        -0.7            
#>   2          -        -0.5            
#>   3          -        -0.6            
#>   4          -         0.0            
#> 
#> <3 rows hidden>
#>                                       
#>   8          -         1.6            
#>   9          -        -0.7            
#>  10          -        -1.3            
print_data.frame(x, rows = 7, cols = 2, digits = 1, col.names = FALSE)
#>       <1 col hidden>     
#> 1   1       -        -0.7
#> 2   2       -        -0.5
#> 3   3       -        -0.6
#> 4   4       -         0.0
#> 
#> <3 rows hidden>
#>                          
#> 8   8       -         1.6
#> 9   9       -        -0.7
#> 10 10       -        -1.3