Skip to content

Commit

Permalink
Made get.edgeIDs(), get.edges(), get.neighborhood(), has.edges(), is.…
Browse files Browse the repository at this point in the history
…adjacent(), and network.density() generic.
  • Loading branch information
krivit committed Dec 11, 2024
1 parent 769972a commit 414ec61
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 18 deletions.
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
35 changes: 29 additions & 6 deletions R/access.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down Expand Up @@ -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.")
Expand All @@ -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')
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}}
Expand All @@ -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.")
Expand Down Expand Up @@ -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.
Expand All @@ -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)){
Expand Down
14 changes: 12 additions & 2 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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){
Expand Down Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
40 changes: 37 additions & 3 deletions man/get.edges.Rd

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

6 changes: 3 additions & 3 deletions man/get.inducedSubgraph.Rd

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

7 changes: 6 additions & 1 deletion man/get.neighborhood.Rd

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

7 changes: 6 additions & 1 deletion man/has.edges.Rd

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

7 changes: 6 additions & 1 deletion man/is.adjacent.Rd

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

7 changes: 6 additions & 1 deletion man/network.density.Rd

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

0 comments on commit 414ec61

Please sign in to comment.