as_huxtable | R Documentation |
as_huxtable
or as_hux
converts an object to a huxtable.
Conversion methods exist for data frames and tibbles, tables,
ftables, matrices and (most) vectors.
as_huxtable(x, ...)
as_hux(x, ...)
## Default S3 method:
as_huxtable(
x,
add_colnames = getOption("huxtable.add_colnames", TRUE),
add_rownames = FALSE,
autoformat = getOption("huxtable.autoformat", TRUE),
...
)
## S3 method for class 'grouped_df'
as_huxtable(x, ..., groups_to_headers = FALSE)
is_huxtable(x)
is_hux(x)
x |
Object to convert. |
... |
Arguments passed on to |
add_colnames |
If |
add_rownames |
If |
autoformat |
If |
groups_to_headers |
Logical. Convert groups to header rows? |
is_hux[table]
tests if an object is a huxtable.
For table
objects, add_colnames
and add_rownames
are TRUE
by default. For
matrix
objects, they are FALSE
. Other classes use
options("huxtable.add_colnames")
, which is TRUE
by default; add_rownames
is FALSE
.
For dplyr::grouped_df()
objects, groups will be converted to header rows
if groups_to_headers
is TRUE
.
An object of class "huxtable".
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, add_colnames = FALSE)
library(stats)
tbl <- table(
Wool = warpbreaks$wool,
Tension = warpbreaks$tension
)
as_huxtable(tbl) # adds row and column names by default
# adding rownames:
as_hux(mtcars[1:3,], add_colnames = TRUE,
add_rownames = "Car")
if (requireNamespace("dplyr")) {
iris_grp <- dplyr::group_by(iris[c(1:4, 51:54, 101:104), ], Species)
as_hux(iris_grp, groups_to_headers = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.