with_watermark
with_watermark.RdRun `fun(tmp_path)` and apply a watermark to the resulting file via the `dso watermark` CLI.
This mirrors the Python `dso.WatermarkedFile` context manager: `fun` receives a path to write to, and once it returns, the file is watermarked and moved to `output_file`. If no watermark configuration is available (and no `...` overrides are given), `fun` is called with `output_file` directly without any temp file or CLI invocation.
Supports SVG, PDF and all pixel formats supported by `dso watermark`.
Examples
if (FALSE) { # \dontrun{
# Base graphics
with_watermark("myplot.png", function(f) {
png(f)
plot(1:10)
dev.off()
})
# ggplot2
p <- ggplot2::ggplot(data.frame(x = 1:10), ggplot2::aes(x, x)) +
ggplot2::geom_point()
with_watermark("myplot.pdf", function(f) ggplot2::ggsave(f, p))
# Override watermark text
with_watermark("myplot.svg", function(f) {
svg(f)
plot(1:10)
dev.off()
}, text = "CONFIDENTIAL")
} # }