alexpghayes / distributions3

Probability Distributions as S3 Objects
https://alexpghayes.github.io/distributions3/
Other
100 stars 16 forks source link

Drop "distribution" in print() output? #101

Closed zeileis closed 7 months ago

zeileis commented 7 months ago

Alex @alexpghayes, when printing distribution objects, the output takes up quite a bit of space (especially for vectors of distributions). Even for a 1-parameter distribution like this:

p <- Poisson(log(2:6))
p
## [1] "Poisson distribution (lambda = 0.6931)"
## [2] "Poisson distribution (lambda = 1.0986)"
## [3] "Poisson distribution (lambda = 1.3863)"
## [4] "Poisson distribution (lambda = 1.6094)"
## [5] "Poisson distribution (lambda = 1.7918)"

This could be alleviated if we omitted the distribution in the output like this:

p
## [1] "Poisson(lambda = 0.6931)" "Poisson(lambda = 1.0986)"
## [3] "Poisson(lambda = 1.3863)" "Poisson(lambda = 1.6094)"
## [5] "Poisson(lambda = 1.7918)"

My feeling is that this easier to read and also closer to the notation used in many textbooks. It's also closer to how we create the objects in distributions3, e.g., we might do:

X = Poisson(lambda = 1.3)
X
## [1] "Poisson(lambda = 1.3)"

Would you consider simplifying the print() output like this? If so, I'm happy to make the change myself, but I wanted to discuss it first before proposing a PR. In any case, the code change is quite minimal, essentially just here: https://github.com/alexpghayes/distributions3/blob/main/R/utils.R#L288

alexpghayes commented 7 months ago

Sounds good to me! I don't have the capacity to make this change myself but I fully support it.

zeileis commented 7 months ago

OK, great. This just needs two mini changes in the format() methods (plus updating the tests accordingly). It's in the devel branch now: https://github.com/alexpghayes/distributions3/pull/100/commits/625801897214a67d89672a6e40f943dec84d8f17

zeileis commented 7 months ago

Now merged into main.