diff --git a/utils.R b/utils.R new file mode 100644 index 0000000..36f7c42 --- /dev/null +++ b/utils.R @@ -0,0 +1,28 @@ +# secMalASCT utilities +# +# License: GPL version 3 +# Jens Mathis Sauer (c) 2020 + +# +# Write plot to filename +# +# This will plot "fun" with arguments "..." as filetype "ftype" and +# the output to "filename". Title and legends can be passed as list, +# or NULL if not needed. +# Default filesize is 3000x3000 px and 300 dpi resolution. +# +sma_plot_file <- function(fname, ftype, title_list, legend_list, fun, ...) { + # Open file for writing + ftype(filename = fname, width = 3000, height = 3000, res = 300) + + # run "fun" with passed arguments + do.call(fun, list(...)) + + if (!is.null(title_list)) { + do.call(title, title_list) + } + if(!is.null(legend_list)) { + do.call(legend, legend_list) + } + dev.off() +}