@@ -60,3 +60,38 @@ to_network_networkLite <- function(x, ...) {
6060as.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+ }
0 commit comments