Skip to content

Commit 255a666

Browse files
authored
Merge pull request #295 from xoopR/fix_c_consistency
Closes #294
2 parents f727044 + e2f2235 commit 255a666

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
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.8.2
3+
Version: 1.8.3
44
Authors@R:
55
c(person(given = "Raphael",
66
family = "Sonabend",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# distr6 1.8.3
2+
3+
* Add `decorators` argument to `c.Matdist` and `c.Arrdist`
4+
15
# distr6 1.8.1
26

37
* Add 'transformer' functions `pdfcdf` and `cdfpdf`, which use Rcpp to transform matrics/arrays/vectors between pdf->cdf and cdf->pdf respectively.

R/SDistribution_Arrdist.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ Arrdist <- R6Class("Arrdist",
372372
#' @title Combine Array Distributions into a Arrdist
373373
#' @description Helper function for quickly combining distributions into a [Arrdist].
374374
#' @param ... array distributions to be concatenated.
375+
#' @param decorators If supplied then adds given decorators, otherwise pulls them from underlying distributions.
375376
#' @return [Arrdist]
376377
#' @examples
377378
#' # create three array distributions with different column names
@@ -383,13 +384,17 @@ Arrdist <- R6Class("Arrdist",
383384
#' })
384385
#' do.call(c, arr)
385386
#' @export
386-
c.Arrdist <- function(...) {
387+
c.Arrdist <- function(..., decorators = NULL) {
387388
# get the pdfs and decorators
388389
pdfdec <- unlist(lapply(list(...), function(x) list(gprm(x, "pdf"), x$decorators)),
389390
recursive = FALSE
390391
)
391392
pdfs <- pdfdec[seq.int(1, length(pdfdec), by = 2)]
392-
decs <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))
393+
394+
395+
if (is.null(decorators)) {
396+
decorators <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))
397+
}
393398

394399
nt <- unique(vapply(pdfs, function(.x) dim(.x)[3L], integer(1)))
395400
if (length(nt) > 1) {
@@ -399,7 +404,7 @@ c.Arrdist <- function(...) {
399404
pdfs <- .merge_arrpdf_cols(pdfs)
400405
pdfs <- do.call(abind::abind, list(what = pdfs, along = 1))
401406

402-
as.Distribution(pdfs, fun = "pdf", decorators = decs)
407+
as.Distribution(pdfs, fun = "pdf", decorators = decorators)
403408
}
404409

405410
#' @title Extract one or more Distributions from an Array distribution

R/SDistribution_Matdist.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ Matdist <- R6Class("Matdist",
335335
#' @title Combine Matrix Distributions into a Matdist
336336
#' @description Helper function for quickly combining distributions into a [Matdist].
337337
#' @param ... matrix distributions to be concatenated.
338+
#' @param decorators If supplied then adds given decorators, otherwise pulls them from underlying distributions.
338339
#' @return [Matdist]
339340
#' @examples
340341
#' # create three matrix distributions with different column names
@@ -346,16 +347,20 @@ Matdist <- R6Class("Matdist",
346347
#' })
347348
#' do.call(c, mats)
348349
#' @export
349-
c.Matdist <- function(...) {
350+
c.Matdist <- function(..., decorators = NULL) {
350351
# get the pdfs and decorators
351352
pdfdec <- unlist(lapply(list(...), function(x) list(gprm(x, "pdf"), x$decorators)),
352353
recursive = FALSE
353354
)
354355
pdfs <- pdfdec[seq.int(1, length(pdfdec), by = 2)]
355-
decs <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))
356+
357+
if (is.null(decorators)) {
358+
decorators <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))
359+
}
360+
356361

357362
as.Distribution(do.call(rbind, .merge_matpdf_cols(pdfs)), fun = "pdf",
358-
decorators = decs)
363+
decorators = decorators)
359364
}
360365

361366
#' @title Extract one or more Distributions from a Matdist

man/c.Arrdist.Rd

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

man/c.Matdist.Rd

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

man/distr6-package.Rd

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

0 commit comments

Comments
 (0)