Skip to content

Commit db6feb8

Browse files
committed
inline single_value()
1 parent 6ac62cf commit db6feb8

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ S3method(scale_type,logical)
124124
S3method(scale_type,numeric)
125125
S3method(scale_type,ordered)
126126
S3method(scale_type,sfc)
127-
S3method(single_value,default)
128-
S3method(single_value,factor)
129127
S3method(summary,ggplot)
130128
S3method(vec_cast,character.mapped_discrete)
131129
S3method(vec_cast,double.mapped_discrete)

R/compat-plyr.R

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ dapply <- function(df, by, fun, ..., drop = TRUE) {
209209
}
210210

211211
# Shortcut when only one group
212-
if (all(vapply(grouping_cols, single_value, logical(1)))) {
212+
has_single_group <- all(vapply(
213+
grouping_cols,
214+
function(x) identical(as.character(levels(x) %||% attr(x, "n")), "1"),
215+
logical(1)
216+
))
217+
if (has_single_group) {
213218
return(apply_fun(df))
214219
}
215220

@@ -221,17 +226,3 @@ dapply <- function(df, by, fun, ..., drop = TRUE) {
221226
})
222227
vec_rbind0(!!!result)
223228
}
224-
225-
single_value <- function(x, ...) {
226-
UseMethod("single_value")
227-
}
228-
#' @export
229-
single_value.default <- function(x, ...) {
230-
# This is set by id() used in creating the grouping var
231-
identical(attr(x, "n"), 1L)
232-
}
233-
#' @export
234-
single_value.factor <- function(x, ...) {
235-
# Panels are encoded as factor numbers and can never be missing (NA)
236-
identical(levels(x), "1")
237-
}

0 commit comments

Comments
 (0)