Skip to content

Commit fd17f08

Browse files
committed
protect against $n partial matches
1 parent b91fe31 commit fd17f08

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

R/stat-density-2d.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
197197
df$group <- data$group[1]
198198
df$ndensity <- df$density / max(df$density, na.rm = TRUE)
199199
df$count <- nx * df$density
200-
df$n <- nx
200+
df[["n"]] <- nx
201201
df$level <- 1
202202
df$piece <- 1
203203
df

R/stat-ydensity.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
170170
trim = trim, na.rm = na.rm, drop = drop, bounds = bounds,
171171
quantiles = quantiles
172172
)
173-
if (!drop && any(data$n < 2)) {
173+
if (!drop && any(data[["n"]] < 2)) {
174174
cli::cli_warn(
175175
"Cannot compute density for groups with fewer than two datapoints."
176176
)
@@ -184,7 +184,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
184184
# count: use the original densities scaled to a maximum of 1 (as above)
185185
# and then scale them according to the number of observations
186186
count = data$density / max(data$density, na.rm = TRUE) *
187-
data$n / max(data$n),
187+
data[["n"]] / max(data[["n"]]),
188188
# width: constant width (density scaled to a maximum of 1)
189189
width = data$scaled
190190
)

0 commit comments

Comments
 (0)