tracee makes it easy to save plots, tables and data from
R in a way that can always be traced back to the code that produced
them.
When you write an output with tracee, you get:
"%model/%name_%model" or
"%script/%name".ggplots, flextables and data frames can be
written one at a time or as a whole list in a single call."standard", "wide",
"wide-screen", "A4", …) for slides and
reports, or your own dimensions.save = TRUE.The project website is at https://nmautoverse.github.io/tracee/.
tracee is on CRAN and MPN:
install.packages("tracee")The development version can be installed from GitHub:
# install.packages("remotes")
remotes::install_github("NMautoverse/tracee")| Function | Purpose |
|---|---|
ggwrite() |
Write ggplot objects (or lists of them) to
png/pdf with stamp |
ftwrite() |
Write flextable objects to png,
docx, pptx, html,
rds |
datwrite() |
Write data frames (via NMdata::NMwriteData()) with
metadata |
writer() |
Detect the object type and dispatch to the right writer |
lwrite() |
Write a (nested) list of plots, tables and data in one call |
ggstamp(), ftstamp() |
Add a traceability stamp without writing to file |
pathFormat() |
Build output paths from templates using %model,
%script, %name |
canvasSize() |
Predefined output dimensions |
traceit() |
Attach script/model/time information to an object for later writing |
The device is chosen from the file name extension (png
or pdf).
library(ggplot2)
library(tracee)
p <- ggplot(ChickWeight, aes(Time, weight, group = Chick)) + geom_line()
ggwrite(p, file = "output/chickweight.png", script = "analysis/plots.R")The plot is saved with a caption showing the script, the output file and the time of creation.
ggwrite(p, file = "output/chickweight.png",
formats = c("png", "pdf"),
canvas = list(slide = "wide", report = "standard"),
script = "analysis/plots.R")
# output/chickweight_slide.png, output/chickweight_report.png, and pdf versionslibrary(flextable)
ft <- flextable(head(ChickWeight))
ftwrite(ft, file = "output/chickweight_table.png", script = "analysis/plots.R")Path formats keep file names consistent across a project. For example, model-specific outputs can be grouped into a folder per model:
ggwrite(p, file = "gof.png", model = "run001",
path.format = "%model/%name_%model",
script = "analysis/plots.R")
# run001/gof_run001.pngThe default format is "%name", i.e. file is
used as is. See ?pathFormat for details.
Collect the outputs of a script in a list and write them in one go. Plots, tables and data frames are each sent to the right writer:
outputs <- list(
gof = p,
table = ft,
data = ChickWeight
)
lwrite(outputs, dir = "output", model = "run001",
path.format = "%model/%name_%model",
script = "analysis/plots.R")writeOutput <- FALSE # set to TRUE when ready to write files
ggwrite(p, file = "output/chickweight.png", save = writeOutput)See the vignette Writing outputs with tracee
(vignette("writing-outputs", package = "tracee")) and the
function
reference.