From e8095660883495e49579b484bd0523bb6decfc63 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Mon, 5 Sep 2022 15:09:23 -0700 Subject: [PATCH 01/10] define as.networkDynamic.networkLite importing networkLite, and adding associated tests --- DESCRIPTION | 2 +- NAMESPACE | 3 ++- R/utilities.R | 4 ++++ tests/utils_tests.R | 21 +++++++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d267d93..669526b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,7 @@ Date: 2022-05-04 Title: Dynamic Extensions for Network Objects Type: Package Depends: R (>= 3.0.0), network (>= 1.17.0) -Imports: statnet.common, methods +Imports: statnet.common, methods, networkLite Suggests: testthat LinkingTo: network Authors@R: c( diff --git a/NAMESPACE b/NAMESPACE index 7abc626..4e72844 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ useDynLib(networkDynamic, .registration = TRUE) -import(statnet.common, network) +import(statnet.common, network, networkLite) importFrom("methods", "el") importFrom("methods", "is") importFrom("stats", "na.omit") @@ -90,6 +90,7 @@ S3method(as.network,networkDynamic) S3method(as.networkDynamic,network) S3method(as.networkDynamic,networkDynamic) S3method(print,networkDynamic) +S3method(as.networkDynamic,networkLite) # these are NOT S3 methods, but are included here because its the # only way to quiet the warning diff --git a/R/utilities.R b/R/utilities.R index 91756ff..80ea550 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1042,6 +1042,10 @@ as.networkDynamic.network<- function(object,...){ return(object) } +as.networkDynamic.networkLite <- function(object, ...) { + as.networkDynamic(to_network_networkLite(object)) +} + # remove networkDynamic class but leave object unchanged as.network.networkDynamic<-function(x,...){ if(is.networkDynamic(x)){ diff --git a/tests/utils_tests.R b/tests/utils_tests.R index 050719a..b432ab8 100644 --- a/tests/utils_tests.R +++ b/tests/utils_tests.R @@ -89,3 +89,24 @@ test_that("get.dyads.active works",{ }) +test_that("conversions between network, networkLite, and networkDynamic behave as expected", { + library(networkLite) + + m <- matrix(rbinom(20*20, 1, 1/10), nrow = 20, ncol = 20) + m[lower.tri(m, diag = TRUE)] <- FALSE + el <- which(m > 0, arr.ind = TRUE) + el <- el[order(el[,1], el[,2]),,drop=FALSE] + attr(el, "n") <- 20 + + nw <- network(el, directed = FALSE, bipartite = FALSE, matrix.type = "edgelist") + nwL <- as.networkLite(nw) + nwLD <- as.networkDynamic(nwL) + nwD <- as.networkDynamic(nw) + expect_identical(nwD, nwLD) + + nwL <- networkLite(el) + nw <- to_network_networkLite(nwL) + nwD <- as.networkDynamic(nw) + nwLD <- as.networkDynamic(nwL) + expect_identical(nwD, nwLD) +}) From 38607e4e074b31d3f1fd5126050e796a7e75a9dc Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Mon, 5 Sep 2022 15:14:00 -0700 Subject: [PATCH 02/10] add networkLite remote --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 669526b..15b73e9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,3 +23,5 @@ Description: Simple interface routines to facilitate the handling of network obj License: GPL-3 LazyLoad: yes URL: http://statnet.org +Remotes: + github::EpiModel/networkLite@networkLite From 74d7e28cf0ad06ca15b1b42b030e661210c4fc83 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Mon, 5 Sep 2022 16:08:53 -0700 Subject: [PATCH 03/10] bump minor version number --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 15b73e9..adf73c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: networkDynamic -Version: 0.11.2 +Version: 0.11.3 Date: 2022-05-04 Title: Dynamic Extensions for Network Objects Type: Package From 36a8af84ce8a0a7b7eda381ede081182371ff0f5 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Mon, 5 Sep 2022 16:10:27 -0700 Subject: [PATCH 04/10] update ChangeLog --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1f166d2..f51b09e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ Change Log: +v0.11.3 + - import networkLite and define as.networkDynamic.networkLite to support tergm applications v0.11.2 - corrected trailing quote in maintainer email flagged by CRAN v0.11.1 From 11312f79434d24c96fdb016e5bb773d29b38e2f4 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Sun, 11 Sep 2022 09:57:59 -0700 Subject: [PATCH 05/10] update documentation for as.networkDynamic and expand tests a bit --- man/as.networkDynamic.Rd | 46 ++++++++++++++++++++++++++++++---------- tests/utils_tests.R | 10 ++++++--- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/man/as.networkDynamic.Rd b/man/as.networkDynamic.Rd index 74bc754..9c346b8 100644 --- a/man/as.networkDynamic.Rd +++ b/man/as.networkDynamic.Rd @@ -11,42 +11,58 @@ \alias{as.networkDynamic} \alias{as.networkDynamic.network} \alias{as.networkDynamic.networkDynamic} +\alias{as.networkDynamic.networkLite} \title{ as.networkDynamic } \description{ -Functions with these names formerly provided S3-dispatched functions for converting between various dynamic network formats which have been DEPRECATED. Use \code{\link{networkDynamic}} instead. Current application only sets the networkDynamic class on objects. +The \code{as.networkDynamic} generic provides basic conversion to +\code{networkDynamic} from other network types. Where possible, it is +recommended to use the \code{\link{networkDynamic}} function instead of +\code{as.networkDynamic}, because \code{\link{networkDynamic}} provides a +number of additional features for handling temporal information. } - - \usage{ \method{as.networkDynamic}{networkDynamic}(object,...) \method{as.networkDynamic}{network}(object,...) +\method{as.networkDynamic}{networkLite}(object,...) } %- maybe also 'usage' for other objects documented here. \arguments{ - \item{object}{a \code{network} or \code{networkDynamic} object} + \item{object}{a \code{network}, \code{networkLite}, or \code{networkDynamic} object} \item{\dots}{ignored} } \details{ - \code{as.networkDynamic.network} converts a network object into networkDynamic object by adding a \code{networkDynamic} class. -} - + \code{as.networkDynamic.network} converts a \code{network} object into + a \code{networkDynamic} object by adding a \code{networkDynamic} class. + + \code{as.networkDynamic.networkLite} converts a \code{networkLite} object into + a \code{networkDynamic} object by first converting it to a \code{network} + object and then adding a \code{networkDynamic} class. + Such conversions between network types are used when starting a dynamic + simulation from a cross-sectional network and returning the simulation history + as a dynamic network, as done in the \code{tergm} package for example. +} \value{ - For \code{as.networkDynamic.network} the input object is returned with a \code{networkDynamic} class added. For \code{as.networkDynamic.networkDynamic} the input object is returned. + For \code{as.networkDynamic.network} the input object is returned with a + \code{networkDynamic} class added. For \code{as.networkDynamic.networkLite}, + the input object is converted to a \code{network} object and then the + \code{networkDynamic} class is added. For + \code{as.networkDynamic.networkDynamic} the input object is returned + unchanged. } \note{ -Function modifies its argument +The \code{network} method modifies its argument. } \author{ @@ -54,11 +70,19 @@ Pavel, Zack W Almquist } %% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ -For previous functionality, see \code{\link{networkDynamic}}. For the inverse (removing networkDynamic class) see \code{\link{as.network.networkDynamic}}. +For more general construction of \code{networkDynamic}s, see +\code{\link{networkDynamic}}. For the inverse (removing \code{networkDynamic} +class) see \code{\link{as.network.networkDynamic}} and +\code{\link{as.networkLite.network}} (which applies to \code{networkDynamic}s). } \examples{ - nd<-as.networkDynamic(network.initialize(3)) + nd <- as.networkDynamic(network.initialize(3)) class(nd) is.networkDynamic(nd) + + nwL <- networkLite::networkLite(3) + nwD <- as.networkDynamic(nwL) + class(nwD) + is.networkDynamic(nwD) } diff --git a/tests/utils_tests.R b/tests/utils_tests.R index b432ab8..b4450b3 100644 --- a/tests/utils_tests.R +++ b/tests/utils_tests.R @@ -91,22 +91,26 @@ test_that("get.dyads.active works",{ test_that("conversions between network, networkLite, and networkDynamic behave as expected", { library(networkLite) - + m <- matrix(rbinom(20*20, 1, 1/10), nrow = 20, ncol = 20) m[lower.tri(m, diag = TRUE)] <- FALSE el <- which(m > 0, arr.ind = TRUE) el <- el[order(el[,1], el[,2]),,drop=FALSE] attr(el, "n") <- 20 - + nw <- network(el, directed = FALSE, bipartite = FALSE, matrix.type = "edgelist") nwL <- as.networkLite(nw) nwLD <- as.networkDynamic(nwL) nwD <- as.networkDynamic(nw) + nwDL <- as.networkLite(nwD) expect_identical(nwD, nwLD) - + expect_identical(nwDL, nwL) + nwL <- networkLite(el) nw <- to_network_networkLite(nwL) nwD <- as.networkDynamic(nw) nwLD <- as.networkDynamic(nwL) + nwDL <- as.networkLite(nwD) expect_identical(nwD, nwLD) + expect_identical(nwDL, nwL) }) From e9a0868469d5df421bce23bb2b0350f9459437dd Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Wed, 14 Sep 2022 08:20:15 -0700 Subject: [PATCH 06/10] documentation update --- man/as.networkDynamic.Rd | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/man/as.networkDynamic.Rd b/man/as.networkDynamic.Rd index 9c346b8..fc45fe9 100644 --- a/man/as.networkDynamic.Rd +++ b/man/as.networkDynamic.Rd @@ -16,10 +16,11 @@ \title{ as.networkDynamic } + \description{ -The \code{as.networkDynamic} generic provides basic conversion to -\code{networkDynamic} from other network types. Where possible, it is -recommended to use the \code{\link{networkDynamic}} function instead of +The \code{as.networkDynamic} generic provides a very basic conversion to +\code{networkDynamic} from other network types. It is generally recommended +to use the \code{\link{networkDynamic}} function instead of \code{as.networkDynamic}, because \code{\link{networkDynamic}} provides a number of additional features for handling temporal information. } @@ -45,7 +46,9 @@ number of additional features for handling temporal information. \code{as.networkDynamic.networkLite} converts a \code{networkLite} object into a \code{networkDynamic} object by first converting it to a \code{network} - object and then adding a \code{networkDynamic} class. + object and then adding a \code{networkDynamic} class. (\code{networkLite}s are + a backend data structure used in some \code{EpiModel} and \code{statnet} + packages, and are not typically handled directly by the end user.) Such conversions between network types are used when starting a dynamic simulation from a cross-sectional network and returning the simulation history From 19a8fc064a92fcf9bcd8c5edc9e8f28530d07dc5 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Wed, 14 Sep 2022 11:32:04 -0700 Subject: [PATCH 07/10] documentation update --- man/as.networkDynamic.Rd | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/man/as.networkDynamic.Rd b/man/as.networkDynamic.Rd index fc45fe9..f9fbbe9 100644 --- a/man/as.networkDynamic.Rd +++ b/man/as.networkDynamic.Rd @@ -73,10 +73,14 @@ Pavel, Zack W Almquist } %% ~Make other sections like Warning with \section{Warning }{....} ~ \seealso{ -For more general construction of \code{networkDynamic}s, see -\code{\link{networkDynamic}}. For the inverse (removing \code{networkDynamic} -class) see \code{\link{as.network.networkDynamic}} and +For the inverse (removing the \code{networkDynamic} class) see +\code{\link{as.network.networkDynamic}} and \code{\link{as.networkLite.network}} (which applies to \code{networkDynamic}s). +For extracting cross-sectional information from a \code{networkDynamic} (which +is often more appropriate than simply removing the \code{networkDynamic} +class), see \code{\link{network.collapse}} and \code{\link{network.extract}}. +For more general construction of \code{networkDynamic}s, see +\code{\link{networkDynamic}}. } \examples{ From cdda973e138c0a9d6fe2aed37b565cced1dcff4a Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Fri, 16 Sep 2022 06:15:21 -0700 Subject: [PATCH 08/10] the network method actually doesn't modify its argument set.nD.class does, but this does not modify the argument passed to the network method (or the generic) --- man/as.networkDynamic.Rd | 4 ---- 1 file changed, 4 deletions(-) diff --git a/man/as.networkDynamic.Rd b/man/as.networkDynamic.Rd index f9fbbe9..348bef8 100644 --- a/man/as.networkDynamic.Rd +++ b/man/as.networkDynamic.Rd @@ -64,10 +64,6 @@ number of additional features for handling temporal information. unchanged. } -\note{ -The \code{network} method modifies its argument. -} - \author{ Pavel, Zack W Almquist } From 13a9880513853a3e52798b8c707c5e895951b5b8 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Fri, 16 Sep 2022 06:17:29 -0700 Subject: [PATCH 09/10] remote Remotes but note that the `EpiModel/networkLite@networkLite` branch is the one to use (until it's merged into main, anyway) --- DESCRIPTION | 2 -- 1 file changed, 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index adf73c4..660c1cb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,5 +23,3 @@ Description: Simple interface routines to facilitate the handling of network obj License: GPL-3 LazyLoad: yes URL: http://statnet.org -Remotes: - github::EpiModel/networkLite@networkLite From 9fc7480f665afdc9245d1c2ba808bb99d14c89b7 Mon Sep 17 00:00:00 2001 From: chad-klumb Date: Thu, 22 Sep 2022 08:19:54 -0700 Subject: [PATCH 10/10] update documentation --- man/as.networkDynamic.Rd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/as.networkDynamic.Rd b/man/as.networkDynamic.Rd index 348bef8..66e4454 100644 --- a/man/as.networkDynamic.Rd +++ b/man/as.networkDynamic.Rd @@ -48,7 +48,11 @@ number of additional features for handling temporal information. a \code{networkDynamic} object by first converting it to a \code{network} object and then adding a \code{networkDynamic} class. (\code{networkLite}s are a backend data structure used in some \code{EpiModel} and \code{statnet} - packages, and are not typically handled directly by the end user.) + packages, providing improved performance for certain applications, especially + when working with vertex and edge attributes that can be stored as atomic + vectors. Currently, \code{networkLite}s come with the restriction that the + network attributes \code{hyper}, \code{multiple}, and \code{loops} must be + \code{FALSE}. See \code{\link{networkLite-package}} for more information.) Such conversions between network types are used when starting a dynamic simulation from a cross-sectional network and returning the simulation history