Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added as.character() and duplicated() methods #106

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

S3method("[",distribution)
S3method("names<-",distribution)
S3method(as.character,distribution)
S3method(as.data.frame,distribution)
S3method(as.list,distribution)
S3method(as.matrix,distribution)
Expand Down Expand Up @@ -41,6 +42,7 @@ S3method(cdf,ZTNegativeBinomial)
S3method(cdf,ZTPoisson)
S3method(dim,distribution)
S3method(dimnames,distribution)
S3method(duplicated,distribution)
S3method(fit_mle,Bernoulli)
S3method(fit_mle,Binomial)
S3method(fit_mle,Exponential)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
simplified. For example, now `Normal(mu = 0, sigma = 1)` is used instead of
`Normal distribution (mu = 0, sigma = 1)` in order to yield a more compact output, especially
for vectors of distributions (#101).
- Added an `as.character()` method which essentially calls `format(..., digits = 15, drop0trailing = TRUE)`.
This mimics the behavior and precision of base R for real vectors. Note that this enables
using `match()` for distribution objects.
- Added a `duplicated()` method which relies on the corresponding method for the `data.frame`
of parameters in a distribution.
- Fixed errors in notation of cumulative distribution function in the documentation of
`HurdlePoisson()` and `HurdleNegativeBinomial()` (by @dkwhu in #94 and #96).
- The `prodist()` method for `glm` objects can now also handle `family` specifications from
`MASS::negative.binomial(theta)` with fixed `theta` (reported by Christian Kleiber).
- Replace `ellipsis` dependency by `rlang` as the former will be
[deprecated/archived](https://rlang.r-lib.org/news/index.html#argument-intake-1-0-0)
(by @olivroy in #105).
- Further small improvements in methods and manual pages.


Expand Down
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ format.distribution <- function(x, digits = pmax(3L, getOption("digits") - 3L),
setNames(f, n)
}

#' @export
as.character.distribution <- function(x, digits = 15L, drop0trailing = TRUE, ...) {
y <- format(x, digits = digits, drop0trailing = drop0trailing, ...)
if (!is.null(names(y))) names(y) <- NULL
return(y)
}

#' @export
duplicated.distribution <- function(x, incomparables = FALSE, ...) {
class(x) <- "data.frame"
duplicated(x, incomparables = incomparables, ...)
}

#' @export
print.distribution <- function(x, digits = pmax(3L, getOption("digits") - 3L), ...) {
if (length(x) < 1L) {
Expand Down
Loading