Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3.1 #102

Merged
merged 12 commits into from
Oct 29, 2024
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: manynet
Title: Many Ways to Make, Modify, Map, Mark, and Measure Myriad Networks
Version: 1.3.0
Date: 2024-10-16
Version: 1.3.1
Date: 2024-10-29
Description: Many tools for making, modifying, mapping, marking, measuring,
and motifs and memberships of many different types of networks.
All functions operate with matrices, edge lists, and 'igraph', 'network', and 'tidygraph' objects,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ S3method(to_signed,igraph)
S3method(to_signed,matrix)
S3method(to_signed,network)
S3method(to_signed,tbl_graph)
S3method(to_simplex,data.frame)
S3method(to_simplex,igraph)
S3method(to_simplex,matrix)
S3method(to_simplex,network)
S3method(to_simplex,tbl_graph)
S3method(to_slices,igraph)
S3method(to_slices,tbl_graph)
Expand Down Expand Up @@ -651,6 +653,7 @@ export(node_triad_census)
export(node_vitality)
export(node_walktrap)
export(node_weak_components)
export(over_membership)
export(over_time)
export(over_waves)
export(pkg_data)
Expand Down Expand Up @@ -854,6 +857,7 @@ importFrom(igraph,as.undirected)
importFrom(igraph,as_adjacency_matrix)
importFrom(igraph,as_biadjacency_matrix)
importFrom(igraph,as_data_frame)
importFrom(igraph,as_directed)
importFrom(igraph,assortativity_degree)
importFrom(igraph,bipartite_projection)
importFrom(igraph,cohesion)
Expand Down
24 changes: 24 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# manynet 1.3.1

## Package

- Fixed miscellaneous documentation issues, re roxygen
- Separated out the data sections in pkgdown

## Modifying

- Added `to_simplex.data.frame()` and `to_simplex.network()`

## Marking

- Fixed bug in `is_aperiodic()` where it would not work in tutorial chunks

## Measuring

- Added `over_membership()` for obtaining summary statistics by a membership vector

## Practicing

- Fixed data pointers in several tutorials
- Added glossary items to diffusion tutorial

# manynet 1.3.0

