R/saveCanonicalPlots.R

#' @title saveCanonicalPlots
#'
#' @description Save plots as generated by \link[IPAPlots]{plotCanonicalPathways} to pngs.
#'
#' @param plot_list List of plots generated by \link[IPAPlots]{plotCanonicalPathways}
#' @param output_dir Directory to save the plots in
#' @param width Width of the saved plots.  Default: 8.
#' @param height Height of the saved plots.  Default: 8.
#' @param units Units used for the width and height.  Default: "in"
#' @param ... Additional parameters to pass to ggsave
#'
#' @importFrom ggplot2 ggsave
#' @importFrom stringr str_replace str_glue
#'
#' @return
#' @export
#'
#' @examples
saveCanonicalPlots <- function(plot_list,
                               output_dir = "~/",
                               width = 8,
                               height = 8,
                               units = "in",
                               ...){
  for(i in seq(plot_list)){
    if (!is.null(plot_list[[i]])){
      ggsave(filename = str_replace(string = as.character(str_glue("{names(plot_list)[[i]]}.png")),
                                    pattern = " ",
                                    replacement = "_"),
             plot = plot_list[[i]],
             path = output_dir,
             width = width,
             height = height,
             units = units,
             ...)
    }
  }
}
milescsmith/IPAPlots documentation built on May 28, 2019, 1:21 p.m.