Skip to content

Commit

Permalink
Added an as.rle.rlebdm() method to cast an rlebdm to an rle for, e.g.…
Browse files Browse the repository at this point in the history
…, arithmetic.
  • Loading branch information
krivit committed Dec 22, 2024
1 parent 794652c commit edc27f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ergm
Version: 4.8.0-7485
Date: 2024-11-24
Version: 4.8.0-7022
Date: 2024-12-22
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
person(c("Mark", "S."), "Handcock", role=c("aut"), email="[email protected]"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ S3method(as.matrix,ergm_state)
S3method(as.matrix,rlebdm)
S3method(as.network,ergm_state_full)
S3method(as.network,numeric)
S3method(as.rle,rlebdm)
S3method(as.rlebdm,"NULL")
S3method(as.rlebdm,edgelist)
S3method(as.rlebdm,ergm_conlist)
Expand Down
15 changes: 15 additions & 0 deletions R/rlebdm.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#' # Large matrix (overflowing .Machine$integer.max)
#' big <- rlebdm(1, 50000)
#' unclass(big) # Represented as two runs
#' big # Only summary is printed
#' stopifnot(length(big)==50000^2)
#'
#' @seealso [as.rlebdm.ergm_conlist()]
Expand Down Expand Up @@ -160,12 +161,26 @@ dim.rlebdm <- function(x){
rep(attr(x, "n"),2)
}

#' @describeIn rlebdm
#'
#' Strip `rlebdm`-specific attributes and class, returning a plain [`rle`] object.
#'
#' @export
as.rle.rlebdm <- function(x) structure(x, class = "rle", n = NULL)

#' @rdname rlebdm
#'
#' @param compact whether to print the matrix compactly (dots and stars) or to print it as a logical matrix.
#'
#' @export
print.rlebdm <- function(x, compact=TRUE, ...){
if(length(x) > getOption("max.print")){
cat(sprintf(
"Large Run-Length-Encoded Binary Dyad Matrix:\n dimension: %0.0f*%0.0f\n number of 1s: %0.0f/%0.0f\n density: %f\n",
nrow(x), ncol(x), sum(x), length(x), sum(x)/length(x)
))
return(invisible(x))
}
x <- as.matrix(x)
if(compact){
x <- ifelse(x, "*", ".")
Expand Down
6 changes: 6 additions & 0 deletions man/rlebdm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit edc27f1

Please sign in to comment.