## Package
Expand Down
3 changes: 2 additions & 1 deletion R/make_generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ generate_fire <- function(n, contacts = 1, their_out = 0, their_in = 1, directed
#' @examples
#' generate_islands(10)
#' @export
generate_islands <- function(n, islands = 2, p = 0.5, bridges = 1, directed = FALSE){
generate_islands <- function(n, islands = 2, p = 0.5, bridges = 1,
directed = FALSE){
directed <- infer_directed(n, directed)
if(is_manynet(n)){
m <- net_nodes(n)
Expand Down
15 changes: 11 additions & 4 deletions R/manip_as.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@
#' @return
#' The currently implemented coercions or translations are:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("as_edgelist","as_matrix", "as_igraph", "as_tidygraph",
#' "as_network", "as_siena", "as_graphAM", "as_diffusion", "as_diffnet")))
#' ```
#' | | data.frame| diff_model| diffnet| igraph| list| matrix| network| network.goldfish| siena| tbl_graph|
#' |:------------|----------:|----------:|-------:|------:|----:|------:|-------:|----------------:|-----:|---------:|
#' |as_diffnet | 0| 1| 0| 0| 0| 0| 0| 0| 0| 0|
#' |as_diffusion | 0| 1| 1| 1| 0| 0| 0| 0| 0| 0|
#' |as_edgelist | 1| 0| 0| 1| 0| 1| 1| 1| 1| 1|
#' |as_graphAM | 1| 0| 0| 1| 0| 1| 1| 1| 1| 1|
#' |as_igraph | 1| 1| 1| 1| 0| 1| 1| 1| 1| 1|
#' |as_matrix | 1| 1| 0| 1| 0| 1| 1| 1| 1| 1|
#' |as_network | 1| 0| 1| 1| 0| 1| 1| 1| 1| 1|
#' |as_siena | 0| 0| 0| 1| 0| 0| 0| 0| 0| 1|
#' |as_tidygraph | 1| 1| 1| 1| 1| 1| 1| 1| 1| 1|
NULL

# Nodelists ####
Expand Down
66 changes: 45 additions & 21 deletions R/manip_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_undirected", "to_unweighted",
#' "to_unsigned", "to_unnamed", "to_simplex", "to_uniplex")))
#' ```
#' | | data.frame| igraph| matrix| network| tbl_graph|
#' |:-------------|----------:|------:|------:|-------:|---------:|
#' |to_simplex | 1| 1| 1| 1| 1|
#' |to_undirected | 1| 1| 1| 1| 1|
#' |to_uniplex | 1| 1| 1| 1| 1|
#' |to_unnamed | 1| 1| 1| 1| 1|
#' |to_unsigned | 1| 1| 1| 1| 1|
#' |to_unweighted | 1| 1| 1| 1| 1|
#' @inheritParams mark_is
#' @param threshold For a matrix, the threshold to binarise/dichotomise at.
#' @returns
Expand Down Expand Up @@ -96,12 +100,12 @@ to_undirected <- function(.data) UseMethod("to_undirected")
#' @importFrom igraph as.undirected
#' @export
to_undirected.igraph <- function(.data) {
igraph::as.undirected(.data)
igraph::as_undirected(.data)
}

#' @export
to_undirected.tbl_graph <- function(.data) {
as_tidygraph(igraph::as.undirected(.data))
as_tidygraph(igraph::as_undirected(.data))
}

#' @export
Expand Down Expand Up @@ -249,6 +253,17 @@ to_simplex.matrix <- function(.data) {
out
}

#' @export
to_simplex.data.frame <- function(.data) {
out <- .data[.data$from != .data$to,]
out
}

#' @export
to_simplex.network <- function(.data) {
as_network(to_simplex(as_igraph(.data)))
}

#' @rdname manip_deformat
#' @param tie Character string naming a tie attribute to retain from a graph.
#' @importFrom igraph delete_edges edge_attr_names delete_edge_attr
Expand Down Expand Up @@ -311,9 +326,12 @@ to_uniplex.matrix <- function(.data, tie){
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_acyclic", "to_anti", "to_redirected", "to_reciprocated")))
#' ```
#' | | data.frame| igraph| matrix| network| tbl_graph|
#' |:---------------|----------:|------:|------:|-------:|---------:|
#' |to_acyclic | 1| 1| 1| 1| 1|
#' |to_anti | 1| 1| 1| 1| 1|
#' |to_reciprocated | 1| 1| 1| 1| 1|
#' |to_redirected | 1| 1| 1| 1| 1|
#' @name manip_reformat
#' @family modifications
#' @inheritParams mark_is
Expand All @@ -325,15 +343,15 @@ to_uniplex.matrix <- function(.data, tie){
NULL

#' @rdname manip_reformat
#' @importFrom igraph as.directed feedback_arc_set
#' @importFrom igraph as_directed feedback_arc_set
#' @export
to_acyclic <- function(.data) UseMethod("to_acyclic")

#' @export
to_acyclic.igraph <- function(.data) {
if(is_directed(.data)){
delete_ties(.data, igraph::feedback_arc_set(.data))
} else igraph::as.directed(.data, mode = "acyclic")
} else igraph::as_directed(.data, mode = "acyclic")
}

#' @export
Expand Down Expand Up @@ -436,13 +454,13 @@ to_redirected.network <- function(.data) {
}

#' @describeIn manip_reformat Returns an object where all ties are reciprocated.
#' @importFrom igraph as.directed
#' @importFrom igraph as_directed
#' @export
to_reciprocated <- function(.data) UseMethod("to_reciprocated")

#' @export
to_reciprocated.igraph <- function(.data) {
igraph::as.directed(.data, mode = "mutual")
igraph::as_directed(.data, mode = "mutual")
}

#' @export
Expand Down Expand Up @@ -493,10 +511,14 @@ to_reciprocated.data.frame <- function(.data) {
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_directed", "to_redirected",
#' "to_reciprocated", "to_acyclic", "to_named", "to_simplex")))
#' ```
#' | | data.frame| igraph| matrix| network| tbl_graph|
#' |:---------------|----------:|------:|------:|-------:|---------:|
#' |to_acyclic | 1| 1| 1| 1| 1|
#' |to_directed | 1| 1| 1| 1| 1|
#' |to_named | 1| 1| 1| 1| 1|
#' |to_reciprocated | 1| 1| 1| 1| 1|
#' |to_redirected | 1| 1| 1| 1| 1|
#' |to_simplex | 0| 1| 1| 0| 1|
#' @name manip_preformat
#' @family modifications
#' @inheritParams mark_is
Expand Down Expand Up @@ -588,7 +610,7 @@ to_directed <- function(.data) UseMethod("to_directed")
to_directed.igraph <- function(.data) {
if(!is_directed.igraph(.data)){
mnet_info("Directions are assigned to existing ties at random.")
igraph::as.directed(.data, mode = "random")
igraph::as_directed(.data, mode = "random")
} else .data
}

Expand Down Expand Up @@ -710,9 +732,11 @@ to_weighted.network <- function(.data, measure = NULL){
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_onemode", "to_twomode", "to_multilevel")))
#' ```
#' | | igraph| matrix| network| tbl_graph|
#' |:-------------|------:|------:|-------:|---------:|
#' |to_multilevel | 1| 1| 0| 1|
#' |to_onemode | 1| 1| 0| 1|
#' |to_twomode | 1| 0| 1| 1|
#' @name manip_levels
#' @family modifications
#' @inheritParams mark_is
Expand Down
7 changes: 4 additions & 3 deletions R/manip_nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("add_nodes", "delete_nodes", "add_node_attribute")))
#' ```
#' | | igraph| network| tbl_graph|
#' |:------------|------:|-------:|---------:|
#' |add_nodes | 1| 1| 1|
#' |delete_nodes | 1| 1| 1|
#' @family modifications
#' @inheritParams mark_is
#' @param attribute A named list to be added as tie or node attributes.
Expand Down
26 changes: 17 additions & 9 deletions R/manip_reformed.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_mode1", "to_mode2", "to_ties")))
#' ```
#' | | data.frame| igraph| matrix| network| tbl_graph|
#' |:--------|----------:|------:|------:|-------:|---------:|
#' |to_mode1 | 1| 1| 1| 1| 1|
#' |to_mode2 | 1| 1| 1| 1| 1|
#' |to_ties | 1| 1| 1| 1| 1|
#' @name manip_project
#' @family modifications
#' @inheritParams manip_reformat
Expand Down Expand Up @@ -222,9 +224,13 @@ to_ties.matrix <- function(.data){
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_ego", "to_giant", "to_no_isolates", "to_subgraph", "to_blocks")))
#' ```
#' | | data.frame| igraph| list| matrix| network| tbl_graph|
#' |:--------------|----------:|------:|----:|------:|-------:|---------:|
#' |to_blocks | 1| 1| 0| 1| 1| 1|
#' |to_ego | 0| 1| 0| 0| 0| 1|
#' |to_giant | 1| 1| 0| 1| 1| 1|
#' |to_no_isolates | 1| 1| 1| 1| 1| 1|
#' |to_subgraph | 1| 1| 0| 1| 1| 1|
#' @name manip_scope
#' @family modifications
#' @inheritParams manip_reformat
Expand Down Expand Up @@ -460,9 +466,11 @@ to_blocks.tbl_graph <- function(.data, membership, FUN = mean){
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_matching", "to_mentoring", "to_eulerian", "to_tree")))
#' ```
#' | | data.frame| igraph| matrix| network| tbl_graph|
#' |:------------|----------:|------:|------:|-------:|---------:|
#' |to_eulerian | 0| 1| 0| 0| 1|
#' |to_matching | 1| 1| 1| 1| 1|
#' |to_mentoring | 0| 1| 0| 0| 1|
#' @name manip_paths
#' @family modifications
#' @inheritParams manip_scope
Expand Down
14 changes: 9 additions & 5 deletions R/manip_split.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#' Not all functions have methods available for all object classes.
#' Below are the currently implemented S3 methods:
#'
#' ```{r, echo = FALSE, cache = TRUE}
#' knitr::kable(available_methods(c("to_egos", "to_subgraphs", "to_components", "to_waves", "to_slices")))
#' ```
#' | | data.frame| diff_model| igraph| matrix| network| tbl_graph|
#' |:-------------|----------:|----------:|------:|------:|-------:|---------:|
#' |to_components | 1| 0| 1| 1| 1| 1|
#' |to_egos | 1| 0| 1| 1| 1| 1|
#' |to_slices | 0| 0| 1| 0| 0| 1|
#' |to_subgraphs | 0| 0| 1| 0| 1| 1|
#' |to_waves | 1| 1| 1| 0| 0| 1|
#' @name manip_split
#' @family modifications
#' @inheritParams manip_scope
Expand All @@ -21,7 +25,7 @@ NULL
#' @importFrom igraph make_ego_graph
#' @examples
#' to_egos(ison_adolescents)
#' #autographs(to_egos(ison_adolescents,2))
#' # graphs(to_egos(ison_adolescents,2))
#' @export
to_egos <- function(.data,
max_dist = 1,
Expand Down Expand Up @@ -265,7 +269,7 @@ cumulative_ties <- function(x, attribute) {
}
}
} else {
message("Cummulative ties were added based on order of appearance for attribute.")
mnet_info("Cummulative ties were added based on order of appearance for attribute.")
a <- list()
for (k in unique(ties$order)) {
if (k != 1) {
Expand Down
10 changes: 6 additions & 4 deletions R/manynet-tutorials.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
NULL

#' @rdname tutorials
#' @examples
#' #run_tute("tutorial2")
#' @export
run_tute <- function(tute) {
thisRequires("learnr")
Expand Down Expand Up @@ -61,8 +59,6 @@ run_tute <- function(tute) {
}

#' @rdname tutorials
#' @examples
#' #extract_tute("tutorial2")
#' @export
extract_tute <- function(tute) {
if (missing(tute)) {
Expand Down Expand Up @@ -216,17 +212,22 @@ clear_glossary <- function(){

glossies <- list(
acyclic = "An acyclic network is a network without any cycles.",
aperiodic = "An aperiodic network is a network where the greatest common divisor of the lengths of its cycles is one.",
adhesion = "The minimum number of ties to remove to increase the number of components.",
blockmodel = "A blockmodel reduces a network to a smaller comprehensible structure of the roles positions take with respect to one another.",
bridge = "A bridge is a tie whose deletion increases the number of components.",
cohesion = "The minimum number of nodes to remove to increase the number of components.",
component = "A component is a connected subgraph not part of a larger connected subgraph.",
connected = "A connected network is one with a single (strong) component.",
cutpoint = "A cutpoint or articulation point is a node whose deletion increases the number of components.",
degree = "A node's degree is the number of connections it has.",
giant = "The giant component is the component that includes the most nodes in the network.",
graphlet = "A graphlet is a small, connected, induced, non-isomorphic subgraphs.",
hit = "A herd immunity threshold is the proportion of the population that would need to be immune for a disease to cease being endemic.",
induced = "An induced subgraph comprises all ties in a subset of the nodes in a network.",
intervention = "A network intervention is a process to accelerate behavioural change or improve performance in a network.",
lattice = "A network that can be drawn as a regular tiling.",
LTM = "A linear threshold model is a diffusion model where nodes are resistant to activation up to some threshold.",
motif = "A subgraph that is exceptional or significant compared to a null model.",
neighborhood = "A node's neighborhood is the set of other nodes to which that node is connected.",
network = "A network comprises a set of nodes/vertices and a set of ties/edges among them.",
Expand All @@ -235,6 +236,7 @@ glossies <- list(
reduced = "A reduced graph is a representation of the ties within and between blocks in the network.",
subgraph = "A subgraph comprises a subset of the nodes and ties in a network.",
transitivity = "Triadic closure is where if the connections A-B and A-C exist among three nodes, there is a tendency for B-C also to be formed.",
threshold = "A threshold is a limit over which behaviour is expected to vary.",
undirected = "An undirected network is one in which tie direction is undefined."
)

Loading
Loading