Skip to content

Commit 4258fdb

Browse files
committed
Fix encoding issue during graph creation
1 parent c104d6d commit 4258fdb

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# tidygraph (development version)
22

3+
* Fix a bug in `tbl_graph()` when edge `to` and `from` where encoded as factors
4+
35
# tidygraph 1.3.0
46

57
* Add `resolution` argument to `group_louvrain()` to mirror the igraph function

R/list.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ as_graph_node_edge <- function(x, directed, node_key = 'name') {
7474
to_ind <- which(names(edges) == 'to')
7575
if (length(to_ind) == 0) to_ind <- 2
7676
edges <- edges[, c(from_ind, to_ind, seq_along(edges)[-c(from_ind, to_ind)]), drop = FALSE]
77+
if (is.factor(edges[[1]])) edges[[1]] <- as.character(edges[[1]])
78+
if (is.factor(edges[[2]])) edges[[2]] <- as.character(edges[[2]])
7779
if (!is.null(nodes)) {
7880
if (is.na(node_key)) {
7981
name_ind <- 1L

0 commit comments

Comments
 (0)