Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
25f0193
added support for netzschleuder
schochastics Apr 5, 2025
67ec488
chore: Auto-update from GitHub Actions
schochastics Apr 5, 2025
5c5895d
better source/target handling
schochastics Apr 5, 2025
233b9e0
added token for restricted networks
schochastics Apr 6, 2025
e521a71
added minty for type checking
schochastics Apr 7, 2025
4b07fc2
Apply suggestions from code review
schochastics Apr 10, 2025
33ae5ed
chore: Auto-update from GitHub Actions
schochastics Apr 10, 2025
db8b0db
changes of review
schochastics Apr 10, 2025
51046b9
added missing quotes
schochastics Apr 10, 2025
d8b1f77
added proper httr2 requests with custom ratelimits
schochastics Apr 10, 2025
bc6a34a
added slash notation and directed/bipartite checking via metadata
schochastics Apr 10, 2025
d7a0b06
suppress minty warnings
schochastics Apr 10, 2025
ca89264
docs update
schochastics Apr 10, 2025
a7c2ef1
correct collection url
schochastics Apr 10, 2025
4b473a1
new netzschleuder namespace
schochastics Apr 14, 2025
e60885d
removed call argument
schochastics Apr 14, 2025
6e45a5d
removed rlang
schochastics Apr 14, 2025
dd495a4
added token to ns_graph and error handling for gprops file
schochastics Apr 14, 2025
7a8004c
docs
schochastics Apr 14, 2025
e29f90f
rate limit works
schochastics Apr 14, 2025
bcd1b1a
put base_req into onload
schochastics Apr 15, 2025
4431e4b
added more comments for clarity
schochastics Apr 16, 2025
a52dec8
added David as ctb and a sentence about netzschleuder
schochastics Apr 16, 2025
10b25c4
chore: Auto-update from GitHub Actions
schochastics Apr 16, 2025
4485280
review changes
schochastics Apr 17, 2025
02fb9db
chore: Auto-update from GitHub Actions
schochastics Apr 17, 2025
0c717fc
moved minty check to ns_df
schochastics Apr 17, 2025
1974d6a
better name error handling
schochastics Apr 17, 2025
29412cf
moved all pkgs to suggest and removed onLoad
schochastics Apr 18, 2025
0ad558d
earlier renaming and better regex
schochastics Apr 18, 2025
3cd0496
double parenthesis
schochastics Apr 18, 2025
eb12a3a
allow metadata as input to ns_graph
schochastics Apr 23, 2025
c9ef882
chore: Auto-update from GitHub Actions
schochastics Apr 23, 2025
94bab69
implement file size limit
schochastics Apr 23, 2025
18f87d1
docs
schochastics Apr 23, 2025
2a6d9f1
added meta data print
schochastics Apr 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed .github/dep-suggests-matrix.json
Empty file.
1 change: 0 additions & 1 deletion .github/versions-matrix.json

This file was deleted.

2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(graph_from_netzschleuder)
export(lesmis_gml)
export(lesmis_graphml)
export(lesmis_pajek)
export(read_from_netzschleuder)
importFrom(igraph,vcount)
80 changes: 80 additions & 0 deletions R/netzschleuder.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#' Download a graph from the Netzschleuder data catalogue
#' Netzschleuder (<https://networks.skewed.de/>) is a large online repository for
#' network datasets with the aim of aiding scientific research.
#' @param name character. name of the network dataset.
#' @param net character. If the dataset contains several networks this is the network name.
#' @return a named list containing an edge list and node attribute data frame and some metadata
#' @export
read_from_netzschleuder <- function(name, net = NULL) {
if (is.null(net)) {
net <- name
}
zip_url <- paste0(
"https://networks.skewed.de/net/",
name,
"/files/",
net,
".csv.zip"
)

temp <- tempfile()
utils::download.file(zip_url, temp, quiet = TRUE) #TODO: add better error handling
zip_contents <- utils::unzip(temp, list = TRUE)

edge_file_name <- zip_contents$Name[grepl("edge", zip_contents$Name)]
node_file_name <- zip_contents$Name[grepl("node", zip_contents$Name)]
meta_file_name <- zip_contents$Name[grepl("gprops", zip_contents$Name)]

edges_df <- utils::read.csv(unz(temp, edge_file_name)) + 1
names(edges_df)[c(1, 2)] <- c("from", "to")

nodes_df <- utils::read.csv(unz(temp, node_file_name))
names(nodes_df)[1] <- "id"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards implementing lintr just for this, here and elsewhere.

Suggested change
names(nodes_df)[1] <- "id"
names(nodes_df)[[1]] <- "id"

nodes_df$id <- nodes_df$id + 1
if ("X_pos" %in% names(nodes_df)) {
pos_array <- gsub("array\\(\\[|\\]|\\)", "", nodes_df[["X_pos"]])
split_coords <- strsplit(pos_array, ",")

x_vals <- sapply(split_coords, function(x) as.numeric(trimws(x[1])))
y_vals <- sapply(split_coords, function(x) as.numeric(trimws(x[2])))

nodes_df[["X_pos"]] <- NULL
nodes_df$x <- x_vals
nodes_df$y <- y_vals
}

meta_df <- utils::read.csv(unz(temp, meta_file_name))
on.exit(unlink(temp))

list(nodes = nodes_df, edges = edges_df, meta = meta_df)
}

#' Create a graph from the Netzschleuder data catalogue
#'
#' Netzschleuder (<https://networks.skewed.de/>) is a large online repository for
#' network datasets with the aim of aiding scientific research.
#' @param name character. name of the network dataset.
#' @param net character. If the dataset contains several networks this is the network name.
#' @param directed logical. Whether a directed graph is constructed.
#' @param bipartite logical. Whether a bipartite graph is constructed.
#' @return a new graph object.
#' @export
graph_from_netzschleuder <- function(
name,
net = NULL,
directed = FALSE,
bipartite = FALSE
) {
graph_data <- read_from_netzschleuder(name, net)
g <- igraph::graph_from_data_frame(
graph_data$edges,
directed = directed,
vertices = graph_data$nodes
)
if (bipartite) {
types <- rep(FALSE, igraph::vcount(g))
types[graph_data$nodes$id %in% graph_data$edges[, 1]] <- TRUE
g <- igraph::set_vertex_attr(g, "type", value = types)
}
g
}
24 changes: 24 additions & 0 deletions man/graph_from_netzschleuder.Rd

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

23 changes: 23 additions & 0 deletions man/read_from_netzschleuder.Rd

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