Lifecycle: experimental CRAN status R-CMD-check pkgdown

tracee

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:

The project website is at https://nmautoverse.github.io/tracee/.

Installation

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")

Overview of functions

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

Examples

Save a plot with a stamp

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.

Multiple formats and canvas sizes in one call

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 versions

Save a table

library(flextable)
ft <- flextable(head(ChickWeight))
ftwrite(ft, file = "output/chickweight_table.png", script = "analysis/plots.R")

Organize outputs by model or script

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.png

The default format is "%name", i.e. file is used as is. See ?pathFormat for details.

Write everything at once

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")

Switch between viewing and saving

writeOutput <- FALSE   # set to TRUE when ready to write files
ggwrite(p, file = "output/chickweight.png", save = writeOutput)

Learn more

See the vignette Writing outputs with tracee (vignette("writing-outputs", package = "tracee")) and the function reference.

mirror server hosted at Truenetwork, Russian Federation.