Skip to content

Commit 5c51519

Browse files
committed
Cleaning
1 parent 213bda0 commit 5c51519

12 files changed

+69
-137
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Suggests:
5151
survival
5252
VignetteBuilder: knitr
5353
LinkingTo: Rcpp, RcppArmadillo
54-
RoxygenNote: 7.3.1
54+
RoxygenNote: 7.3.2
5555
Encoding: UTF-8
5656
URL: https://github.com/USCCANA/netdiffuseR,
5757
https://USCCANA.github.io/netdiffuseR/

NEWS.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Changes in netdiffuseR version 1.23.0 (2025-01-03)
2+
3+
* New methods for simulating multi-diffusion models, including disadoption.
4+
5+
*
6+
7+
18
# Changes in netdiffuseR version 1.22.7 (2024-09-18)
29

310
* Minor changes to testing (skip warnings).

R/diffnet-class.r

+10-8
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ check_as_diffnet_attrs <- function(
532532
#' \item \code{undirected}: Logical scalar.
533533
#' \item \code{multiple}: Logical scalar.
534534
#' \item \code{name}: Character scalar.
535-
#' \item \code{behavior}: Character scalar.
535+
#' \item \code{behavior}: A list of character scalars.
536536
#' }
537537
#' }
538538
#' @author George G. Vega Yon & Aníbal Olivera M.
@@ -572,7 +572,7 @@ new_diffnet <- function(
572572
self = getOption("diffnet.self"),
573573
multiple = getOption("diffnet.multiple"),
574574
name = "Diffusion Network",
575-
behavior = NA_character_
575+
behavior = NULL
576576
) {
577577

578578
# Step 0.0: Check if its diffnet! --------------------------------------------
@@ -583,17 +583,19 @@ new_diffnet <- function(
583583

584584
# Step 0.1: Setting num_of_behavior ------------------------------------------
585585

586-
if (inherits(toa, "matrix"))
586+
if (inherits(toa, "matrix"))
587587
num_of_behaviors <- dim(toa)[2]
588588
else
589589
num_of_behaviors <- 1
590590

591-
if (is.na(behavior))
591+
if (length(behavior) == 0L)
592592
behavior <- rep("Unknown", num_of_behaviors)
593593
else if (length(behavior) != num_of_behaviors)
594594
stop(
595595
"Length of -behavior- must be equal to the number of behaviors in -toa-."
596596
)
597+
else if (!inherits(behavior, "list"))
598+
behavior <- as.list(behavior)
597599

598600
# Step 1.1: Check graph ------------------------------------------------------
599601
meta <- classify_graph(graph)
@@ -603,14 +605,14 @@ new_diffnet <- function(
603605

604606
# Step 1.2: Checking that lengths fit
605607
if ((num_of_behaviors == 1L) && (length(toa) != meta$n)) {
606-
608+
607609
stop(
608610
"-graph- and -toa- have different lengths (", meta$n, " and ",
609611
length(toa),
610612
" respectively). -toa- should be of length n (number of vertices)."
611613
)
612614

613-
} else if (length(toa[, 1L])!=meta$n) {
615+
} else if ((num_of_behaviors > 1L) && length(toa[, 1L])!=meta$n) {
614616

615617
stop(
616618
"-graph- and -toa[, 1]- have different lengths (", meta$n, " and ",
@@ -620,7 +622,7 @@ new_diffnet <- function(
620622

621623
}
622624

623-
# Step 2.1: Checking class of TOA and coercing if necessary
625+
# Step 2.1: Checking class of TOA and coercing if necessary
624626
if (!inherits(toa, "integer")) {
625627

626628
warning("Coercing -toa- into integer.")
@@ -686,7 +688,7 @@ new_diffnet <- function(
686688
"Please provide lower and upper boundaries for the values in -toa- ",
687689
"using -t0- and -t- (see ?toa_mat)."
688690
)
689-
691+
690692
} else {
691693

692694
graph <- lapply(

R/diffnet-methods.r

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ summary.diffnet <- function(
324324
"Name : ", meta$name, "\n")
325325

326326
if (single) {
327-
cat(" Behavior : ", meta$behavior, "\n",
327+
cat(" Behavior : ", meta$behavior[[1L]], "\n",
328328
rule,"\n",sep="")
329329
cat(header,"\n")
330330
cat(hline, "\n")
@@ -335,7 +335,7 @@ summary.diffnet <- function(
335335
} else {
336336
beh_names <- meta$behavior
337337
for (q in 1:length(object$cumadopt)) {
338-
cat("\n Behavior : ", beh_names[q], "\n",
338+
cat("\n Behavior : ", beh_names[[q]], "\n",
339339
rule,"\n",sep="")
340340
cat(header,"\n")
341341
cat(hline, "\n")

R/graph_data.r

-77
Original file line numberDiff line numberDiff line change
@@ -41,83 +41,6 @@
4141
#' @family graph formats
4242
NULL
4343

44-
45-
as_generic_graph <- function(graph) UseMethod("as_generic_graph")
46-
47-
# Method for igraph objects
48-
as_generic_graph.igraph <- function(graph) {
49-
50-
# If multiple then warn
51-
if (igraph::any_multiple(graph))
52-
warning("The -igraph- object has multiple edges. Only one of each will be retrieved.")
53-
if ("weight" %in% igraph::graph_attr_names(graph)) {
54-
adjmat <- igraph::as_adj(graph, attr="weight")
55-
} else {
56-
adjmat <- igraph::as_adj(graph)
57-
}
58-
59-
# Converting to dgCMatrix
60-
env <- environment()
61-
ans <- new_generic_graph()
62-
suppressWarnings(add_to_generic_graph("ans", "graph", list(`1`=adjmat), env))
63-
meta <- c(classify_graph(adjmat), list(
64-
self = any(igraph::is.loop(graph)),
65-
undirected = FALSE, # For now we will assume it is undirected
66-
multiple = FALSE, # And !multiple
67-
class = "igraph"
68-
))
69-
add_to_generic_graph("ans", "meta", meta, env)
70-
71-
return(ans)
72-
}
73-
74-
new_generic_graph <- function() {
75-
list(graph=NULL, meta=NULL)
76-
}
77-
78-
# This function adds an element checking that the slot exits
79-
add_to_generic_graph <- function(gg,nam,val,env=environment()) {
80-
obj <- get(gg, envir = env)
81-
if (!(nam %in% names(obj))) stop(nam," unknown slot.")
82-
obj[[nam]] <- val
83-
assign(gg,obj,envir = env)
84-
invisible(NULL)
85-
}
86-
87-
# Method for network objects
88-
as_generic_graph.network <- function(graph) {
89-
# If multiple then warn
90-
if (network::is.multiplex(graph))
91-
warning("The -network- object has multiple edges. These will be added up.")
92-
93-
# Converting to an adjacency matrix (dgCMatrix)
94-
adjmat <- edgelist_to_adjmat(
95-
network::as.edgelist(graph),
96-
undirected = !network::is.directed(graph),
97-
multiple = network::is.multiplex(graph),
98-
self = network::has.loops(graph)
99-
)
100-
101-
ord <- network::network.vertex.names(graph)
102-
ord <- match(ord, rownames(adjmat))
103-
adjmat <- adjmat[ord,ord]
104-
105-
env <- environment()
106-
ans <- new_generic_graph()
107-
suppressWarnings(add_to_generic_graph("ans", "graph", list(`1`=adjmat), env))
108-
109-
meta <- c(classify_graph(adjmat), list(
110-
self = network::has.loops(graph),
111-
undirected = !network::is.directed(graph),
112-
multiple = network::is.multiplex(graph),
113-
class = "network"
114-
))
115-
116-
add_to_generic_graph("ans", "meta", meta, env)
117-
118-
return(ans)
119-
}
120-
12144
stopifnot_graph <- function(x)
12245
stop("No method for graph of class -",class(x),"- for ", deparse(sys.call()) #match.call()
12346
,". Please refer to the manual 'netdiffuseR-graphs'.")

man/diffnet-class.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/figures/netdiffuser-logo.png

-5 KB
Loading

man/split_behaviors.Rd

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netdiffuseR.Rproj

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: cd097d00-46b5-4411-bf0c-2d01da946aea
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

tests/testthat/test-rdiffnet.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ test_that("Disadoption works", {
200200

201201
}
202202

203-
ans_d_adopt <- rdiffnet(n = n, t = 10, disadopt = d_adopt, seed.p.adopt = list(0.1, 0.1))
203+
ans_d_adopt <- rdiffnet(
204+
n = n, t = 10, disadopt = d_adopt,
205+
seed.p.adopt = list(0.1, 0.1)
206+
)
204207

205208
tmat <- toa_mat(ans_d_adopt)
206209
should_be_ones_or_zeros <- tmat[[1]]$cumadopt[, 10] + tmat[[2]]$cumadopt[, 10]

vignettes/large-simulation.Rmd

-44
This file was deleted.

vignettes/simulating-multiple-behaviors-on-networks.Rmd

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
title: "Simulating Multiple Behaviors on Networks"
33
author: "Aníbal Olivera M."
44
date: "2024-11-21"
5-
output: html_document
5+
output: rmarkdown::html_vignette
6+
vignette: >
7+
%\VignetteIndexEntry{Simulating Multiple Behaviors on Networks}
8+
%\VignetteEngine{knitr::rmarkdown}
9+
%\VignetteEncoding{UTF-8}
610
---
711

812
\tableofcontents

0 commit comments

Comments
 (0)