Skip to content

Commit 5935bb3

Browse files
committed
throw informative error
1 parent 1800a9a commit 5935bb3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

R/stat-density-2d.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
182182
h <- c(MASS::bandwidth.nrd(data$x), MASS::bandwidth.nrd(data$y))
183183
h <- h * adjust
184184
}
185+
if (any(is.na(h) | h <= 0)) {
186+
cli::cli_abort(c(
187+
"The bandwidth argument {.arg h} must contain numbers larger than 0.",
188+
i = "Please set the {.arg h} argument to stricly positive numbers manually."
189+
))
190+
}
185191

186192
# calculate density
187193
dens <- MASS::kde2d(

0 commit comments

Comments
 (0)