Skip to content

Commit 29b70b0

Browse files
committed
Added "fallback" methods that emulate network's internal structure.
1 parent e74bbfb commit 29b70b0

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method("$",networkLite)
34
S3method("+",networkLite)
45
S3method("-",networkLite)
6+
S3method("[",networkLite)
57
S3method("[<-",networkLite)
68
S3method(add.edges,networkLite)
79
S3method(add.vertices,networkLite)

R/to_network_networkLite.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,38 @@ to_network_networkLite <- function(x, ...) {
6060
as.network.networkLite <- function(x, ...) {
6161
return(x)
6262
}
63+
64+
#' @rdname last-resort
65+
#'
66+
#' @title Last-resort utilities
67+
#'
68+
#' @description Since the purpose of [`networkLite`] is to be a drop-in replacement
69+
#' for [`network`], these utilities emulate the internal structure of
70+
#' `network`. They are likely to perform poorly and should be avoided.
71+
#'
72+
#' @param x a `networkLite` object
73+
#' @param name passed to `[[`, but some special cases (`"oel"` nd `"iel"` are handled)
74+
#'
75+
#' @note Please do not rely on these unless you absolutely have to;
76+
#' since they slow down access to `networkLite` objects, they may be
77+
#' removed if they ever stop being necessary.
78+
#'
79+
#' @export
80+
`$.networkLite` <- function(x, name) {
81+
o <- x[[name, exact = FALSE]]
82+
if(!is.null(o)) return(o)
83+
84+
name <- match.arg(name, c("oel", "iel"))
85+
if(getOption("networkLite.warn_fallback")) warning(sQuote("networkLite"), " fallback invoked: ", sQuote(name), ".", immediate. = TRUE)
86+
switch(name,
87+
oel = split(seq_len(nrow(x$el)), factor(x$el$.tail, levels = seq_len(x$gal$n))),
88+
iel = split(seq_len(nrow(x$el)), factor(x$el$.head, levels = seq_len(x$gal$n)))
89+
)
90+
}
91+
92+
#' @rdname last-resort
93+
#' @export
94+
`[.networkLite` <- function(x, ...) {
95+
if(getOption("networkLite.warn_fallback")) warning(sQuote("networkLite"), " fallback invoked: ", sQuote("["), ".", immediate. = TRUE)
96+
to_network_networkLite(x)[...]
97+
}

R/zzz.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.onLoad <- function(libname, pkgname){
2+
statnet.common::default_options(networkLite.warn_fallback = FALSE)
3+
}

man/last-resort.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)