Open venpopov opened 8 months ago
The documentation should definitely be improved to explain how the distributions and arguments are vectorised. Essentially the operation's argument (e.g. density(at=)
) is vectorised across the distributions and the result is simplified if possible. While I agree that returning lists with one element is more consistent, it would be less efficient and less usable - it could be a non-default option, like drop = FALSE
.
The nature of vectorisation in distributional is discussed here: https://github.com/mitchelloharawild/distributional/issues/52
This specific behaviour was considered here: https://github.com/mitchelloharawild/distributional/issues/52#issuecomment-939694518
The issue with simplify2array()
is that the vectorisation needs to work with multivariate distributions which already produces arrays.
While doing some testing I noticed that density, cdf and quantile sometimes return vectors, sometimes lists:
Created on 2024-04-01 with reprex v2.1.0
And the expected output type is not documented for these functions. I think it would be good to have consistent output type. For example, I was surprised that
density(dist_norma(), 0)
returns a scalar, but thatdensity(dist_normal(), c(0,1))
returns a list, while with two distributions and single point we get a vector.One possibility is to always return a list, where each element corresponds to one distribution, like it is now for some of the outputs. Although I believe this would be desirable, it is a breaking change that might affect other packages. In any case, the return value type should be documented.
Additionally, it could also be nice to have an option simplify2array as an argument.