Skip to content

Commit

Permalink
The function save_plot() gains the new argument view_plot to cont…
Browse files Browse the repository at this point in the history
…rol whether to view the plot on screen after saving (#40).
  • Loading branch information
jbengler committed Jan 4, 2025
1 parent eb881a6 commit 129c515
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# tidyplots (development version)

* New color scheme `colors_discrete_rainbow` (@electrolars, #35).
* The function `save_plot()` gains the new argument `view_plot`
to control whether to view the plot on screen after saving (#40).

# tidyplots 0.2.0

Expand Down
5 changes: 3 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ view_plot <- function(plot, data = all_rows(), title = ggplot2::waiver(), ...) {
#' incoming `plot` object (see Details).
#' @param units Units of length. Defaults to `"mm"`.
#' @param multiple_files Whether to save multiple pages as individual files.
#' @param view_plot Whether to view the plot on screen after saving.
#' @inheritParams ggplot2::ggsave
#' @inherit common_arguments
#'
Expand Down Expand Up @@ -270,7 +271,7 @@ view_plot <- function(plot, data = all_rows(), title = ggplot2::waiver(), ...) {
#' @export
save_plot <- function(plot = ggplot2::last_plot(), filename,
width = NA, height = NA, units = c("mm", "cm", "in"),
multiple_files = FALSE, bg = "transparent", ...) {
multiple_files = FALSE, view_plot = TRUE, bg = "transparent", ...) {
if (!ggplot2::is.ggplot(plot) && !all(purrr::map_lgl(plot, ggplot2::is.ggplot)))
cli::cli_abort("{.arg plot} must be a single plot or a list of plots.")

Expand Down Expand Up @@ -318,6 +319,6 @@ save_plot <- function(plot = ggplot2::last_plot(), filename,
cli::cli_alert_success("save_plot: saved multiple plots to {.file {filenames}}")
}
}
print(input)
if (view_plot) print(input)
invisible(input)
}
3 changes: 3 additions & 0 deletions man/save_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 129c515

Please sign in to comment.