From 7a38403d8b951040d8ea3efe31d356ffe79bb1a3 Mon Sep 17 00:00:00 2001 From: Jason Cory Brunson Date: Wed, 8 Jul 2026 12:54:06 -0400 Subject: [PATCH 1/2] replace length-0 with empty character when do.call of TDA::*Diag is passed to as_persistence.diagram - fixes #54 --- NEWS.md | 4 ++++ R/persistence-class.R | 2 ++ inst/tinytest/test-persistence-class.R | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/NEWS.md b/NEWS.md index 8e58f5e..a246938 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # phutil (development version) +## Bug fixes + +- `as_persistence.diagram()` would fail when the input was obtained through `do.call()`; it now continues without error, but with empty information about the engine. + # phutil 0.0.2 ## New features diff --git a/R/persistence-class.R b/R/persistence-class.R index c7025c5..20aa32e 100644 --- a/R/persistence-class.R +++ b/R/persistence-class.R @@ -274,6 +274,8 @@ as_persistence.diagram <- function(x, warn = TRUE, ...) { bd_cols <- match(c("Birth", "Death"), info$dimnames[[2L]]) filt_nm <- gsub("*Diag", "", rlang::call_name(info$call)) + # when using `do.call()`, call does not include `TDA::*Diag()` + if (length(filt_nm) == 0L) filt_nm <- "" if (filt_nm == "rips") { filt_nm <- "Vietoris-Rips" } diff --git a/inst/tinytest/test-persistence-class.R b/inst/tinytest/test-persistence-class.R index 8fe3caf..1aea1e1 100644 --- a/inst/tinytest/test-persistence-class.R +++ b/inst/tinytest/test-persistence-class.R @@ -191,4 +191,8 @@ if (requireNamespace("ripserr", quietly = TRUE)) { expect_true(!is.list(as_diagram(h, list = FALSE))) } +# tolerate `do.call()` input +ph <- do.call(ripsDiag, c(list(X = x, maxdimension = 2, maxscale = 10))) +expect_silent(as_persistence(ph)) + options(opts) From 9be71ec7f53afa540d4cd7252b53149b741fe2a2 Mon Sep 17 00:00:00 2001 From: Aymeric Stamm Date: Tue, 6 Oct 2026 13:27:46 +0200 Subject: [PATCH 2/2] Added a forgotten TDA namespace in test suite. --- inst/tinytest/test-persistence-class.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/tinytest/test-persistence-class.R b/inst/tinytest/test-persistence-class.R index 1aea1e1..35046d7 100644 --- a/inst/tinytest/test-persistence-class.R +++ b/inst/tinytest/test-persistence-class.R @@ -192,7 +192,7 @@ if (requireNamespace("ripserr", quietly = TRUE)) { } # tolerate `do.call()` input -ph <- do.call(ripsDiag, c(list(X = x, maxdimension = 2, maxscale = 10))) +ph <- do.call(TDA::ripsDiag, c(list(X = x, maxdimension = 2, maxscale = 10))) expect_silent(as_persistence(ph)) options(opts)