From 414ec61caee724e42c031020003be1cc2e17dc84 Mon Sep 17 00:00:00 2001
From: "Pavel N. Krivitsky"
Date: Wed, 11 Dec 2024 18:00:36 +1100
Subject: [PATCH] Made get.edgeIDs(), get.edges(), get.neighborhood(),
has.edges(), is.adjacent(), and network.density() generic.
---
NAMESPACE | 6 ++++++
R/access.R | 35 +++++++++++++++++++++++++++------
R/misc.R | 14 +++++++++++--
man/get.edges.Rd | 40 +++++++++++++++++++++++++++++++++++---
man/get.inducedSubgraph.Rd | 6 +++---
man/get.neighborhood.Rd | 7 ++++++-
man/has.edges.Rd | 7 ++++++-
man/is.adjacent.Rd | 7 ++++++-
man/network.density.Rd | 7 ++++++-
9 files changed, 111 insertions(+), 18 deletions(-)
diff --git a/NAMESPACE b/NAMESPACE
index 5c1efcb..402245e 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -37,9 +37,14 @@ S3method(get.edge.attribute,list)
S3method(get.edge.attribute,network)
S3method(get.edge.value,list)
S3method(get.edge.value,network)
+S3method(get.edgeIDs,network)
+S3method(get.edges,network)
S3method(get.inducedSubgraph,network)
+S3method(get.neighborhood,network)
S3method(get.network.attribute,network)
S3method(get.vertex.attribute,network)
+S3method(has.edges,network)
+S3method(is.adjacent,network)
S3method(is.bipartite,mixingmatrix)
S3method(is.bipartite,network)
S3method(is.directed,mixingmatrix)
@@ -49,6 +54,7 @@ S3method(list.edge.attributes,network)
S3method(list.network.attributes,network)
S3method(list.vertex.attributes,network)
S3method(mixingmatrix,network)
+S3method(network.density,network)
S3method(network.dyadcount,network)
S3method(network.edgecount,network)
S3method(network.naedgecount,network)
diff --git a/R/access.R b/R/access.R
index af49afe..d5e3a4b 100644
--- a/R/access.R
+++ b/R/access.R
@@ -731,6 +731,7 @@ get.edge.value.list <- get.edge.value.network
#' @param na.omit logical; should we omit missing edges?
#' @param tails a vector of vertex ID for the 'tails' (v) side of the dyad
#' @param heads a vector of vertex ID for the 'heads' (alter) side of the dyad
+#' @param ... additional arguments to methods
#' @return For \code{get.edges}, a list of edges. For \code{get.edgeIDs}, a
#' vector of edge ID numbers. For \code{get.dyads.eids}, a list of edge IDs
#' corresponding to the dyads defined by the vertex ids in \code{tails} and
@@ -752,7 +753,11 @@ get.edge.value.list <- get.edge.value.network
#' get.edgeIDs(g,1,neighborhood="in")
#'
#' @export get.edgeIDs
-get.edgeIDs<-function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.omit=TRUE){
+get.edgeIDs <- function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.omit=TRUE, ...) UseMethod("get.edgeIDs")
+
+#' @rdname get.edges
+#' @export
+get.edgeIDs.network <- function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.omit=TRUE, ...){
#Check to be sure we were called with a network
if(!is.network(x))
stop("get.edgeIDs requires an argument of class network.")
@@ -780,7 +785,11 @@ get.edgeIDs<-function(x, v, alter=NULL, neighborhood=c("out","in","combined"), n
#' @rdname get.edges
#' @export get.edges
-get.edges<-function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.omit=TRUE){
+get.edges <- function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.omit=TRUE, ...) UseMethod("get.edges")
+
+#' @rdname get.edges
+#' @export
+get.edges.network <- function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.omit=TRUE, ...){
#Check to be sure we were called with a network
if(!is.network(x))
stop("get.edges requires an argument of class network.")
@@ -803,7 +812,11 @@ get.edges<-function(x, v, alter=NULL, neighborhood=c("out","in","combined"), na.
# as defined by a vector of tails and heads vertex ids
#' @rdname get.edges
#' @export get.dyads.eids
-get.dyads.eids<-function(x,tails,heads,neighborhood = c("out", "in", "combined"),na.omit = TRUE){
+get.dyads.eids <- function(x, tails, heads, neighborhood = c("out", "in", "combined"), na.omit = TRUE, ...) UseMethod("get.dyad.eids")
+
+#' @rdname get.edges
+#' @export
+get.dyads.eids <- function(x, tails, heads, neighborhood = c("out", "in", "combined"), na.omit = TRUE, ...){
if(length(tails)!=length(heads)){
stop('heads and tails vectors must be the same length for get.dyads.eids')
}
@@ -907,7 +920,7 @@ get.dyads.eids<-function(x,tails,heads,neighborhood = c("out", "in", "combined")
#'
#'
#' @export get.inducedSubgraph
-get.inducedSubgraph <- function(x, ...) UseMethod("get.inducedSubgraph")
+get.inducedSubgraph <- function(x, v, alters=NULL,...) UseMethod("get.inducedSubgraph")
#' @rdname get.inducedSubgraph
#' @export
@@ -1024,6 +1037,7 @@ get.network.attribute.network <- function(x, attrname, unlist=FALSE, ...) {
#' @param type the neighborhood to be computed
#' @param na.omit logical; should missing edges be ignored when obtaining
#' vertex neighborhoods?
+#' @param ... additional arguments to methods
#' @return A vector containing the vertex IDs for the chosen neighborhood.
#' @author Carter T. Butts \email{buttsc@@uci.edu}
#' @seealso \code{\link{get.edges}}, \code{\link{is.adjacent}}
@@ -1047,7 +1061,11 @@ get.network.attribute.network <- function(x, attrname, unlist=FALSE, ...) {
#' get.neighborhood(g,1,"combined")
#'
#' @export get.neighborhood
-get.neighborhood<-function(x, v, type=c("out","in","combined"), na.omit=TRUE){
+get.neighborhood<-function(x, v, type=c("out","in","combined"), na.omit=TRUE, ...) UseMethod("get.neighborhood")
+
+#' @rdname get.neighborhood
+#' @export
+get.neighborhood.network<-function(x, v, type=c("out","in","combined"), na.omit=TRUE, ...){
#Check to be sure we were called with a network
if(!is.network(x))
stop("get.neighborhood requires an argument of class network.")
@@ -1217,6 +1235,7 @@ has.loops<-function(x){
#' @param vj a second vertex ID
#' @param na.omit logical; should missing edges be ignored when assessing
#' adjacency?
+#' @param ... additional arguments to methods
#' @return A logical, giving the status of the (i,j) edge
#' @note Prior to version 1.4, \code{na.omit} was set to \code{TRUE} by
#' default.
@@ -1241,7 +1260,11 @@ has.loops<-function(x){
#' g[2,1]==1 #FALSE
#'
#' @export is.adjacent
-is.adjacent<-function(x,vi,vj,na.omit=FALSE){
+is.adjacent <- function(x, vi, vj, na.omit=FALSE, ...) UseMethod("is.adjacent")
+
+#' @rdname is.adjacent
+#' @export
+is.adjacent.network <- function(x, vi, vj, na.omit=FALSE, ...){
if(!is.network(x))
stop("is.adjacent requires an argument of class network.\n")
if(length(vi)!=length(vj)){
diff --git a/R/misc.R b/R/misc.R
index 19551d1..1805dc7 100644
--- a/R/misc.R
+++ b/R/misc.R
@@ -344,6 +344,7 @@ print.mixingmatrix <- function(x, ...) {
#' density?
#' @param discount.bipartite logical; if \code{x} is bipartite, should
#' \dQuote{forbidden} edges be excluded from the count of potential edges?
+#' @param ... additional arguments to methods
#' @return The network density.
#' @section Warning : \code{network.density} relies on network attributes (see
#' \link{network.indicators}) to determine the properties of the underlying
@@ -370,7 +371,11 @@ print.mixingmatrix <- function(x, ...) {
#'
#' @rdname network.density
#' @export network.density
-network.density<-function(x,na.omit=TRUE,discount.bipartite=FALSE){
+network.density <- function(x, na.omit=TRUE, discount.bipartite=FALSE, ...) UseMethod("network.density")
+
+#' @rdname network.density
+#' @export
+network.density.network <- function(x, na.omit=TRUE, discount.bipartite=FALSE, ...){
if(!is.network(x))
stop("network.density requires a network object.")
if(network.size(x)==0){
@@ -413,6 +418,7 @@ network.density<-function(x,na.omit=TRUE,discount.bipartite=FALSE){
#' @aliases is.isolate
#' @param net a \code{\link{network}} object to be queried
#' @param v integer vector of vertex ids to check
+#' @param ... additional arguments to methods
#' @return returns a logical vector with the same length as v, with TRUE if the
#' vertex is involved in any edges, FALSE if it is an isolate.
#' @author skyebend
@@ -425,7 +431,11 @@ network.density<-function(x,na.omit=TRUE,discount.bipartite=FALSE){
#'
#' @rdname has.edges
#' @export has.edges
-has.edges<-function(net,v=seq_len(network.size(net))){
+has.edges <- function(net, v=seq_len(network.size(net)), ...) UseMethod("has.edges")
+
+#' @rdname has.edges
+#' @export
+has.edges.network <- function(net, v=seq_len(network.size(net)), ...){
if(network.size(net)==0){
return(logical(0))
}
diff --git a/man/get.edges.Rd b/man/get.edges.Rd
index b72a1f2..a03ad27 100644
--- a/man/get.edges.Rd
+++ b/man/get.edges.Rd
@@ -3,6 +3,8 @@
\name{get.edges}
\alias{get.edges}
\alias{get.edgeIDs}
+\alias{get.edgeIDs.network}
+\alias{get.edges.network}
\alias{get.dyads.eids}
\title{Retrieve Edges or Edge IDs Associated with a Given Vertex}
\usage{
@@ -11,7 +13,17 @@ get.edgeIDs(
v,
alter = NULL,
neighborhood = c("out", "in", "combined"),
- na.omit = TRUE
+ na.omit = TRUE,
+ ...
+)
+
+\method{get.edgeIDs}{network}(
+ x,
+ v,
+ alter = NULL,
+ neighborhood = c("out", "in", "combined"),
+ na.omit = TRUE,
+ ...
)
get.edges(
@@ -19,7 +31,26 @@ get.edges(
v,
alter = NULL,
neighborhood = c("out", "in", "combined"),
- na.omit = TRUE
+ na.omit = TRUE,
+ ...
+)
+
+\method{get.edges}{network}(
+ x,
+ v,
+ alter = NULL,
+ neighborhood = c("out", "in", "combined"),
+ na.omit = TRUE,
+ ...
+)
+
+get.dyads.eids(
+ x,
+ tails,
+ heads,
+ neighborhood = c("out", "in", "combined"),
+ na.omit = TRUE,
+ ...
)
get.dyads.eids(
@@ -27,7 +58,8 @@ get.dyads.eids(
tails,
heads,
neighborhood = c("out", "in", "combined"),
- na.omit = TRUE
+ na.omit = TRUE,
+ ...
)
}
\arguments{
@@ -43,6 +75,8 @@ undirected networks}
\item{na.omit}{logical; should we omit missing edges?}
+\item{...}{additional arguments to methods}
+
\item{tails}{a vector of vertex ID for the 'tails' (v) side of the dyad}
\item{heads}{a vector of vertex ID for the 'heads' (alter) side of the dyad}
diff --git a/man/get.inducedSubgraph.Rd b/man/get.inducedSubgraph.Rd
index 9a8ca77..6570d8e 100644
--- a/man/get.inducedSubgraph.Rd
+++ b/man/get.inducedSubgraph.Rd
@@ -6,7 +6,7 @@
\alias{\%s\%}
\title{Retrieve Induced Subgraphs and Cuts}
\usage{
-get.inducedSubgraph(x, ...)
+get.inducedSubgraph(x, v, alters = NULL, ...)
\method{get.inducedSubgraph}{network}(x, v, alters = NULL, eid = NULL, ...)
@@ -15,13 +15,13 @@ x \%s\% v
\arguments{
\item{x}{an object of class \code{network}.}
-\item{...}{additional arguments for methods.}
-
\item{v}{a vector of vertex IDs, or, for \code{\%s\%}, optionally a list containing two disjoint vectors of vertex IDs (see below).}
\item{alters}{optionally, a second vector of vertex IDs. Must be disjoint
with \code{v}.}
+\item{...}{additional arguments for methods.}
+
\item{eid}{optionally, a numeric vector of valid edge ids in \code{x} that
should be retained (cannot be used with \code{v} or \code{alter})}
}
diff --git a/man/get.neighborhood.Rd b/man/get.neighborhood.Rd
index 00ce8c3..c18490b 100644
--- a/man/get.neighborhood.Rd
+++ b/man/get.neighborhood.Rd
@@ -2,9 +2,12 @@
% Please edit documentation in R/access.R
\name{get.neighborhood}
\alias{get.neighborhood}
+\alias{get.neighborhood.network}
\title{Obtain the Neighborhood of a Given Vertex}
\usage{
-get.neighborhood(x, v, type = c("out", "in", "combined"), na.omit = TRUE)
+get.neighborhood(x, v, type = c("out", "in", "combined"), na.omit = TRUE, ...)
+
+\method{get.neighborhood}{network}(x, v, type = c("out", "in", "combined"), na.omit = TRUE, ...)
}
\arguments{
\item{x}{an object of class \code{network}}
@@ -15,6 +18,8 @@ get.neighborhood(x, v, type = c("out", "in", "combined"), na.omit = TRUE)
\item{na.omit}{logical; should missing edges be ignored when obtaining
vertex neighborhoods?}
+
+\item{...}{additional arguments to methods}
}
\value{
A vector containing the vertex IDs for the chosen neighborhood.
diff --git a/man/has.edges.Rd b/man/has.edges.Rd
index 642d676..5b37270 100644
--- a/man/has.edges.Rd
+++ b/man/has.edges.Rd
@@ -3,15 +3,20 @@
\name{has.edges}
\alias{has.edges}
\alias{is.isolate}
+\alias{has.edges.network}
\title{Determine if specified vertices of a network have any edges (are not
isolates)}
\usage{
-has.edges(net, v = seq_len(network.size(net)))
+has.edges(net, v = seq_len(network.size(net)), ...)
+
+\method{has.edges}{network}(net, v = seq_len(network.size(net)), ...)
}
\arguments{
\item{net}{a \code{\link{network}} object to be queried}
\item{v}{integer vector of vertex ids to check}
+
+\item{...}{additional arguments to methods}
}
\value{
returns a logical vector with the same length as v, with TRUE if the
diff --git a/man/is.adjacent.Rd b/man/is.adjacent.Rd
index 946a160..be7b054 100644
--- a/man/is.adjacent.Rd
+++ b/man/is.adjacent.Rd
@@ -2,9 +2,12 @@
% Please edit documentation in R/access.R
\name{is.adjacent}
\alias{is.adjacent}
+\alias{is.adjacent.network}
\title{Determine Whether Two Vertices Are Adjacent}
\usage{
-is.adjacent(x, vi, vj, na.omit = FALSE)
+is.adjacent(x, vi, vj, na.omit = FALSE, ...)
+
+\method{is.adjacent}{network}(x, vi, vj, na.omit = FALSE, ...)
}
\arguments{
\item{x}{an object of class \code{network}}
@@ -15,6 +18,8 @@ is.adjacent(x, vi, vj, na.omit = FALSE)
\item{na.omit}{logical; should missing edges be ignored when assessing
adjacency?}
+
+\item{...}{additional arguments to methods}
}
\value{
A logical, giving the status of the (i,j) edge
diff --git a/man/network.density.Rd b/man/network.density.Rd
index 397e279..bc03296 100644
--- a/man/network.density.Rd
+++ b/man/network.density.Rd
@@ -2,9 +2,12 @@
% Please edit documentation in R/misc.R
\name{network.density}
\alias{network.density}
+\alias{network.density.network}
\title{Compute the Density of a Network}
\usage{
-network.density(x, na.omit = TRUE, discount.bipartite = FALSE)
+network.density(x, na.omit = TRUE, discount.bipartite = FALSE, ...)
+
+\method{network.density}{network}(x, na.omit = TRUE, discount.bipartite = FALSE, ...)
}
\arguments{
\item{x}{an object of class \code{network}}
@@ -14,6 +17,8 @@ density?}
\item{discount.bipartite}{logical; if \code{x} is bipartite, should
\dQuote{forbidden} edges be excluded from the count of potential edges?}
+
+\item{...}{additional arguments to methods}
}
\value{
The network density.