Skip to content

Commit 7ca6637

Browse files
committed
Merge pull request #152 from gaborcsardi/no-igraph
Replace igraph calls with our own R code, get rid of igraph
2 parents 2b091a8 + 6f314dc commit 7ca6637

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

DESCRIPTION

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Imports:
1616
stringdist,
1717
testthat,
1818
digest,
19-
igraph,
2019
rstudioapi (>= 0.2),
2120
httr,
2221
jsonlite,

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# lintr 1.0.0.9000 #
2+
* lintr does not need the igraph package any more (#152, @gaborcsardi)
3+
24
* trailing_semicolon_linter (#147, @gaborcsardi)
35

46
* Commas linter handles missing arguments calls properly (#145)

R/get_source_expressions.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ get_source_expressions <- function(filename) {
8989
content <- get_content(expr_lines, parsed_content[loc, ])
9090

9191
id <- as.character(parsed_content$id[loc])
92-
edges <- igraph::E(tree)[from(igraph::subcomponent(tree, id, mode = "out"))]
92+
edges <- component_edges(tree, id)
9393
pc <- parsed_content[c(loc, edges), ]
9494
list(
9595
filename = filename,

R/tree-utils.R

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,32 @@ generate_tree <- function(pc) {
33
return(NULL)
44
}
55
edges <- matrix(as.character(c(pc$parent, pc$id)), ncol = 2)
6-
igraph::graph.edgelist(edges, directed = TRUE)
6+
list(edges = edges, adjlist = adjlist_from_edgelist(edges))
77
}
8+
9+
## Create an adjacency list from an edge list
10+
11+
adjlist_from_edgelist <- function(edges) {
12+
tapply(edges[, 2], edges[, 1], c, simplify = FALSE)
13+
}
14+
15+
## Take the subcomponent of id (mode out), and then all edges
16+
## that start at these vertices
17+
18+
component_edges <- function(graph, id) {
19+
sc <- newv <- unique(id)
20+
size <- length(sc)
21+
repeat {
22+
neis <- unlist(graph$adjlist[newv])
23+
newv <- setdiff(neis, sc)
24+
sc <- c(sc, newv)
25+
if (length(sc) == size) break;
26+
size <- length(sc)
27+
}
28+
29+
which(graph$edges[, 1] %in% sc)
30+
}
31+
832
children <- function(data, id, levels = Inf, simplify = TRUE) {
933

1034
child_ids <- function(ids) {

0 commit comments

Comments
 (0)