From 5dc4343ff54036a4fc6373f9993c684540bfe3fd Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Jul 2016 14:22:48 -0700 Subject: [PATCH] Still working on cran release --- ChangeLog | 7 +++ DESCRIPTION | 4 +- NEWS.md | 2 +- R/diffnet-indexing.R | 29 ++++++++- R/struct_test.R | 4 +- cran-comments.md | 23 +++----- inst/NEWS | 2 +- man/struct_test.Rd | 8 +-- tests/testthat/test-diffnet-methods.R | 35 ++++++++--- tests/testthat/test-stats.R | 84 +++++++++++++-------------- tests/testthat/test-struct_test.R | 7 ++- 11 files changed, 124 insertions(+), 81 deletions(-) diff --git a/ChangeLog b/ChangeLog index da476d5..6d3116c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-07-07 George G. Vega Yon + * 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 + * R/struc_test.R: Changing defaults in n_rewires. + 2016-06-26 George G. Vega Yon * R/egonets.R: Fixing small bug on the matrix methods * R/diffnet-methods.R: No actual significant changes diff --git a/DESCRIPTION b/DESCRIPTION index 557d2a0..2d7ec61 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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="g.vegayon@gmail.com", role=c("aut", "cre"), comment="Rewrite functions with Rcpp, plus new features"), person("Stephanie", "Dyal", email="stepharp@usc.edu", role=c("aut"), comment="Package's first version"), diff --git a/NEWS.md b/NEWS.md index c72c9e6..2004bc7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/diffnet-indexing.R b/R/diffnet-indexing.R index e5953ed..e4f86da 100644 --- a/R/diffnet-indexing.R +++ b/R/diffnet-indexing.R @@ -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")) { diff --git a/R/struct_test.R b/R/struct_test.R index 797dacf..e53aab6 100644 --- a/R/struct_test.R +++ b/R/struct_test.R @@ -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) #' diff --git a/cran-comments.md b/cran-comments.md index 2790e1b..e311355 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -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 @@ -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. diff --git a/inst/NEWS b/inst/NEWS index 3b3f8ad..319f2d7 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -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 diff --git a/man/struct_test.Rd b/man/struct_test.Rd index d789cde..c69a672 100644 --- a/man/struct_test.Rd +++ b/man/struct_test.Rd @@ -105,10 +105,10 @@ are performed in each iteration. \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) @@ -121,9 +121,7 @@ legend("topright", bty="n", ) # Concatenating results -res2 <- struct_test(diffnet, function(g) mean(threshold(g), na.rm=TRUE), R=50) - -c(res, res2) +c(res, res) # Running in parallel fashion \dontrun{ diff --git a/tests/testthat/test-diffnet-methods.R b/tests/testthat/test-diffnet-methods.R index aea99e1..6f5fc52 100644 --- a/tests/testthat/test-diffnet-methods.R +++ b/tests/testthat/test-diffnet-methods.R @@ -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 @@ -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 @@ -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 @@ -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()) + +}) diff --git a/tests/testthat/test-stats.R b/tests/testthat/test-stats.R index 30fd383..2425400 100644 --- a/tests/testthat/test-stats.R +++ b/tests/testthat/test-stats.R @@ -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 + # ) +}) diff --git a/tests/testthat/test-struct_test.R b/tests/testthat/test-struct_test.R index 9c3879f..535f0fd 100644 --- a/tests/testthat/test-struct_test.R +++ b/tests/testthat/test-struct_test.R @@ -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") @@ -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")