| trclass | R Documentation |
Internal function that determines the appropriate class type of an object for dispatching to the correct writer function. This function classifies objects into one of several categories: "flextable", "data.frame", "gg" (for ggplot/gtable objects), "list", or throws an error for unknown types.
trclass(x)
x |
An R object to classify. Can be a |
The function checks object class in the following priority order:
flextable: checked via "flextable" %in% class(x)
data.frame: checked via is.data.frame(x)
gg: checked via is.gg(x) (includes ggplot and gtable)
list: checked via is.list(x) && !is.gg(x)
If none match: throws an error
This function is primarily used internally by writer and
traceit.traceit to determine which specific writer function
to call (ggwrite, ftwrite, or datwrite).
The function ignores the "traceit" class that may be prepended by
traceit, allowing it to classify traced objects by their
underlying type.
A character string indicating the object class type:
"flextable": for flextable objects
"data.frame": for data frame objects
"gg": for ggplot or gtable objects
"list": for list objects (that are not plots)
writer for the main writer function that uses this classification,
traceit.traceit for traceit method that uses this,
is.gg for plot object detection,
is.listnotplot for list detection logic
## Not run:
library(ggplot2)
library(flextable)
# Classify different object types
trclass(mtcars) # Returns: "data.frame"
p1 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
trclass(p1) # Returns: "gg"
ft1 <- flextable(head(mtcars))
trclass(ft1) # Returns: "flextable"
trclass(list(p1, ft1)) # Returns: "list"
# Works with traced objects too
p1_traced <- traceit(p1, canvas = "wide")
trclass(p1_traced) # Still returns: "gg"
# Unknown types throw an error
trclass(matrix(1:4, 2)) # Error: x is an unknown format
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.