From 49e67b9164416729040091af5e6d74c1ff373511 Mon Sep 17 00:00:00 2001 From: James Hollway Date: Wed, 8 Dec 2021 14:02:03 +0100 Subject: [PATCH 1/8] Removed ggraphgrid documentation --- R/ggraphgrid.R | 1 + man/ggraphgrid.Rd | 29 ----------------------------- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 man/ggraphgrid.Rd diff --git a/R/ggraphgrid.R b/R/ggraphgrid.R index d41c4e04..578bbb23 100644 --- a/R/ggraphgrid.R +++ b/R/ggraphgrid.R @@ -1,6 +1,7 @@ #' Plot graph to grid #' #' For quick and easy graphing of networks to a grid plot +#' @noRd #' @details The function uses approximate pattern matching #' to redistributes the coarse layouts on the square grid points, while #' preserving the topological relationships among the nodes (see Inoue et al. 2012). diff --git a/man/ggraphgrid.Rd b/man/ggraphgrid.Rd deleted file mode 100644 index 077c27b7..00000000 --- a/man/ggraphgrid.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ggraphgrid.R -\name{ggraphgrid} -\alias{ggraphgrid} -\title{Plot graph to grid} -\usage{ -ggraphgrid(x, algorithm = c("kk", "fr")) -} -\arguments{ -\item{x}{A migraph-consistent network/graph} - -\item{algorithm}{An initial network layout, -currently either Kamada-Kawai ("kk") or -Fruchterman-Reingold ("fr")} -} -\description{ -For quick and easy graphing of networks to a grid plot -} -\details{ -The function uses approximate pattern matching -to redistributes the coarse layouts on the square grid points, while -preserving the topological relationships among the nodes (see Inoue et al. 2012). -} -\references{ -Inoue et al. (2012). -Application of Approximate Pattern Matching in Two Dimensional -Spaces to Grid Layout for Biochemical Network Maps. -PLoS One 7 (6): e37739. doi: https://doi.org/10.1371/journal.pone.0037739. -} From ea477e82737e418d87ce171a760ea9c2272a1057 Mon Sep 17 00:00:00 2001 From: BBieri Date: Wed, 8 Dec 2021 16:48:43 +0100 Subject: [PATCH 2/8] Removed unnecessary header argument in read import functions It was throwing an error preventing imports --- R/read.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/read.R b/R/read.R index 8ded340c..226abd67 100644 --- a/R/read.R +++ b/R/read.R @@ -73,7 +73,7 @@ read_edgelist <- function(file = file.choose(), out <- read.csv2(file, header = TRUE, ...) # For EU } } else if (grepl("xlsx$|xls$", file)) { - out <- readxl::read_excel(file, header = TRUE, ...) + out <- readxl::read_excel(file, ...) } out } @@ -103,6 +103,7 @@ write_edgelist <- function(object, #' @export read_nodelist <- function(file = file.choose(), sv = c("comma", "semi-colon"), + ...){ sv <- match.arg(sv) if (grepl("csv$", file)) { @@ -112,7 +113,7 @@ read_nodelist <- function(file = file.choose(), out <- read.csv2(file, header = TRUE, ...) # For EU } } else if (grepl("xlsx$|xls$", file)) { - out <- readxl::read_excel(file, header = TRUE, ...) + out <- readxl::read_excel(file, ...) } out } From 99d73e33088665671eaae86688b0cadc8f790923 Mon Sep 17 00:00:00 2001 From: BBieri Date: Wed, 8 Dec 2021 18:16:41 +0100 Subject: [PATCH 3/8] Fixed some issues with as_network.igraph mentionned in #173 --- R/as.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/as.R b/R/as.R index 7c917776..8fc0b6ba 100644 --- a/R/as.R +++ b/R/as.R @@ -348,13 +348,16 @@ as_network.network <- function(object) { #' @export as_network.matrix <- function(object) { - # Convert to adjacency matrix - out <- to_multilevel(object) + # Convert to adjacency matrix if not square already + if (nrow(object) != ncol(object)) { + out <- to_multilevel(object) + } else out <- object network::as.network(out, directed = is_directed(object), bipartite = ifelse(is_twomode(object), nrow(object), FALSE), + loops = ifelse(sum(diag(out)) > 0, TRUE, FALSE), ignore.eval = ifelse(is_weighted(object), FALSE, TRUE), names.eval = ifelse(is_weighted(object), @@ -365,7 +368,8 @@ as_network.matrix <- function(object) { as_network.igraph <- function(object) { name <- type <- NULL attr <- as.data.frame(igraph::get.vertex.attribute(object)) - attr <- subset(attr, select = c(-name, -type)) + if ("name" %in% colnames(attr)) attr <- subset(attr, select = c(-name)) + if ("type" %in% colnames(attr)) attr <- subset(attr, select = c(-type)) out <- as_network(as_matrix(object, weight = is_weighted(object))) if (length(attr) > 0) { out <- network::set.vertex.attribute(out, names(attr), attr) From e61965118ef013c09588de00b20dc0c391af8a1f Mon Sep 17 00:00:00 2001 From: BBieri Date: Fri, 10 Dec 2021 10:14:25 +0100 Subject: [PATCH 4/8] Bumped version and date --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ba396abb..59cc4863 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: migraph Title: Multimodal and Multilevel Network Analysis -Version: 0.8.10 -Date: 2021-12-08 +Version: 0.8.11 +Date: 2021-12-10 Description: A set of tools that extend common social network analysis packages for analysing multimodal and multilevel networks. It includes functions for one- and two-mode (and sometimes three-mode) From 24e317387d1494a886c865898760b2e5075dbfaa Mon Sep 17 00:00:00 2001 From: BBieri Date: Fri, 10 Dec 2021 10:14:38 +0100 Subject: [PATCH 5/8] Updated NEWS --- NEWS.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NEWS.md b/NEWS.md index ffb26da7..15028656 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# migraph 0.8.11 + +## Import and export +- Fixed #172 by removing redundant header argument in `read_nodelist()` and + `read_edgelist()` + +## Package +- Fixed #173 by extending `as_network()` method to convert correctly form + an `{igraph}` to a `{network}` object. + # migraph 0.8.10 ## Import and export From 05dd4d1db8effae1faa4f10e0caf6a7b2d7b180b Mon Sep 17 00:00:00 2001 From: BBieri Date: Fri, 10 Dec 2021 10:18:22 +0100 Subject: [PATCH 6/8] Aligned NEWS with PR description --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 15028656..2b1a8c12 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ ## Package - Fixed #173 by extending `as_network()` method to convert correctly form an `{igraph}` to a `{network}` object. +- Removed `ggraphgrid()` documentation # migraph 0.8.10 From b39c2d19f565cb1dbed4b5c9f340906f655695fa Mon Sep 17 00:00:00 2001 From: BBieri Date: Fri, 10 Dec 2021 10:34:07 +0100 Subject: [PATCH 7/8] Fixed an odd test --- tests/testthat/test-to.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-to.R b/tests/testthat/test-to.R index 129dfb48..cbfc5835 100644 --- a/tests/testthat/test-to.R +++ b/tests/testthat/test-to.R @@ -56,8 +56,8 @@ test_that("to_undirected works",{ ((as_matrix(ison_coleman) + t(as_matrix(ison_coleman))) > 0) * 1) expect_equal(to_undirected(as_matrix(southern_women)), as_matrix(southern_women)) - expect_equal(unname(as_matrix(to_undirected(as_network(ison_coleman)))[1, ]), - c(rep(0,9),1,rep(0,6))) + expect_equal(as_matrix(to_undirected(as_network(ison_coleman))), + as_matrix(to_undirected(ison_coleman))) }) test_that("to_onemode works",{ From d43f9f55387615971978c5a4cecebc16d5186779 Mon Sep 17 00:00:00 2001 From: Jael Tan Date: Fri, 10 Dec 2021 12:32:42 +0100 Subject: [PATCH 8/8] Added tests for 'grab' functions --- tests/testthat/test-grab.R | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-grab.R b/tests/testthat/test-grab.R index 47bd3de0..35b86df1 100644 --- a/tests/testthat/test-grab.R +++ b/tests/testthat/test-grab.R @@ -4,7 +4,11 @@ net <- as_tidygraph(data.frame(from = c("A", "B", "C", "D","E"), net2 <- as_tidygraph(data.frame(from = c("A", "B", "C", "D","E"), to = c("B", "C", "D", "E", "A"))) %>% - dplyr::mutate(friends = c("yes", "yes", "no", "no", "yes")) + dplyr::mutate(friends = c("yes", "yes", "no", "no", "yes")) %>% + igraph::set_edge_attr("weight", value = 1:5) + +net3 <- as_matrix(data.frame(from = c("A", "A", "B", "C", "D", "D", "E", "E"), + to = c("B", "G", "C", "D", "E", "G", "A", "H"))) name <- c("Lisa", "John", "Lily", "Ben", "Adam") @@ -12,10 +16,20 @@ friends <- c("yes", "yes", "no", "no", "yes") test_that("node_names works", { expect_equal(node_names(net), name) + expect_length(node_names(net), 5) }) test_that("node_attribute works", { expect_equal(node_attribute(net2, "friends"), friends) + expect_length(node_attribute(net2, "friends"), igraph::vcount(net2)) +}) + +test_that("edge_attribute works", { + expect_equal(edge_attribute(net2, "weight"), c(1, 2, 3, 4, 5)) +}) + +test_that("edge_weights works", { + expect_equal(edge_weights(net2), edge_attribute(net2, "weight")) }) test_that("graph_nodes works", { @@ -25,3 +39,9 @@ test_that("graph_nodes works", { test_that("graph_edges works", { expect_false(graph_edges(net)==10) }) + +test_that("graph_dims works", { + expect_equal(graph_dims(net3), c(5, 7)) + expect_length(graph_dims(net3), 2) + expect_false(length(graph_dims(net3)) == 1) +})