R Under development (unstable) (2025-05-04 r88189 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # tests for the time-projected functions > > require(tsna) Loading required package: tsna Loading required package: network 'network' 1.19.0 (2024-12-08), part of the Statnet Project * 'news(package="network")' for changes since last version * 'citation("network")' for citation information * 'https://statnet.org' for help, support, and other information Loading required package: networkDynamic 'networkDynamic' 0.11.5 (2024-11-21), part of the Statnet Project * 'news(package="networkDynamic")' for changes since last version * 'citation("networkDynamic")' for citation information * 'https://statnet.org' for help, support, and other information > library(networkDynamicData) > require(testthat) Loading required package: testthat > > # trivial example network, directed case > test<-network.initialize(3) > add.edges.active(test,tail=1,head=2,onset=0,terminus=1) > add.edges.active(test,tail=2,head=3,onset=1,terminus=2) > testProj<-timeProjectedNetwork(test,start=0,end=2) > expect_equal(as.matrix(testProj), + matrix( + c(0, 1, 0, 1, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0),ncol=6,byrow=TRUE),check.attributes=FALSE) > > # undirected case > test%n%'directed'<-FALSE > testProj<-timeProjectedNetwork(test,start=0,end=2) > expect_equal(as.matrix(testProj), + matrix( + c(0, 1, 0, 1, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 1, 0),ncol=6,byrow=TRUE),check.attributes=FALSE) > > > # test edge attribute > data("nd_test_nets") > test<-nd_test_nets[[27]] > activate.edge.attribute(test,'foo',onset=1,terminus=2,'A') > activate.edge.attribute(test,'foo',onset=2,terminus=3,'B') > activate.edge.attribute(test,'foo',onset=3,terminus=4,'C') > activate.edge.attribute(test,'foo',onset=4,terminus=5,'D') > activate.edge.attribute(test,'foo',onset=5,terminus=6,'E') > activate.edge.attribute(test,'foo',onset=6,terminus=7,'F') > activate.edge.attribute(test,'foo',onset=7,terminus=8,'G') > testProj<-timeProjectedNetwork(test,start=0,end=10) > expect_equal(get.edge.attribute(testProj,'foo'),c("A", "B", "C", "D", "E", "F", "G", NA , NA)) > expect_equal(get.edge.attribute(testProj,'pid'),1:9) > # in the undirected case, edges should be copied twice > test%n%'directed'<-FALSE > testProj<-timeProjectedNetwork(test,start=0,end=10) > expect_equal(get.edge.attribute(testProj,'foo'),c("A", "A","B","B", "C","C","D", "D", "E","E","F", "F", "G","G",NA,NA, NA , NA)) > expect_equal(get.edge.attribute(testProj,'pid'),c(1 ,1 ,2 ,2 ,3 ,3 ,4 ,4 ,5, 5, 6, 6 ,7, 7, 8, 8 ,9 ,9)) > > data(moodyContactSim) > changes<-get.change.times(moodyContactSim) > moodyProj<-timeProjectedNetwork(moodyContactSim,onsets=changes,termini=changes) > # make sure the listing didn't get mangled for NA > expect_equal(length(moodyProj%e%'na'),length(get.edge.attribute(moodyProj,'na',unlist=FALSE))) > > data(harry_potter_support) > hpProj<-timeProjectedNetwork(harry_potter_support) > plot(hpProj,arrowhead.cex = 0,edge.col=ifelse(hpProj%e%'edge.type'=='within_slice','black','gray'),vertex.cex=0.7) > > # check that specific slices copied correctly > # WHY DOES THIS FAIL? > #expect_equal(as.matrix(network.extract(harry_potter_support,at=5)),as.matrix(hpProj)[(64*4+1):(64*5),(64*4+1):(64*5)]) > > # check that vertex attributes copied > expect_equal((hpProj%v%'gender')[1:64],harry_potter_support%v%'gender') > expect_equal((hpProj%v%'gender')[65:128],harry_potter_support%v%'gender') > > expect_equal(length(network.vertex.names(hpProj)),network.size(hpProj)) > > # check edge type added > expect_true("edge.type"%in%list.edge.attributes(hpProj)) > > > moodyProj<-timeProjectedNetwork(moodyContactSim,time.increment=100) > > # correct size of new network? > expect_equal(network.size(moodyContactSim)*(moodyContactSim%n%'net.obs.period')$observations[[1]][2]/100,network.size(moodyProj)) > > # create network from changes > changes<-get.change.times(moodyContactSim) > moodyProjChange<-timeProjectedNetwork(moodyContactSim,onsets=changes,termini =changes) > > # test for some vertex inactivity > data(windsurfers) > windProj<-timeProjectedNetwork(windsurfers,start=0,end=5) > > # gplot3d(windProj,edge.col=ifelse(proj%e%'edge.type'=='within_slice','black','gray')) > > proc.time() user system elapsed 2.95 0.43 3.39