huxtable: Create a huxtable

Description Usage Arguments Details Value Automatic formatting See Also Examples

Description

huxtable, or hux, creates a huxtable object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
huxtable(
  ...,
  add_colnames = getOption("huxtable.add_colnames", TRUE),
  add_rownames = FALSE,
  autoformat = getOption("huxtable.autoformat", TRUE)
)

hux(
  ...,
  add_colnames = getOption("huxtable.add_colnames", TRUE),
  add_rownames = FALSE,
  autoformat = getOption("huxtable.autoformat", TRUE)
)

tribble_hux(
  ...,
  add_colnames = getOption("huxtable.add_colnames", TRUE),
  autoformat = getOption("huxtable.autoformat", TRUE)
)

Arguments

...

For huxtable, named list of values as in data.frame(). For tribble_hux, data values as in tibble::tribble().

add_colnames

If TRUE, add a first row of column names to the huxtable.

add_rownames

If TRUE or a character string, add a first column of row names to the huxtable. The string gives the name for the new column (or "rownames" for TRUE).

autoformat

If TRUE, automatically format columns by type. See below.

Details

If you use add_colnames or add_rownames, be aware that these will shift your rows and columns along by one: your old row/column 1 will now be row/column 2, etc.

add_colnames defaults to TRUE. You can set the default globally by setting options("huxtable.add_colnames") to TRUE or FALSE.

tribble_hux is a simple wrapper around tibble::tribble() which lets you create data in a readable format. It requires the "tibble" package to be installed.

Value

An object of class huxtable.

Automatic formatting

If autoformat is TRUE, then columns will have number_format() and align() properties set automatically, as follows:

You can change these defaults by editing options("huxtable.autoformat_number_format") and options("huxtable.autoformat_align"). See huxtable-package for more details.

Automatic alignment also applies to column headers if add_colnames is TRUE; headers of columns aligned on a decimal point will be right-aligned. Automatic number formatting does not apply to column headers.

See Also

huxtable-options

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ht <- huxtable(
        column1 = 1:5,
        column2 = letters[1:5]
      )
ht
tribble_hux(
  ~ Name,             ~ Salary,
    "John Smith",       50000,
    "Jane Doe",         50000,
    "David Hugh-Jones", 50000,
    add_colnames = TRUE
)

Example output

        1   a        
        2   b        
        3   c        
        4   d        
        5   e        

Column names: column1, column2
  Name                Salary  
  John Smith           5e+04  
  Jane Doe             5e+04  
  David Hugh-Jones     5e+04  

Column names: Name, Salary

huxtable documentation built on July 1, 2020, 7:13 p.m.