Skip to content

Commit

Permalink
Still working on cran release
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jul 7, 2016
1 parent 21b7499 commit 5dc4343
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 81 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2016-07-07 George G. Vega Yon <[email protected]>
* R/diffnet-indexing.R: Adding method for [[.diffnet <- NULL
* tests/testthat/*: Adding more tests + small changes to reduce time.

2016-07-06 George G. Vega Yon <[email protected]>
* R/struc_test.R: Changing defaults in n_rewires.

2016-06-26 George G. Vega Yon <[email protected]>
* R/egonets.R: Fixing small bug on the matrix methods
* R/diffnet-methods.R: No actual significant changes
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: netdiffuseR
Title: Network Analysis for Diffusion of Innovations
Version: 1.16.6
Date: 2016-06-21
Version: 1.16.7
Date: 2016-07-07
Authors@R: c(
person("George", "Vega Yon", email="[email protected]", role=c("aut", "cre"), comment="Rewrite functions with Rcpp, plus new features"),
person("Stephanie", "Dyal", email="[email protected]", role=c("aut"), comment="Package's first version"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changes in netdiffuseR version 1.16.6 (2016-06-21)
# Changes in netdiffuseR version 1.16.7 (2016-07-07)

## Bug fixes

Expand Down
29 changes: 28 additions & 1 deletion R/diffnet-indexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,34 @@ diffnet_check_attr_class <- function(value, meta) {
# Checking and preparing the data
meta <- x$meta
if (length(j) < meta$n) meta$n <- length(j)
value <- diffnet_check_attr_class(value, meta)
if (length(value)) value <- diffnet_check_attr_class(value, meta)
else {

if (i %in% colnames(x$vertex.static.attrs)) {

# Static case
tokeep <- colnames(x$vertex.static.attrs)
tokeep <- tokeep[which(tokeep != i)]
x$vertex.static.attrs <- subset(x$vertex.static.attrs, select=tokeep)
return(x)

} else if (i %in% colnames(x$vertex.dyn.attrs[[1]])) {

# Dynamic case
tokeep <- colnames(x$vertex.dyn.attrs[[1]])
tokeep <- tokeep[which(tokeep != i)]
x$vertex.dyn.attrs <-
lapply(x$vertex.dyn.attrs, subset, select=tokeep)
return(x)
} else {

# Nothing case
warning('There is no attribute called -',i,'-. Returning the diffnet intact.')
return(x)
}


}

# Adding the attribute
if (!inherits(value, "list")) {
Expand Down
4 changes: 2 additions & 2 deletions R/struct_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
#' @examples
#' # Creating a random graph
#' set.seed(881)
#' diffnet <- rdiffnet(300, 5, seed.graph="small-world")
#' diffnet <- rdiffnet(100, 5, seed.graph="small-world")
#'
#' # Testing structure-dependency of threshold
#' res <- struct_test(diffnet, function(g) mean(threshold(g), na.rm=TRUE), R=50)
#' res <- struct_test(diffnet, function(g) mean(threshold(g), na.rm=TRUE), R=100)
#' res
#' hist(res)
#'
Expand Down
23 changes: 7 additions & 16 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
## Test environments
* Local Ubuntu 14.04, R version 3.3.0 (2016-05-03)
* Ubuntu 12.04.5 LTS (on travis-ci), R version 3.3.0 (2016-05-03).
* Windows Server 2012 R2 x64 (on AppVeyor), R Under development (3.2.5 Patched (2016-04-18 r70556).
* OS X 10.9.5 (Mavericks) (on travis-ci), R version 3.2.4 (2016-03-10).

* Local Ubuntu 14.04, R version 3.3.1 (2016-06-21).
* Ubuntu 12.04.5 LTS (on travis-ci), version 3.3.1 (2016-06-21).
* Windows Server 2012 R2 x64 (on AppVeyor), R version 3.3.1 Patched (2016-06-28 r70858).
* OS X 10.9.5 (Mavericks) (on travis-ci), R version 3.3.1 (2016-06-21).

## R CMD check results

0 errors | 0 warnings | 1 note

* Possible invalid URLs in man/rgraph_ws.Rd is false positive.
* Install size > 1Mb in libs. Using Rcpp increases the size. Still, working on
reducing it.
* Also, possible mis-spelled words in DESCRIPTION have the correct spelling.
* CRAN repository db overrides: X-CRAN-Comment: Archived on 2016-05-02 as ...
fixed (see below).
* Possible invalid URLs in man/rgraph_ws.Rd is false positive.

## Reverse dependencies

Expand All @@ -23,13 +22,5 @@ There are no reverse dependencies.

This is a resubmission. In this version I have:

* Included rgb (grDevices), polygon (graphics) and setNames (stats) as importFrom
in the package's NAMESPACE.
* Fixed the problem with "Vignette sources missing".
* About "Memtest notes: clang-UBSAN valgrind", the issue was actually a bug in
RcppArmadillo. This has been solved in RcppArmadillo v 0.6.700.6.0 (which is
already on CRAN). R CMD check --use-valgrind no longer reports memory leaks
or 'Conditional jump...' issues.
* Updated tests in testthat/*.R following the testthat package update (all passing).
(Fixed errors that caused CRAN archiving the previous version).
* Reduced the times on examples, tests and vignettes as requested by CRAN.

2 changes: 1 addition & 1 deletion inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


CHANGES IN NETDIFFUSER VERSION 1.16.6 (2016-06-21)
CHANGES IN NETDIFFUSER VERSION 1.16.7 (2016-07-07)


Bug fixes
Expand Down
8 changes: 3 additions & 5 deletions man/struct_test.Rd

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

35 changes: 26 additions & 9 deletions tests/testthat/test-diffnet-methods.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
context("Plotting functions 1 (plot_diffnet, threshold, and exposure)")

################################################################################
# plot_diffnet
################################################################################
# plot_diffnet -----------------------------------------------------------------

test_that("Should return coords of dim n x 2 (plot_diffnet)", {
# Creating the graph
Expand All @@ -28,9 +26,7 @@ test_that("Should return coords of dim n x 2 (plot_diffnet)", {
expect_equal(dim(coords), c(11,2), info = "applying to diffnet")
})

################################################################################
# plot_threshold, threshold and exposure
################################################################################
# plot_threshold, threshold and exposure ---------------------------------------

test_that("Returning threshold equal to the threshold fun (plot_threshold and )", {
# Generating a random graph
Expand Down Expand Up @@ -66,9 +62,8 @@ test_that("Returning threshold equal to the threshold fun (plot_threshold and )"
expect_equivalent(th, thdn)
})

################################################################################
# plot_infectsuscept, infection, susceptibility
################################################################################
# plot_infectsuscept, infection, susceptibility --------------------------------


test_that("Returning threshold equal to the infect/suscept funs", {
# Generating a random graph
Expand Down Expand Up @@ -129,3 +124,25 @@ test_that("summary.diffnet with slices", {
}
})

# Concatenating diffnet --------------------------------------------------------
test_that('concatenating diffnet', {

# Spliting and putting together
index <- medInnovationsDiffNet[['city']]<2
mi1 <- medInnovationsDiffNet[which(index)]
mi2 <- medInnovationsDiffNet[which(!index)]

mi <- c(mi1, mi2)
test <- all(mapply(identical, mi$graph, medInnovationsDiffNet$graph))

expect_true(test)

# Errors
expect_error(c(mi1, 1), 'Some objects are not of class')
expect_error(c(mi1, mi1), 'No pair of diffnets')
expect_error(c(mi1[,,1:4], mi2), 'same time range')
# mi1less <- mi1[['city']] <- NULL
# colnames(mi1less)
# expect_error(c())

})
84 changes: 42 additions & 42 deletions tests/testthat/test-stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,45 @@ test_that("exposure calculations", {
# expect_equivalent(exp_1_diffnet, exp_1_manual)
})

# test_that("Times of Adoption", {
# # Creating the data
# set.seed(13131)
# toa <- sample(c(NA, 1:10), 100, TRUE)
#
# toa_mat2 <- function(
# times, labels=NULL,
# t0=min(times, na.rm=TRUE), t1=max(times, na.rm=TRUE)) {
#
# # Counting number of rows
# n <- length(times)
#
# # Checking names
# if (length(labels)) rn <- labels
# else {
# rn <- names(times)
# if (!length(rn)) rn <- 1:n
# }
#
# cn <- t0:t1
#
# # Computing
# m <- matrix(0, nrow=n, ncol= t1-t0 + 1, dimnames = list(rn, cn))
# m[cbind(cn, times - t0 + 1)] <- 1
# m <- list(adopt=m, cumadopt=t(apply(m, 1, cumsum)))
#
# # Assigning names
# dimnames(m[[2]]) <- dimnames(m[[1]])
#
# m
# }
#
# expect_equal(toa_mat(toa), toa_mat2(toa))
# # library(microbenchmark)
# # tm1 <- toa_mat(toa)
# # tm2 <- toa_mat2(toa)
# #
# # microbenchmark(
# # toa_mat(toa),
# # toa_mat2(toa), times = 1
# # )
# })
test_that("Times of Adoption", {
# Creating the data
set.seed(13131)
toa <- sample(c(NA, 1:10), 100, TRUE)

toa_mat2 <- function(
times, labels=NULL,
t0=min(times, na.rm=TRUE), t1=max(times, na.rm=TRUE)) {

# Counting number of rows
n <- length(times)

# Checking names
if (length(labels)) rn <- labels
else {
rn <- names(times)
if (!length(rn)) rn <- 1:n
}

cn <- t0:t1

# Computing
m <- matrix(0, nrow=n, ncol= t1-t0 + 1, dimnames = list(rn, cn))
m[cbind(rn, times - t0 + 1)] <- 1
m <- list(adopt=m, cumadopt=t(apply(m, 1, cumsum)))

# Assigning names
dimnames(m[[2]]) <- dimnames(m[[1]])

m
}

expect_equal(toa_mat(toa), toa_mat2(toa))
# library(microbenchmark)
# tm1 <- toa_mat(toa)
# tm2 <- toa_mat2(toa)
#
# microbenchmark(
# toa_mat(toa),
# toa_mat2(toa), times = 1000
# )
})
7 changes: 5 additions & 2 deletions tests/testthat/test-struct_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ test_that("struct_test should be reproducible (serial version)", {

test_that("struct_test should be reproducible (parallel version)", {

# I don't want to run this test
skip_on_cran()

# Generating data
set.seed(1231)
graph <- rdiffnet(150, 5, seed.graph = "small-world")
Expand All @@ -27,11 +30,11 @@ test_that("struct_test should be reproducible (parallel version)", {
# RNG algorithm to be L'Ecuyer so the sequences can be reproduced

N <- 100
set.seed(123, "L'Ecuyer-CMRG")
set.seed(123, "L'Ecuyer")
b1 <- struct_test(graph, function(x) mean(threshold(x), na.rm = TRUE), R=N, ncpus=2,
parallel="multicore")

set.seed(123, "L'Ecuyer-CMRG")
set.seed(123, "L'Ecuyer")
b2 <- struct_test(graph, function(x) mean(threshold(x), na.rm = TRUE), R=N, ncpus=2,
parallel="multicore")

Expand Down

0 comments on commit 5dc4343

Please sign in to comment.