Skip to content

Commit

Permalink
Applying CRAN changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Feb 3, 2020
1 parent 67875ed commit 5b3bbfb
Show file tree
Hide file tree
Showing 73 changed files with 1,237 additions and 631 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ makefile
^docs$
^LICENSE\.md$
^_pkgdown\.yml$
^netdiffuseR\.tar\.gz$
32 changes: 23 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ dist: trusty
language: r
sudo: false

r:
- release
- oldrel

os:
- linux
- osx

osx_image: xcode7.3
matrix:
include:
- os: linux
r: oldrel
- os: linux
r: release
env:
- R_CODECOV=true
- BUILD_WWW_HERE=true
- os: linux
r: devel
- os: osx
osx_image: xcode10.2

env:
global:
Expand All @@ -36,3 +40,13 @@ notifications:
email:
on_success: change
on_failure: change

# For automatic deploy of the website
before_deploy: Rscript -e 'remotes::install_cran("pkgdown")'
deploy:
provider: script
script: Rscript -e 'pkgdown::deploy_site_github()'
skip_cleanup: true
on:
branch: master
condition: $BUILD_WWW_HERE = true
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: netdiffuseR
Title: Analysis of Diffusion and Contagion Processes on Networks
Version: 1.20.2
Date: 2019-03-25
Version: 1.20.999
Date: 2020-02-03
Authors@R: c(
person("George", "Vega Yon", email="[email protected]", role=c("aut", "cre"),
comment=c(ORCID = "0000-0002-3171-0844", what="Rewrite functions with Rcpp, plus new features")
Expand Down Expand Up @@ -49,7 +49,7 @@ Suggests:
survival
VignetteBuilder: knitr
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Encoding: UTF-8
URL: https://github.com/USCCANA/netdiffuseR,
https://USCCANA.github.io/netdiffuseR
Expand Down
16 changes: 10 additions & 6 deletions R/adjmat.r
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,16 @@ toa_mat <- function(obj, labels=NULL, t0=NULL, t1=NULL) {
if (!length(t1)) t1 <- max(obj, na.rm = TRUE)
}

ans <- switch(class(obj),
numeric = toa_mat.numeric(obj, labels, t0, t1),
integer = toa_mat.integer(obj, labels, t0, t1),
diffnet = with(obj, list(adopt=adopt,cumadopt=cumadopt)),
stopifnot_graph(obj)
)
cls <- class(obj)
ans <- if ("numeric" %in% cls) {
toa_mat.numeric(obj, labels, t0, t1)
} else if ("integer" %in% cls) {
toa_mat.integer(obj, labels, t0, t1)
} else if ("diffnet" %in% cls) {
with(obj, list(adopt=adopt,cumadopt=cumadopt))
} else
stopifnot_graph(obj)


if (inherits(obj, "diffnet")) {
dimnames(ans$adopt) <- with(obj$meta, list(ids,pers))
Expand Down
107 changes: 65 additions & 42 deletions R/diffnet-methods.r
Original file line number Diff line number Diff line change
Expand Up @@ -1525,16 +1525,22 @@ as.array.diffnet <- function(x, ...) {
#' nedges(graph_mat)
#' nedges(graph_dgCMatrix)
nvertices <- function(graph) {
switch(class(graph),
array = nrow(graph),
matrix = nrow(graph),
dgCMatrix = nrow(graph),
list = nrow(graph[[1]]),
diffnet = graph$meta$n,
igraph = igraph::vcount(graph),
network = network::network.size(graph),
stopifnot_graph(graph)
)

cls <- class(graph)

if (any(c("array", "matrix", "dgCMatrix") %in% cls)) {
nrow(graph)
} else if ("list" %in% cls) {
nrow(graph[[1]])
} else if ("diffnet" %in% cls) {
graph$meta$n
} else if ("igraph" %in% cls) {
igraph::vcount(graph)
} else if ("network" %in% cls) {
network::network.size(graph)
} else
stopifnot_graph(graph)

}

#' @rdname nvertices
Expand All @@ -1544,32 +1550,41 @@ nnodes <- nvertices
#' @export
#' @rdname nvertices
nedges <- function(graph) {
switch (class(graph),
array = {
# Computing and coercing into a list
x <- as.list(apply(graph, 3, function(x) sum(x!=0)))

# Naming
tnames <- names(x)
if (!length(tnames)) names(x) <- 1:length(x)
x
},
matrix = sum(graph != 0),
dgCMatrix = length(graph@i),
list = {
# Computing
x <- lapply(graph, function(x) length(x@i))

# Naming
tnames <- names(x)
if (!length(tnames)) names(x) <- 1:length(x)
x
},
diffnet = lapply(graph$graph, function(x) sum(x@x != 0)),
igraph = igraph::ecount(graph),
network = network::network.edgecount(graph),

cls <- class(graph)

if ("matrix" %in% cls) {
sum(graph != 0)
} else if ("array" %in% cls) {
# Computing and coercing into a list
x <- as.list(apply(graph, 3, function(x) sum(x!=0)))

# Naming
tnames <- names(x)
if (!length(tnames)) names(x) <- 1:length(x)
x

} else if ("dgCMatrix" %in% cls) {
length(graph@i)
} else if ("list" %in% cls) {

# Computing
x <- lapply(graph, function(x) length(x@i))

# Naming
tnames <- names(x)
if (!length(tnames)) names(x) <- 1:length(x)
x

} else if ("diffnet" %in% cls) {
lapply(graph$graph, function(x) sum(x@x != 0))
} else if ("igraph" %in% cls) {
igraph::ecount(graph)
} else if ("network" %in% cls) {
network::network.edgecount(graph)
} else
stopifnot_graph(graph)
)

}

#' @export
Expand All @@ -1579,14 +1594,22 @@ nlinks <- nedges
#' @export
#' @rdname nvertices
nslices <- function(graph) {
switch (class(graph),
array = dim(graph)[3],
matrix = 1L,
dgCMatrix = 1L,
diffnet = graph$meta$nper,
list = length(graph),

cls <- class(graph)

if ("matrix" %in% cls) {
1L
} else if ("array" %in% cls) {
dim(graph)[3]
} else if ("dgCMatrix" %in% cls) {
1L
} else if ("diffnet" %in% cls) {
graph$meta$nper
} else if ("list" %in% cls) {
length(graph)
} else
stopifnot_graph(graph)
)

}

#' @export
Expand Down
32 changes: 19 additions & 13 deletions R/egonets.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ egonet_attrs <- function(
1, " and ", nnodes(graph), ".")
}

switch(
class(graph),
diffnet = egonet_attrs.list(
cls <- class(graph)

if ("diffnet" %in% cls) {
egonet_attrs.list(
graph = graph$graph,
attrs = attrs,
V = V,
Expand All @@ -179,8 +180,9 @@ egonet_attrs <- function(
self = self,
valued = valued,
...
),
list = egonet_attrs.list(
)
} else if ("list" %in% cls) {
egonet_attrs.list(
graph = graph,
attrs = attrs,
V = V,
Expand All @@ -190,8 +192,9 @@ egonet_attrs <- function(
self = self,
valued = valued,
...
),
matrix = egonet_attrs.matrix(
)
} else if ("matrix" %in% cls) {
egonet_attrs.matrix(
graph = as_spmat(graph),
attrs = attrs,
V = V,
Expand All @@ -201,8 +204,9 @@ egonet_attrs <- function(
self = self,
valued = valued,
...
),
dgCMatrix = egonet_attrs.matrix(
)
} else if ("dgCMatrix" %in% cls) {
egonet_attrs.matrix(
graph = graph,
attrs = attrs,
V = V,
Expand All @@ -212,8 +216,9 @@ egonet_attrs <- function(
self = self,
valued = valued,
...
),
array = egonet_attrs.array(
)
} else if ("array" %in% cls) {
egonet_attrs.array(
graph = graph,
attrs = attrs,
V = V,
Expand All @@ -223,9 +228,10 @@ egonet_attrs <- function(
self = self,
valued = valued,
...
),
)
} else
stopifnot_graph(graph)
)

}

egonet_attrs.matrix <- function(graph, attrs, V, outer, fun, as.df, self, valued, ...) {
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template:
params:
ganalytics: UA-40608305-5

14 changes: 9 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
news:
netdiffuseR.tar.gz: */*.R
rm netdiffuseR.tar.gz ; \
R CMD build . && \
mv netdiffuseR*.tar.gz netdiffuseR.tar.gz

inst/NEWS: NEWS.md
Rscript -e "rmarkdown::pandoc_convert('NEWS.md', 'plain', output='inst/NEWS')"&& \
head -n 80 inst/NEWS
check:
cd ..&&R CMD build netdiffuseR/ && \
R CMD check --as-cran netdiffuseR*.tar.gz
check: netdiffuseR.tar.gz
R CMD check --as-cran netdiffuseR.tar.gz

checkv:
checkv: netdiffuseR.tar.gz
cd ..&&R CMD build netdiffuseR/ && \
R CMD check --as-cran --use-valgrind netdiffuseR*.tar.gz

13 changes: 8 additions & 5 deletions man/as.array.diffnet.Rd

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

39 changes: 27 additions & 12 deletions man/bass.Rd

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

Loading

0 comments on commit 5b3bbfb

Please sign in to comment.