From 625801897214a67d89672a6e40f943dec84d8f17 Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Mon, 29 Apr 2024 23:40:35 +0200 Subject: [PATCH] format() method and hence print() simplified without ...distribution... e.g. Normal(mu = 0, sigma = 1) --- R/PoissonBinomial.R | 2 +- R/utils.R | 2 +- tests/testthat/test-Bernoulli.R | 2 +- tests/testthat/test-Beta.R | 2 +- tests/testthat/test-Binomial.R | 2 +- tests/testthat/test-Categorical.R | 4 ++-- tests/testthat/test-Cauchy.R | 2 +- tests/testthat/test-ChiSquare.R | 2 +- tests/testthat/test-Erlang.R | 2 +- tests/testthat/test-Exponential.R | 4 ++-- tests/testthat/test-FisherF.R | 2 +- tests/testthat/test-Frechet.R | 2 +- tests/testthat/test-Gamma.R | 2 +- tests/testthat/test-GeneralisedExtremeValue.R | 2 +- tests/testthat/test-GeneralisedPareto.R | 2 +- tests/testthat/test-Geometric.R | 2 +- tests/testthat/test-Gumbel.R | 2 +- tests/testthat/test-HurdleNegativeBinomial.R | 2 +- tests/testthat/test-HurdlePoisson.R | 2 +- tests/testthat/test-HyperGeometric.R | 2 +- tests/testthat/test-LogNormal.R | 2 +- tests/testthat/test-Logistic.R | 2 +- tests/testthat/test-Multinomial.R | 2 +- tests/testthat/test-NegativeBinomial.R | 2 +- tests/testthat/test-Normal.R | 2 +- tests/testthat/test-Poisson.R | 2 +- tests/testthat/test-PoissonBinomial.R | 2 +- tests/testthat/test-RevWeibull.R | 2 +- tests/testthat/test-StudentsT.R | 2 +- tests/testthat/test-Tukey.R | 2 +- tests/testthat/test-Uniform.R | 2 +- tests/testthat/test-Weibull.R | 2 +- tests/testthat/test-ZINegativeBinomial.R | 2 +- tests/testthat/test-ZIPoisson.R | 2 +- tests/testthat/test-ZTNegativeBinomial.R | 2 +- tests/testthat/test-ZTPoisson.R | 2 +- 36 files changed, 38 insertions(+), 38 deletions(-) diff --git a/R/PoissonBinomial.R b/R/PoissonBinomial.R index 1a7d07f0..55d219df 100644 --- a/R/PoissonBinomial.R +++ b/R/PoissonBinomial.R @@ -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) diff --git a/R/utils.R b/R/utils.R index c73d20f6..32e7330e 100755 --- a/R/utils.R +++ b/R/utils.R @@ -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) } diff --git a/tests/testthat/test-Bernoulli.R b/tests/testthat/test-Bernoulli.R index db0dfe0d..eef6c31d 100755 --- a/tests/testthat/test-Bernoulli.R +++ b/tests/testthat/test-Bernoulli.R @@ -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", { diff --git a/tests/testthat/test-Beta.R b/tests/testthat/test-Beta.R index 38ba8ffb..c764b00a 100755 --- a/tests/testthat/test-Beta.R +++ b/tests/testthat/test-Beta.R @@ -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", { diff --git a/tests/testthat/test-Binomial.R b/tests/testthat/test-Binomial.R index 4667a676..d728c821 100755 --- a/tests/testthat/test-Binomial.R +++ b/tests/testthat/test-Binomial.R @@ -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", { diff --git a/tests/testthat/test-Categorical.R b/tests/testthat/test-Categorical.R index 9154b454..d15e3607 100755 --- a/tests/testthat/test-Categorical.R +++ b/tests/testthat/test-Categorical.R @@ -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", { diff --git a/tests/testthat/test-Cauchy.R b/tests/testthat/test-Cauchy.R index 06cd28f7..489dae51 100755 --- a/tests/testthat/test-Cauchy.R +++ b/tests/testthat/test-Cauchy.R @@ -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", { diff --git a/tests/testthat/test-ChiSquare.R b/tests/testthat/test-ChiSquare.R index 0d37bbab..50a4d3e1 100755 --- a/tests/testthat/test-ChiSquare.R +++ b/tests/testthat/test-ChiSquare.R @@ -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", { diff --git a/tests/testthat/test-Erlang.R b/tests/testthat/test-Erlang.R index 6e9ec689..5b4b6e90 100755 --- a/tests/testthat/test-Erlang.R +++ b/tests/testthat/test-Erlang.R @@ -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", { diff --git a/tests/testthat/test-Exponential.R b/tests/testthat/test-Exponential.R index 8c1c1047..7facb622 100755 --- a/tests/testthat/test-Exponential.R +++ b/tests/testthat/test-Exponential.R @@ -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", { diff --git a/tests/testthat/test-FisherF.R b/tests/testthat/test-FisherF.R index f1062e7a..ad0bb289 100755 --- a/tests/testthat/test-FisherF.R +++ b/tests/testthat/test-FisherF.R @@ -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", { diff --git a/tests/testthat/test-Frechet.R b/tests/testthat/test-Frechet.R index d8b71661..ffecd493 100755 --- a/tests/testthat/test-Frechet.R +++ b/tests/testthat/test-Frechet.R @@ -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 diff --git a/tests/testthat/test-Gamma.R b/tests/testthat/test-Gamma.R index 1bb225cb..77e5e1dd 100755 --- a/tests/testthat/test-Gamma.R +++ b/tests/testthat/test-Gamma.R @@ -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", { diff --git a/tests/testthat/test-GeneralisedExtremeValue.R b/tests/testthat/test-GeneralisedExtremeValue.R index 12de5d14..524a8a92 100755 --- a/tests/testthat/test-GeneralisedExtremeValue.R +++ b/tests/testthat/test-GeneralisedExtremeValue.R @@ -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 diff --git a/tests/testthat/test-GeneralisedPareto.R b/tests/testthat/test-GeneralisedPareto.R index a6adb199..47892d68 100755 --- a/tests/testthat/test-GeneralisedPareto.R +++ b/tests/testthat/test-GeneralisedPareto.R @@ -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 diff --git a/tests/testthat/test-Geometric.R b/tests/testthat/test-Geometric.R index 5934bea6..987f4faa 100755 --- a/tests/testthat/test-Geometric.R +++ b/tests/testthat/test-Geometric.R @@ -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", { diff --git a/tests/testthat/test-Gumbel.R b/tests/testthat/test-Gumbel.R index e2a48307..5814acb8 100755 --- a/tests/testthat/test-Gumbel.R +++ b/tests/testthat/test-Gumbel.R @@ -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) diff --git a/tests/testthat/test-HurdleNegativeBinomial.R b/tests/testthat/test-HurdleNegativeBinomial.R index 7a3911b2..738e1ab3 100755 --- a/tests/testthat/test-HurdleNegativeBinomial.R +++ b/tests/testthat/test-HurdleNegativeBinomial.R @@ -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", { diff --git a/tests/testthat/test-HurdlePoisson.R b/tests/testthat/test-HurdlePoisson.R index 6d4147c5..96165b84 100755 --- a/tests/testthat/test-HurdlePoisson.R +++ b/tests/testthat/test-HurdlePoisson.R @@ -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", { diff --git a/tests/testthat/test-HyperGeometric.R b/tests/testthat/test-HyperGeometric.R index b7908fcc..df83a18e 100755 --- a/tests/testthat/test-HyperGeometric.R +++ b/tests/testthat/test-HyperGeometric.R @@ -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") }) diff --git a/tests/testthat/test-LogNormal.R b/tests/testthat/test-LogNormal.R index bdf7e8ae..a6e295fa 100755 --- a/tests/testthat/test-LogNormal.R +++ b/tests/testthat/test-LogNormal.R @@ -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", { diff --git a/tests/testthat/test-Logistic.R b/tests/testthat/test-Logistic.R index ab7dc398..aae9be89 100755 --- a/tests/testthat/test-Logistic.R +++ b/tests/testthat/test-Logistic.R @@ -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", { diff --git a/tests/testthat/test-Multinomial.R b/tests/testthat/test-Multinomial.R index b13cd814..ff24f51d 100755 --- a/tests/testthat/test-Multinomial.R +++ b/tests/testthat/test-Multinomial.R @@ -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", { diff --git a/tests/testthat/test-NegativeBinomial.R b/tests/testthat/test-NegativeBinomial.R index 89e42102..c34352d4 100755 --- a/tests/testthat/test-NegativeBinomial.R +++ b/tests/testthat/test-NegativeBinomial.R @@ -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", { diff --git a/tests/testthat/test-Normal.R b/tests/testthat/test-Normal.R index 50108f79..798c4b48 100755 --- a/tests/testthat/test-Normal.R +++ b/tests/testthat/test-Normal.R @@ -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", { diff --git a/tests/testthat/test-Poisson.R b/tests/testthat/test-Poisson.R index 1bcdd34e..39a11a21 100755 --- a/tests/testthat/test-Poisson.R +++ b/tests/testthat/test-Poisson.R @@ -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", { diff --git a/tests/testthat/test-PoissonBinomial.R b/tests/testthat/test-PoissonBinomial.R index c5630ce1..68c2c8bd 100755 --- a/tests/testthat/test-PoissonBinomial.R +++ b/tests/testthat/test-PoissonBinomial.R @@ -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", { diff --git a/tests/testthat/test-RevWeibull.R b/tests/testthat/test-RevWeibull.R index b3de5fc7..ad91d963 100755 --- a/tests/testthat/test-RevWeibull.R +++ b/tests/testthat/test-RevWeibull.R @@ -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 diff --git a/tests/testthat/test-StudentsT.R b/tests/testthat/test-StudentsT.R index 7ccfbb4b..6a9717e3 100755 --- a/tests/testthat/test-StudentsT.R +++ b/tests/testthat/test-StudentsT.R @@ -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", { diff --git a/tests/testthat/test-Tukey.R b/tests/testthat/test-Tukey.R index bbaababe..e6433172 100755 --- a/tests/testthat/test-Tukey.R +++ b/tests/testthat/test-Tukey.R @@ -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", { diff --git a/tests/testthat/test-Uniform.R b/tests/testthat/test-Uniform.R index b2aa4818..63ff7a59 100755 --- a/tests/testthat/test-Uniform.R +++ b/tests/testthat/test-Uniform.R @@ -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", { diff --git a/tests/testthat/test-Weibull.R b/tests/testthat/test-Weibull.R index 948b100a..5e3d30e2 100755 --- a/tests/testthat/test-Weibull.R +++ b/tests/testthat/test-Weibull.R @@ -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", { diff --git a/tests/testthat/test-ZINegativeBinomial.R b/tests/testthat/test-ZINegativeBinomial.R index ee80e87b..c5efb646 100755 --- a/tests/testthat/test-ZINegativeBinomial.R +++ b/tests/testthat/test-ZINegativeBinomial.R @@ -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", { diff --git a/tests/testthat/test-ZIPoisson.R b/tests/testthat/test-ZIPoisson.R index 424114ff..5cc1265e 100755 --- a/tests/testthat/test-ZIPoisson.R +++ b/tests/testthat/test-ZIPoisson.R @@ -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", { diff --git a/tests/testthat/test-ZTNegativeBinomial.R b/tests/testthat/test-ZTNegativeBinomial.R index 04718528..9519c431 100755 --- a/tests/testthat/test-ZTNegativeBinomial.R +++ b/tests/testthat/test-ZTNegativeBinomial.R @@ -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", { diff --git a/tests/testthat/test-ZTPoisson.R b/tests/testthat/test-ZTPoisson.R index 41ec6d23..3ac07b12 100755 --- a/tests/testthat/test-ZTPoisson.R +++ b/tests/testthat/test-ZTPoisson.R @@ -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", {