Skip to content

Commit

Permalink
trace_position tidy eval
Browse files Browse the repository at this point in the history
  • Loading branch information
sheridar committed Nov 20, 2023
1 parent c49c567 commit 6817157
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ VignetteBuilder:
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
SystemRequirements: pandoc
Collate:
'a-legend-draw.R'
Expand Down
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,3 @@ export(geom_line_trace)
export(geom_path_trace)
export(geom_point_trace)
export(geom_step_trace)
import(ggplot2)
importFrom(grid,gpar)
importFrom(grid,grobName)
importFrom(grid,grobTree)
importFrom(grid,pointsGrob)
importFrom(rlang,on_load)
13 changes: 7 additions & 6 deletions R/geom-point-trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ geom_point_trace <- function(mapping = NULL, data = NULL, stat = "identity",

trans_fn <- function(dat, ex, inv = FALSE) {
if (inv) {
return(subset(dat, !eval(ex)))
return(subset(dat, !rlang::eval_tidy(ex, dat)))
}

subset(dat, eval(ex))
subset(dat, rlang::eval_tidy(ex, dat))
}

create_trace_layers(
Expand All @@ -81,7 +81,7 @@ geom_point_trace <- function(mapping = NULL, data = NULL, stat = "identity",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...),
trace_position = substitute(trace_position),
trace_position = rlang::enquo(trace_position),
background_params = background_params,
trans_fn = trans_fn,
allow_bottom = TRUE
Expand Down Expand Up @@ -117,7 +117,8 @@ create_trace_layers <- function(mapping, data, stat, geom, position,

# If trace_position is 'bottom', create new column and use to override
# original group specification.
if (allow_bottom && trace_expr == "bottom") {
if (allow_bottom && identical(rlang::as_label(trace_expr), "\"bottom\"")) {

data <- ggplot2::fortify(~ transform(.x, BOTTOM_TRACE_GROUP = "bottom"))

if (is.null(mapping)) {
Expand All @@ -126,8 +127,8 @@ create_trace_layers <- function(mapping, data, stat, geom, position,

mapping$group <- as.name("BOTTOM_TRACE_GROUP")

# If trace_position is not 'all', evaluate expression
} else if (trace_expr != "all") {
# If trace_position is not 'all', evaluate expression
} else if (!identical(rlang::as_label(trace_expr), "\"all\"")) {
# If data is not NULL, the user has passed a data.frame, function, or
# formula to the geom. Need to fortify this before applying the predicate
# passed through trace_position. For a formula fortify will return an
Expand Down
7 changes: 0 additions & 7 deletions R/ggtrace-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,5 @@
#'
#' @name ggtrace
#' @docType package
#' @import ggplot2
#' @importFrom grid
#' gpar
#' pointsGrob
#' grobName
#' grobTree
#' @importFrom rlang on_load
#' @keywords internal
"_PACKAGE"
1 change: 0 additions & 1 deletion R/utilities-ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ modify_list <- function(old, new) {
# Info needed for rbind_dfs date/time handling
ggtrace_global <- new.env(parent = emptyenv())

#' @importFrom rlang on_load
#' @noRd
rlang::on_load({
date <- Sys.Date()
Expand Down
20 changes: 12 additions & 8 deletions man/geom_path_trace.Rd

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

20 changes: 12 additions & 8 deletions man/geom_point_trace.Rd

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

0 comments on commit 6817157

Please sign in to comment.