| traceit | R Documentation |
The traceit family of functions attaches metadata to R objects that can be
used later by writer functions to automatically determine output settings. This
allows you to "trace" or "tag" objects with information about how they should be
written, then write them later without having to re-specify those settings.
traceit(x, ...)
## S3 method for class 'ggplot'
traceit(x, ..., quite = TRUE)
## S3 method for class 'flextable'
traceit(x, ..., quite = TRUE)
## S3 method for class 'data.frame'
traceit(x, ..., quite = TRUE)
## S3 method for class 'traceit'
traceit(x, ..., quite = TRUE)
x |
An R object to attach trace attributes to. Can be a |
... |
Named arguments that will be stored as trace attributes. For ggplot
objects, valid arguments match those in |
quite |
Logical. If |
The traceit function is a generic that dispatches to specific methods based
on the class of x:
traceit.ggplot: For ggplot objects
traceit.flextable: For flextable objects
traceit.data.frame: For data frames
traceit.traceit: For objects that already have traceit attributes
(allows updating existing trace information)
When an object is traced, two attributes are added:
args: A list of arguments to be used when writing the object
class: The class vector is prepended with "traceit" to indicate
the object has been traced
Arguments passed to traceit are filtered to include only those that are
valid for the corresponding writer function. Invalid arguments are silently ignored.
When calling traceit on an already-traced object, the new arguments are
merged with existing trace arguments using modifyList, with
new arguments taking precedence.
Returns x invisibly with trace attributes attached. The object
can be used normally and the trace attributes will be preserved.
To extract trace attributes from an object, use argsFromTrace.
ggwrite for writing ggplot objects,
ftwrite for writing flextable objects,
NMwriteData for writing data frames,
argsFromTrace for extracting trace attributes,
writer for a unified writing interface
## Not run:
library(ggplot2)
library(flextable)
# Create a plot and trace it with output settings
p1 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
p1_traced <- traceit(p1, canvas = "wide", formats = c("png", "pdf"))
# The traced plot can be written later without re-specifying settings
# writer() will automatically use the traced arguments
# Trace a flextable
ft1 <- flextable(head(mtcars))
ft1_traced <- traceit(ft1, formats = "docx")
# Update trace attributes on an already-traced object
p1_traced <- traceit(p1_traced, canvas = "standard") # overrides previous canvas
# Trace a data frame for NMwriteData
df1 <- data.frame(ID = 1:10, DV = rnorm(10))
df1_traced <- traceit(df1, file = "mydata.csv")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.