From 7ea133fb8eb516d84804e2e233dc3494ab0156b1 Mon Sep 17 00:00:00 2001 From: RaphaelS1 Date: Tue, 17 Oct 2023 14:58:18 +0100 Subject: [PATCH 1/3] Closes `survival` property disappears after combining `VectorDistribution`s #294 --- R/SDistribution_Arrdist.R | 9 +++++++-- R/SDistribution_Matdist.R | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/R/SDistribution_Arrdist.R b/R/SDistribution_Arrdist.R index e6d8efd53..507a9780e 100644 --- a/R/SDistribution_Arrdist.R +++ b/R/SDistribution_Arrdist.R @@ -372,6 +372,7 @@ Arrdist <- R6Class("Arrdist", #' @title Combine Array Distributions into a Arrdist #' @description Helper function for quickly combining distributions into a [Arrdist]. #' @param ... array distributions to be concatenated. +#' @param decorators If supplied then adds given decorators, otherwise pulls them from underlying distributions. #' @return [Arrdist] #' @examples #' # create three array distributions with different column names @@ -383,13 +384,17 @@ Arrdist <- R6Class("Arrdist", #' }) #' do.call(c, arr) #' @export -c.Arrdist <- function(...) { +c.Arrdist <- function(..., decorators = NULL) { # get the pdfs and decorators pdfdec <- unlist(lapply(list(...), function(x) list(gprm(x, "pdf"), x$decorators)), recursive = FALSE ) pdfs <- pdfdec[seq.int(1, length(pdfdec), by = 2)] - decs <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)])) + + + if (is.null(decorators)) { + decorators <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)])) + } nt <- unique(vapply(pdfs, function(.x) dim(.x)[3L], integer(1))) if (length(nt) > 1) { diff --git a/R/SDistribution_Matdist.R b/R/SDistribution_Matdist.R index af2003c85..fc127b99c 100644 --- a/R/SDistribution_Matdist.R +++ b/R/SDistribution_Matdist.R @@ -335,6 +335,7 @@ Matdist <- R6Class("Matdist", #' @title Combine Matrix Distributions into a Matdist #' @description Helper function for quickly combining distributions into a [Matdist]. #' @param ... matrix distributions to be concatenated. +#' @param decorators If supplied then adds given decorators, otherwise pulls them from underlying distributions. #' @return [Matdist] #' @examples #' # create three matrix distributions with different column names @@ -346,16 +347,20 @@ Matdist <- R6Class("Matdist", #' }) #' do.call(c, mats) #' @export -c.Matdist <- function(...) { +c.Matdist <- function(..., decorators = NULL) { # get the pdfs and decorators pdfdec <- unlist(lapply(list(...), function(x) list(gprm(x, "pdf"), x$decorators)), recursive = FALSE ) pdfs <- pdfdec[seq.int(1, length(pdfdec), by = 2)] - decs <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)])) + + if (is.null(decorators)) { + decorators <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)])) + } + as.Distribution(do.call(rbind, .merge_matpdf_cols(pdfs)), fun = "pdf", - decorators = decs) + decorators = decorators) } #' @title Extract one or more Distributions from a Matdist From 5e26b5c0b5c9db472a31eb3b392349fc8e53091e Mon Sep 17 00:00:00 2001 From: RaphaelS1 Date: Tue, 17 Oct 2023 15:00:50 +0100 Subject: [PATCH 2/3] vbump --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ man/c.Arrdist.Rd | 4 +++- man/c.Matdist.Rd | 4 +++- man/distr6-package.Rd | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4c49deef2..a24640230 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: distr6 Title: The Complete R6 Probability Distributions Interface -Version: 1.8.2 +Version: 1.8.3 Authors@R: c(person(given = "Raphael", family = "Sonabend", diff --git a/NEWS.md b/NEWS.md index ffdf2f633..5bb395921 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# distr6 1.8.3 + +* Add `decorators` argument to `c.Matdist` and `c.Arrdist` + # distr6 1.8.1 * Add 'transformer' functions `pdfcdf` and `cdfpdf`, which use Rcpp to transform matrics/arrays/vectors between pdf->cdf and cdf->pdf respectively. diff --git a/man/c.Arrdist.Rd b/man/c.Arrdist.Rd index 90a72c90a..54a995da5 100644 --- a/man/c.Arrdist.Rd +++ b/man/c.Arrdist.Rd @@ -4,10 +4,12 @@ \alias{c.Arrdist} \title{Combine Array Distributions into a Arrdist} \usage{ -\method{c}{Arrdist}(...) +\method{c}{Arrdist}(..., decorators = NULL) } \arguments{ \item{...}{array distributions to be concatenated.} + +\item{decorators}{If supplied then adds given decorators, otherwise pulls them from underlying distributions.} } \value{ \link{Arrdist} diff --git a/man/c.Matdist.Rd b/man/c.Matdist.Rd index a12b9b113..3cec0e6f2 100644 --- a/man/c.Matdist.Rd +++ b/man/c.Matdist.Rd @@ -4,10 +4,12 @@ \alias{c.Matdist} \title{Combine Matrix Distributions into a Matdist} \usage{ -\method{c}{Matdist}(...) +\method{c}{Matdist}(..., decorators = NULL) } \arguments{ \item{...}{matrix distributions to be concatenated.} + +\item{decorators}{If supplied then adds given decorators, otherwise pulls them from underlying distributions.} } \value{ \link{Matdist} diff --git a/man/distr6-package.Rd b/man/distr6-package.Rd index 7ec106d73..cb49ceae3 100644 --- a/man/distr6-package.Rd +++ b/man/distr6-package.Rd @@ -66,6 +66,7 @@ Other contributors: \item Chijing Zeng \email{britneyzenguk@gmail.com} [contributor] \item Qian Zhou \email{zcakqz1@ucl.ac.uk} [contributor] \item Michal Lauer \email{michal.lauer.25@gmail.com} [contributor] + \item John Zobolas \email{bblodfon@gmail.com} (\href{https://orcid.org/0000-0002-3609-8674}{ORCID}) [contributor] } } From e2f2235212d5c1539880900a091befb1c4ba51e4 Mon Sep 17 00:00:00 2001 From: john Date: Tue, 17 Oct 2023 17:34:22 +0200 Subject: [PATCH 3/3] fix var name --- R/SDistribution_Arrdist.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/SDistribution_Arrdist.R b/R/SDistribution_Arrdist.R index 507a9780e..f6f4e85a6 100644 --- a/R/SDistribution_Arrdist.R +++ b/R/SDistribution_Arrdist.R @@ -404,7 +404,7 @@ c.Arrdist <- function(..., decorators = NULL) { pdfs <- .merge_arrpdf_cols(pdfs) pdfs <- do.call(abind::abind, list(what = pdfs, along = 1)) - as.Distribution(pdfs, fun = "pdf", decorators = decs) + as.Distribution(pdfs, fun = "pdf", decorators = decorators) } #' @title Extract one or more Distributions from an Array distribution