mitchelloharawild / distributional

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

hilo error when sampling distribution has missing values #13

Closed robjhyndman closed 4 years ago

robjhyndman commented 4 years ago
library(distributional)
library(magrittr)
dist_sample(list(c(NA,rnorm(20)))) %>% hilo()
#> Error in quantile.default(X[[i]], ...): missing values and NaN's not allowed if 'na.rm' is FALSE

Created on 2020-04-10 by the reprex package (v0.3.0)

I think it would be reasonable to generate a warning here rather than an error, and pass na.rm=TRUE to quantile().

mitchelloharawild commented 4 years ago

Is there any value to having NA values in dist_sample()? Perhaps the warning should occur on object creation.

robjhyndman commented 4 years ago

Yes, that would be an alternative (or warn in both functions). There is no value in having NAs, but sometimes they might be generated. For example, if the distribution is a set of percentiles, then it is possible that some NAs will be generated due to the percentiles not covering the full range (0,100).

mitchelloharawild commented 4 years ago

Fixed, thanks.