Skip to content

Commit

Permalink
scale_x/y_facet use quosures
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Apr 6, 2023
1 parent b4c8efd commit d302dfb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggh4x (development version)

* `scale_{x/y}_facet()` now use quosures instead of expressions (#101)

# ggh4x 0.2.4

This is a small release for compatibility with ggplot2 3.4.2, along with some
Expand Down
6 changes: 3 additions & 3 deletions R/scale_facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ scale_facet <- function(expr, aes, ..., type = "continuous") {
))
}

if (!rlang::is_expression(expr)) {
if (!rlang::is_quosure(expr) || quo_is_missing(expr)) {
cli::cli_abort("{.arg expr} must be a valid {.cls expression}.")
}

Expand All @@ -118,13 +118,13 @@ scale_facet <- function(expr, aes, ..., type = "continuous") {
#' @export
#' @rdname scale_facet
scale_x_facet <- function(expr, ..., type = "continuous") {
scale_facet(expr = enexpr(expr), "x", ..., type = type)
scale_facet(expr = enquo(expr), "x", ..., type = type)
}

#' @export
#' @rdname scale_facet
scale_y_facet <- function(expr, ..., type = "continuous") {
scale_facet(expr = enexpr(expr), "y", ..., type = type)
scale_facet(expr = enquo(expr), "y", ..., type = type)
}

#' @export
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-scale_facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test_that("scale_(x/y)_facet can be added to a plot", {
expect_length(p$facet$new_y_scales, 1L)
expect_identical(
attr(p$facet$new_y_scales, "lhs")[[1]],
rlang::expr(COL == 2)
rlang::quo(COL == 2)
)

p <- p + scale_y_facet(COL == 1, breaks = 1:40)
Expand All @@ -54,7 +54,7 @@ test_that("scale_(x/y)_facet can be added to a plot", {
expect_length(attr(p$facet$new_y_scales, "lhs"), 2L)
expect_identical(
attr(p$facet$new_y_scales, "lhs")[[2]],
rlang::expr(COL == 1)
rlang::quo(COL == 1)
)

p <- p + scale_x_facet(PANEL == 3, limits = c(0, 500))
Expand Down

0 comments on commit d302dfb

Please sign in to comment.