Skip to content

Commit 6e589fa

Browse files
author
Raphael Sonabend
committed
update version, dstrs
Branch: master
1 parent 529122b commit 6e589fa

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: distr6
22
Title: The Complete R6 Probability Distributions Interface
3-
Version: 1.6.0
3+
Version: 1.5.0
44
Authors@R:
55
c(person(given = "Raphael",
66
family = "Sonabend",

NEWS.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
# distr6 1.6.0
2-
3-
### Edited Functionality
4-
5-
* The separator for composite (wrapped) distributions is now `__` (before `_`). This may affect backwards compatibility in rare cases.
6-
7-
### Added Functionality
8-
9-
* Added `length.VectorDistribution`
10-
* Added `ids` parameter to `VectorDistribution` to allow specifying names for wrapped distributions. Extended `extract.VectorDistribution` so these ids can be used for extraction.
11-
121
# distr6 1.5.0
132

143
### Minor Updates
154

165
#### Added Functionality
176

7+
* Added `length.VectorDistribution`
8+
* Added `ids` parameter to `VectorDistribution` to allow specifying names for wrapped distributions. Extended `extract.VectorDistribution` so these ids can be used for extraction.
189
* Added sugar function `dstr` to construct distributions more easily, e.g. `dstr("Binom", size = 4)` instead of `Binomial$new(size = 4)`.
1910
* Added sugar function `dstrs` to construct a `VectorDistribution` of distributions.
2011
* `ParameterSet` method `setParameterValue` now includes `resolveConflicts` parameter for resolving conflicts between conflicting parameters (see below). This should primarily only be used internally and is useful for transforming composite distributions.
2112

2213
#### Edited Functionality
2314

15+
* The separator for composite (wrapped) distributions is now `__` (before `_`). This may affect backwards compatibility in rare cases.
2416
* Construction and setting of parameters is now changed. Previously this relied on knowing a confusing hierarchy in parameters which would take priority over one another. Now if conflicting parameters are supplied in construction or on setting an error is returned, e.g. `Binomial$new(prob = 0.1, qprob = 0.2)` would cause an error. This may affect bacwards compatibility however should not do so if distributions are correctly constructed/updated without conflicts.
2517
* `setParameterValue` in `ParameterSet` no longer errors if a non-settable parameter is updated, instead a `warning` is given and the parameter is ignored.
2618
* Multivariate distributions no longer error if constructed with a single variate, though this is still advised against.

R/sugar.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#' dstrs(c("Binom", "Gamma"),
3737
#' list(list(size = 4), list(rate = 2, shape = 3)))
3838
#'
39+
#' # Multiple Binomials
40+
#' dstrs("Binom", data.frame(size = 1:5))
41+
#'
3942
#' @export
4043
dstr <- function(d, ..., pars = NULL) {
4144
choices <- listDistributions()
@@ -57,6 +60,17 @@ dstr <- function(d, ..., pars = NULL) {
5760
#' @rdname dstr
5861
#' @export
5962
dstrs <- function(d, pars = NULL) {
60-
if (is.null(pars)) pars <- vector("list", length(d))
61-
VectorDistribution$new(mapply(dstr, d, pars = pars))
63+
64+
if (length(d) == 1) {
65+
if (is.null(pars)) {
66+
stop("pars' cannot be NULL if 'd' is length 1.")
67+
} else {
68+
VectorDistribution$new(distribution = d, params = pars)
69+
}
70+
} else {
71+
if (is.null(pars)) {
72+
pars <- vector("list", length(d))
73+
}
74+
VectorDistribution$new(mapply(dstr, d, pars = pars))
75+
}
6276
}

man/dstr.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_sugar.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ test_that("dstrs", {
1717
v <- dstrs(c("Binom", "Gamma"), list(list(size = 4), list(rate = 2, shape = 3)))
1818
expect_equal(v[1]$strprint(), "Binom(prob = 0.5, qprob = 0.5, size = 4)")
1919
expect_equal(v[2]$strprint(), "Gamma(shape = 3, rate = 2, scale = 0.5, mean = 1.5)")
20+
v <- dstrs("Binom", data.frame(size = 1:2))
21+
expect_equal(v[1]$strprint(), "Binom(prob = 0.5, qprob = 0.5, size = 1)")
22+
expect_equal(v[2]$strprint(), "Binom(prob = 0.5, qprob = 0.5, size = 2)")
2023
})

0 commit comments

Comments
 (0)