Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion R/stat-summary-2d.r
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ StatSummary2d <- ggproto("StatSummary2d", Stat,
xbin <- cut(data$x, xbreaks, include.lowest = TRUE, labels = FALSE)
ybin <- cut(data$y, ybreaks, include.lowest = TRUE, labels = FALSE)

if (is.formula(fun)) fun <- rlang::as_function(fun)
if (is.formula(fun)) fun <- as_function(fun)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just remove the is.formula check and call as_function() unconditionally... same with the other two places

f <- function(x) {
do.call(fun, c(list(quote(x)), fun.args))
}
Expand Down
8 changes: 2 additions & 6 deletions R/stat-summary-bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ make_summary_fun <- function(fun.data, fun, fun.max, fun.min, fun.args) {

if (!is.null(fun.data)) {
# Function that takes complete data frame as input
if (is.formula(fun.data)) {
fun.data <- rlang::as_function(fun.data)
} else {
fun.data <- match.fun(fun.data)
}
fun.data <- as_function(fun.data)
function(df) {
do.call(fun.data, c(list(quote(df$y)), fun.args))
}
Expand All @@ -109,7 +105,7 @@ make_summary_fun <- function(fun.data, fun, fun.max, fun.min, fun.args) {

call_f <- function(fun, x) {
if (is.null(fun)) return(NA_real_)
if (is.formula(fun)) fun <- rlang::as_function(fun)
if (is.formula(fun)) fun <- as_function(fun)
do.call(fun, c(list(quote(x)), fun.args))
}

Expand Down
2 changes: 1 addition & 1 deletion R/stat-summary-hex.r
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ StatSummaryHex <- ggproto("StatSummaryHex", Stat,
try_require("hexbin", "stat_summary_hex")

binwidth <- binwidth %||% hex_binwidth(bins, scales)
if (is.formula(fun)) fun <- rlang::as_function(fun)
if (is.formula(fun)) fun <- as_function(fun)
hexBinSummarise(data$x, data$y, data$z, binwidth,
fun = fun, fun.args = fun.args, drop = drop)
}
Expand Down