Skip to content

Commit

Permalink
format() method and hence print() simplified without ...distribution.…
Browse files Browse the repository at this point in the history
….. e.g. Normal(mu = 0, sigma = 1)
  • Loading branch information
zeileis committed Apr 29, 2024
1 parent 259ab77 commit 6258018
Show file tree
Hide file tree
Showing 36 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion R/PoissonBinomial.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ format.PoissonBinomial <- function(x, digits = pmax(3L, getOption("digits") - 3L
} else {
dots <- NULL
}
f <- sprintf("%s distribution (%s)", cl, apply(
f <- sprintf("%s(%s)", cl, apply(
rbind(apply(as.matrix(x), 2L, format, digits = digits, ...)), 1L, function(p)
paste(c(paste(names(x), "=", as.vector(p)), dots), collapse = ", ")))
setNames(f, n)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ format.distribution <- function(x, digits = pmax(3L, getOption("digits") - 3L),
n <- names(x)
if (is.null(attr(x, "row.names"))) attr(x, "row.names") <- 1L:length(x)
class(x) <- "data.frame"
f <- sprintf("%s distribution (%s)", cl, apply(rbind(apply(as.matrix(x), 2L, format, digits = digits, ...)), 1L, function(p) paste(names(x), "=", as.vector(p), collapse = ", ")))
f <- sprintf("%s(%s)", cl, apply(rbind(apply(as.matrix(x), 2L, format, digits = digits, ...)), 1L, function(p) paste(names(x), "=", as.vector(p), collapse = ", ")))
setNames(f, n)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Bernoulli.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Bernoulli")

test_that("print.Bernoulli works", {
expect_output(print(Bernoulli()), regexp = "Bernoulli distribution")
expect_output(print(Bernoulli()), regexp = "Bernoulli")
})

test_that("fit_mle.Bernoulli works correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Beta.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Beta")

test_that("print.Beta works", {
expect_output(print(Beta()), regexp = "Beta distribution")
expect_output(print(Beta()), regexp = "Beta")
})

test_that("random.Beta work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Binomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Binomial")

test_that("print.Binomial works", {
expect_output(print(Binomial(1)), regexp = "Binomial distribution")
expect_output(print(Binomial(1)), regexp = "Binomial")
})

test_that("fit_mle.Binomial works correctly", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-Categorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ test_that("print.Categorical", {
X <- Categorical(1:6)
Y <- Categorical(LETTERS[1:3], p = c(0.1, 0.2, 0.7))

expect_output(print(X), regexp = "Categorical distribution")
expect_output(print(Y), regexp = "Categorical distribution")
expect_output(print(X), regexp = "Categorical")
expect_output(print(Y), regexp = "Categorical")
})

test_that("random.Categorical", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Cauchy.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Cauchy")

test_that("print.Cauchy works", {
expect_output(print(Cauchy(1, 1)), regexp = "Cauchy distribution")
expect_output(print(Cauchy(1, 1)), regexp = "Cauchy")
})

test_that("likelihood.Cauchy and log_likelihood.Cauchy work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ChiSquare.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("print.ChiSquare works", {
expect_output(print(ChiSquare(df = 1)), regexp = "ChiSquare distribution")
expect_output(print(ChiSquare(df = 1)), regexp = "ChiSquare")
})

test_that("random.ChiSquare work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Erlang.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("Erlang constructor works", {
})

test_that("print.Erlang works", {
expect_output(print(e), regexp = "Erlang distribution")
expect_output(print(e), regexp = "Erlang")
})

test_that("random.Erlang works correctly", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-Exponential.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ test_that("fit_mle.Exponential works correctly", {
expect_true(is.numeric(fit_mle(Exponential(), rexp(100))$rate))
})

test_that("print.Beta works", {
expect_output(print(Exponential()), regexp = "Exponential distribution")
test_that("print.Exponential works", {
expect_output(print(Exponential()), regexp = "Exponential")
})

test_that("random.Exponential work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-FisherF.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-FisherF")

test_that("print.FisherF works", {
expect_output(print(FisherF(1, 1)), regexp = "FisherF distribution")
expect_output(print(FisherF(1, 1)), regexp = "FisherF")
})

test_that("likelihood.FisherF and log_likelihood.FisherF work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Frechet.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Frechet")

test_that("print.Frechet works", {
expect_output(print(Frechet()), regexp = "Frechet distribution")
expect_output(print(Frechet()), regexp = "Frechet")
})

## Example distributions
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Gamma.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Gamma")

test_that("print.Gamma works", {
expect_output(print(Gamma(1, 1)), regexp = "Gamma distribution")
expect_output(print(Gamma(1, 1)), regexp = "Gamma")
})

test_that("likelihood.Gamma and log_likelihood.Gamma work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-GeneralisedExtremeValue.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-GEV")

test_that("print.GEV works", {
expect_output(print(GEV()), regexp = "GEV distribution")
expect_output(print(GEV()), regexp = "GEV")
})

## Example distributions
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-GeneralisedPareto.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-GP")

test_that("print.GP works", {
expect_output(print(GP()), regexp = "GP distribution")
expect_output(print(GP()), regexp = "GP")
})

## Example distributions
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Geometric.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Geometric")

test_that("print.Geometric works", {
expect_output(print(Geometric()), regexp = "Geometric distribution")
expect_output(print(Geometric()), regexp = "Geometric")
})

test_that("likelihood.Geometric and log_likelihood.Geometric work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Gumbel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Gumbel")

test_that("print.Gumbel works", {
expect_output(print(Gumbel()), regexp = "Gumbel distribution")
expect_output(print(Gumbel()), regexp = "Gumbel")
})

## Example distribution (from test-GeneralisedExtremeValue.R)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-HurdleNegativeBinomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-HurdleNegativeBinomial")

test_that("print.HurdleNegativeBinomial works", {
expect_output(print(HurdleNegativeBinomial(1, 1, 0.7)), regexp = "HurdleNegativeBinomial distribution")
expect_output(print(HurdleNegativeBinomial(1, 1, 0.7)), regexp = "HurdleNegativeBinomial")
})

test_that("random.HurdleNegativeBinomial work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-HurdlePoisson.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-HurdlePoisson")

test_that("print.HurdlePoisson works", {
expect_output(print(HurdlePoisson(1, 0.7)), regexp = "HurdlePoisson distribution")
expect_output(print(HurdlePoisson(1, 0.7)), regexp = "HurdlePoisson")
})

test_that("random.HurdlePoisson work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-HyperGeometric.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test_that("HyperGeometric works as intended when k > n + m", {
})

test_that("print.HyperGeometric works", {
expect_output(print(HyperGeometric(1, 1, 1)), regexp = "HyperGeometric distribution")
expect_output(print(HyperGeometric(1, 1, 1)), regexp = "HyperGeometric")
})


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-LogNormal.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-LogNormal")

test_that("print.LogNormal works", {
expect_output(print(LogNormal()), regexp = "LogNormal distribution")
expect_output(print(LogNormal()), regexp = "LogNormal")
})

test_that("likelihood.LogNormal and log_likelihood.LogNormal work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Logistic.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Logistic")

test_that("print.Logistic works", {
expect_output(print(Logistic(1, 1)), regexp = "Logistic distribution")
expect_output(print(Logistic(1, 1)), regexp = "Logistic")
})

test_that("likelihood.Logistic and log_likelihood.Logistic work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Multinomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Multinomial")

test_that("print.Multinomial works", {
expect_output(print(Multinomial(1, 0.5)), regexp = "Multinomial distribution")
expect_output(print(Multinomial(1, 0.5)), regexp = "Multinomial")
})

test_that("likelihood.Multinomial and log_likelihood.Multinomial work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-NegativeBinomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-NegativeBinomial")

test_that("print.NegativeBinomial works", {
expect_output(print(NegativeBinomial(1, 1)), regexp = "NegativeBinomial distribution")
expect_output(print(NegativeBinomial(1, 1)), regexp = "NegativeBinomial")
})

test_that("likelihood.NegativeBinomial and log_likelihood.NegativeBinomial work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Normal.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Normal")

test_that("print.Normal works", {
expect_output(print(Normal()), regexp = "Normal distribution")
expect_output(print(Normal()), regexp = "Normal")
})

test_that("suff_stat.Normal works correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Poisson.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Poisson")

test_that("print.Poisson works", {
expect_output(print(Poisson(1)), regexp = "Poisson distribution")
expect_output(print(Poisson(1)), regexp = "Poisson")
})

test_that("suff_stat.Poisson works correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-PoissonBinomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-PoissonBinomial")

test_that("print.PoissonBinomial works", {
expect_output(print(PoissonBinomial(0.5, 0.3, 0.8)), regexp = "PoissonBinomial distribution")
expect_output(print(PoissonBinomial(0.5, 0.3, 0.8)), regexp = "PoissonBinomial")
})

test_that("likelihood.PoissonBinomial and log_likelihood.PoissonBinomial work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-RevWeibull.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-RevWeibull")

test_that("print.RevWeibull works", {
expect_output(print(RevWeibull()), regexp = "RevWeibull distribution")
expect_output(print(RevWeibull()), regexp = "RevWeibull")
})

## Example distributions
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-StudentsT.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-StudentsT")

test_that("print.StudentsT works", {
expect_output(print(StudentsT(1)), regexp = "StudentsT distribution")
expect_output(print(StudentsT(1)), regexp = "StudentsT")
})

test_that("likelihood.StudentsT and log_likelihood.StudentsT work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Tukey.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Tukey")

test_that("print.Tukey works", {
expect_output(print(Tukey(1, 2, 2)), regexp = "Tukey distribution")
expect_output(print(Tukey(1, 2, 2)), regexp = "Tukey")
})

test_that("random.Tukey work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Uniform.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Uniform")

test_that("print.Uniform works", {
expect_output(print(Uniform(1, 1)), regexp = "Uniform distribution")
expect_output(print(Uniform(1, 1)), regexp = "Uniform")
})

test_that("likelihood.Uniform and log_likelihood.Uniform work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Weibull.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-Weibull")

test_that("print.Weibull works", {
expect_output(print(Weibull(1, 1)), regexp = "Weibull distribution")
expect_output(print(Weibull(1, 1)), regexp = "Weibull")
})

test_that("likelihood.Weibull and log_likelihood.Weibull work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ZINegativeBinomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-ZINegativeBinomial")

test_that("print.ZINegativeBinomial works", {
expect_output(print(ZINegativeBinomial(1, 1, 0.3)), regexp = "ZINegativeBinomial distribution")
expect_output(print(ZINegativeBinomial(1, 1, 0.3)), regexp = "ZINegativeBinomial")
})

test_that("random.ZINegativeBinomial work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ZIPoisson.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-ZIPoisson")

test_that("print.ZIPoisson works", {
expect_output(print(ZIPoisson(1, 0.2)), regexp = "ZIPoisson distribution")
expect_output(print(ZIPoisson(1, 0.2)), regexp = "ZIPoisson")
})

test_that("random.ZIPoisson work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ZTNegativeBinomial.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-ZTNegativeBinomial")

test_that("print.ZTNegativeBinomial works", {
expect_output(print(ZTNegativeBinomial(1, 1)), regexp = "ZTNegativeBinomial distribution")
expect_output(print(ZTNegativeBinomial(1, 1)), regexp = "ZTNegativeBinomial")
})

test_that("random.ZTNegativeBinomial work correctly", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ZTPoisson.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
context("test-ZTPoisson")

test_that("print.ZTPoisson works", {
expect_output(print(ZTPoisson(1)), regexp = "ZTPoisson distribution")
expect_output(print(ZTPoisson(1)), regexp = "ZTPoisson")
})

test_that("random.ZTPoisson work correctly", {
Expand Down

0 comments on commit 6258018

Please sign in to comment.