Saves an audit_trail() to disk as either an RDS file (default) or a
JSON file. The RDS format preserves all R types and can be restored
perfectly with read_trail(). The JSON format produces a human-readable
representation suitable for archiving or interoperability with other tools.
Usage
write_trail(.trail, file, format = c("rds", "json"))Arguments
- .trail
An
audit_trail()object.- file
Path to the output file. A
.rdsextension is conventional forformat = "rds";.jsonforformat = "json".- format
One of
"rds"(default) or"json". The JSON format requires the jsonlite package to be installed.
Note
Custom diagnostic results (the custom field, populated via .fns
in audit_tap()) are serialised on a best-effort basis for JSON output.
Complex R objects such as environments or functions cannot be represented
in JSON and will cause an error.
See also
Other audit export:
audit_export(),
read_trail(),
trail_to_df(),
trail_to_list()
Examples
trail <- audit_trail("example")
mtcars |> audit_tap(trail, "raw")
tmp <- tempfile(fileext = ".rds")
write_trail(trail, tmp)
restored <- read_trail(tmp)