wrap_igraph: Run an igraph function on an sfnetwork object

View source: R/utils.R

wrap_igraphR Documentation

Run an igraph function on an sfnetwork object

Description

Since sfnetwork objects inherit igraph objects, any igraph function can be called on a sfnetwork. However, if this function returns a network, it will be an igraph object rather than a sfnetwork object. With wrap_igraph, such a function will preserve the sfnetwork class, after checking if the network returned by igraph still has a valid spatial network structure.

Usage

wrap_igraph(.data, .f, ..., .force = FALSE, .message = TRUE)

Arguments

.data

An object of class sfnetwork.

.f

An function from the igraph package that accepts a graph as its first argument, and returns a graph.

...

Arguments passed on to .f.

.force

Should network validity checks be skipped? Defaults to FALSE, meaning that network validity checks are executed when returning the new network. These checks guarantee a valid spatial network structure. For the nodes, this means that they all should have POINT geometries. In the case of spatially explicit edges, it is also checked that all edges have LINESTRING geometries, nodes and edges have the same CRS and boundary points of edges match their corresponding node coordinates. These checks are important, but also time consuming. If you are already sure your input data meet the requirements, the checks are unnecessary and can be turned off to improve performance.

.message

Should informational messages (those messages that are neither warnings nor errors) be printed when constructing the network? Defaults to TRUE.

Value

An object of class sfnetwork.

Examples

oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))

net = as_sfnetwork(mozart, "delaunay", directed = FALSE)
mst = wrap_igraph(net, igraph::mst, .message = FALSE)
mst

plot(net)
plot(mst)

par(oldpar)


luukvdmeer/sfnetworks documentation built on Nov. 21, 2024, 4:54 a.m.