Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# sgplot (development version)

* Add `quietly` argument to `use_sgplot()` to allow messages to be suppressed
(#67).

* Set minimum version of ggplot (>= 3.5.0) (#62).

* Fix bug where `use_sgplot()` could not handle passing multiple arguments of
Expand Down
20 changes: 15 additions & 5 deletions R/use_sgplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#'
#' @param palette_type Name of palette type to use. Defaults to "sg". For all
#' available palette types, run `available_palette_types()`.
#' @param quietly Should the function run quietly? By default, `use_sgplot()`
#' prints information messages to the console. Set `quietly = TRUE` to suppress
#' these.
#' @param ... Arguments passed to \code{sgplot::theme_sg()}.
#' @param default_colour `r lifecycle::badge("deprecated")` Use the
#' `palette_type` argument instead.
Expand Down Expand Up @@ -35,6 +38,7 @@


use_sgplot <- function(palette_type = "sg",
quietly = FALSE,
...,
default_colour = deprecated()) {

Expand All @@ -56,8 +60,9 @@ use_sgplot <- function(palette_type = "sg",

ggplot2::theme_set(theme_sg(...))

cli::cli_alert_info("Default ggplot2 theme set to `theme_sg`.")

if (!quietly) {
cli::cli_alert_info("Default ggplot2 theme set to `theme_sg`.")
}

# Use sgplot colour palette ----

Expand All @@ -76,8 +81,11 @@ use_sgplot <- function(palette_type = "sg",
}
)

cli::cli_alert_info("Default colours set to {.str {palette_type}} palettes.")

if (!quietly) {
cli::cli_alert_info(
"Default colours set to {.str {palette_type}} palettes."
)
}

# Set default geom characteristics ----

Expand Down Expand Up @@ -148,6 +156,8 @@ use_sgplot <- function(palette_type = "sg",
size = base_size / 8)
)

cli::cli_alert_info("Default geom aesthetics set.")
if (!quietly) {
cli::cli_alert_info("Default geom aesthetics set.")
}

}
11 changes: 10 additions & 1 deletion man/use_sgplot.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/test-use_sgplot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("`quietly` argument works", {
expect_message(use_sgplot())
expect_no_message(use_sgplot(quietly = TRUE))
})
Loading