mitchelloharawild / distributional

Vectorised distributions for R
https://pkg.mitchelloharawild.com/distributional
GNU General Public License v3.0
94 stars 15 forks source link

fix density(<dist_categorical>, x) for x <= 0 #87

Closed mjskay closed 1 year ago

mjskay commented 1 year ago

Another minor bugfix on categorical dists. Probably not worthy of a news item (but I can write one if you'd like).

Basically, there's some weird behavior in density.dist_categorical() due to R's indexing rules when i <= 0:

> density(dist_categorical(list(1:3)), -1)
[1] 0.3333333 0.5000000
> density(dist_categorical(list(1:3)), 0)
numeric(0)

With the fix:

> density(dist_categorical(list(1:3)), -1)
[1] NA
> density(dist_categorical(list(1:3)), 0)
[1] NA
mitchelloharawild commented 1 year ago

Great, thanks! I'll summarise the NEWS as bug fixes with links to the PR when I prepare a release.

mjskay commented 1 year ago

Cool thanks!