R: Convert objects to huxtables

as_huxtable {huxtable} | R Documentation

## Convert objects to huxtables

### Description

`as_huxtable` or `as_hux` converts an object to a huxtable. Conversion methods exist for data frames, tables, ftables, matrices and (most) vectors. `is_hux[table]` tests if an object is a huxtable.

### Usage

    as_huxtable(x, ...)

    as_hux(x, ...)

    ## Default S3 method:
    as_huxtable(x,
      add_colnames = getOption("huxtable.add_colnames", FALSE),
      add_rownames = FALSE, autoformat = getOption("huxtable.autoformat",
      TRUE), ...)

    is_huxtable(x)

    is_hux(x)

### Arguments

`x` | Object to convert.
`...` | Arguments passed on to `huxtable()`.
`add_colnames` | If `TRUE`, add a first row of column names to the huxtable.
`add_rownames` | If `TRUE`, add a first column of row names, named 'rownames', to the huxtable.
`autoformat` | If `TRUE`, automatically format columns by type. See below.

### Value

An object of class "huxtable".

### Examples

    dfr <- data.frame(a = 1:5, b = letters[1:5], stringsAsFactors = FALSE)
    as_huxtable(dfr)
    mx <- matrix(letters[1:12], 4, 3)
    as_huxtable(mx)
    library(stats)
    tbl <- table(Wool = warpbreaks$wool, Tension = warpbreaks$tension)
    as_huxtable(tbl) # adds row and column names by default

[Package huxtable version 4.2.0 Index]