Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yjunechoe committed Oct 10, 2024
1 parent fd3f596 commit 2c96752
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/sublayer-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ sublayer_data <- function(x, cond = 1L,

step <- .sublayer_stages[[match.arg(step)]]

ns_ggplot2 <- if (!"package:ggplot2" %in% search()) "ggplot2"
ns_ggtrace <- if (!"package:ggtrace" %in% search()) "ggtrace"
ns_ggplot2 <- resolve_ns("ggplot2")
ns_ggtrace <- resolve_ns("ggtrace")

if (rlang::is_missing(x)) {
x_expr <- rlang::call2("last_plot", .ns = ns_ggplot2)
Expand Down Expand Up @@ -170,7 +170,7 @@ layer_after_scale <- function(plot, i = 1L, ..., error = FALSE,
#' @export
layer_is <- function(expr) {
x <- rlang::enexpr(expr)
rlang::call2(".layer_is", x, .ns = if (!"package:ggtrace" %in% search()) "ggtrace")
rlang::call2(".layer_is", x, .ns = resolve_ns("ggtrace"))
}

#' @rdname sublayer-data
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ resolve_formatting <- function(method, remove_trace = FALSE) {
return(result)
}
}

resolve_ns <- function(x) {
if (!paste0("package:", x) %in% search()) x
}

0 comments on commit 2c96752

Please sign in to comment.