Skip to contents

Looks up input by the name it was called with (via deparse(substitute())) and only calls ggplot2::ggsave() if an object of that name exists in the calling environment — this lets report chunks unconditionally call ggsave_rawr(p_some_plot, "some_plot", folder = FolderFigures) even when p_some_plot was conditionally skipped upstream (e.g. no non-NA correlation to plot), without erroring.

Usage

ggsave_rawr(input, file, folder, width = 8, height = 10)

Arguments

input

The plot object to save. When it is a bare variable name, that name is used to check existence rather than the value.

file

Output file name, without extension; saved as <file>.png under folder.

folder

Destination directory for the png.

width, height

Figure dimensions in cm, passed to ggplot2::ggsave().

Value

Invisible NULL; called for its side effect of writing a png (or warning that it was skipped).

Details

Reconciles two near-duplicate report-inline variants (one hardcoding "4_figures", the other a width = n_conditions + 5 default and a chunk-local FolderFigures) into a single canonical version that takes folder/width/height as ordinary explicit arguments — callers compute and pass whatever values their report context needs.

A bare symbol is looked up by name in the calling environment; any other expression (plots[[nm]], a computed plot) is evaluated and judged by its value, so the idiomatic for (nm in names(plots)) ggsave_rawr(plots[[nm]], file = nm, ...) export loop works as well.

Examples

if (FALSE) { # \dontrun{
ggsave_rawr(p_peplength_all, "peplength_all", folder = FolderFigures)
} # }