Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions R/facet-.R
Original file line number Diff line number Diff line change
Expand Up @@ -1415,14 +1415,14 @@ censor_labels <- function(ranges, layout, labels) {
)

if (!labels$x) {
xmax <- stats::ave(layout$ROW, layout$COL, FUN = max)
xmin <- stats::ave(layout$ROW, layout$COL, FUN = min)
xmax <- vec_ave(layout$ROW, layout$COL, max)
xmin <- vec_ave(layout$ROW, layout$COL, min)
draw[which(layout$ROW != xmax), "bottom"] <- FALSE
draw[which(layout$ROW != xmin), "top"] <- FALSE
}
if (!labels$y) {
ymax <- stats::ave(layout$COL, layout$ROW, FUN = max)
ymin <- stats::ave(layout$COL, layout$ROW, FUN = min)
ymax <- vec_ave(layout$COL, layout$ROW, max)
ymin <- vec_ave(layout$COL, layout$ROW, min)
draw[which(layout$COL != ymax), "right"] <- FALSE
draw[which(layout$COL != ymin), "left"] <- FALSE
}
Expand Down
4 changes: 2 additions & 2 deletions R/geom-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GeomPath <- ggproto("GeomPath", Geom,
# middle since you expect those to be shown by a break in the line
aesthetics <- c(self$required_aes, self$non_missing_aes)
complete <- stats::complete.cases(data[names(data) %in% aesthetics])
kept <- stats::ave(complete, data$group, FUN = keep_mid_true)
kept <- vec_ave(complete, data$group, keep_mid_true)
data <- data[kept, ]

if (!all(kept) && !params$na.rm) {
Expand Down Expand Up @@ -48,7 +48,7 @@ GeomPath <- ggproto("GeomPath", Geom,
munched <- coord_munch(coord, data, panel_params)

# Silently drop lines with less than two points, preserving order
rows <- stats::ave(seq_len(nrow(munched)), munched$group, FUN = length)
rows <- vec_ave(seq_len(nrow(munched)), munched$group, length)
munched <- munched[rows >= 2, ]
if (nrow(munched) < 2) return(zeroGrob())

Expand Down
2 changes: 1 addition & 1 deletion R/stat-sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ StatSum <- ggproto(

counts <- count(data, group_by, wt_var = "weight")
counts <- rename(counts, c(freq = "n"))
counts$prop <- stats::ave(counts$n, counts$group, FUN = prop.table)
counts$prop <- vec_ave(counts$n, counts$group, prop.table)
counts
}
)
Expand Down
13 changes: 12 additions & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ compute_data_size <- function(data, size, default = 0.9,
res <- vapply(res, resolution, FUN.VALUE = numeric(1), ...)
res <- min(res, na.rm = TRUE)
} else if (panels == "by") {
res <- stats::ave(data[[var]], data$PANEL, FUN = function(x) resolution(x, ...))
res <- vec_ave(data[[var]], data$PANEL, function(x) resolution(x, ...))
} else {
res <- resolution(data[[var]], ...)
}
Expand All @@ -927,3 +927,14 @@ try_prop <- function(object, name, default = NULL) {
}
S7::prop(object, name)
}

vec_ave <- function(x, by, fn, ...) {
idx <- vec_group_loc(by)$loc
list_unchop(
lapply(
vec_chop(x, indices = idx),
FUN = fn, ...
),
indices = idx
)
}