Comments (8)
Creating the network via igraph::graph_from_edgelist
and the converting works as expected:
igraph::graph_from_edgelist(as.matrix(el)) %>%
as_tbl_graph()
from tidygraph.
Try setting directed = TRUE
in tbl_graph
?
from tidygraph.
directed = TRUE
is documented as the default. I confirmed it doesn't change the result.
from tidygraph.
Ok - this was a “From-my-phone” suggestion, sorry for leading you astray.
I’ll look into it
from tidygraph.
No worries. It's easy enough to create and convert the igraph object, so it's not blocking me. Just fyi.
from tidygraph.
Problem seems to occur in the as_graph_node_edge
method when dealing with a tibble. Note first that when using a data frame, the problem does not occur (provided stringsAsfactors = F
):
> el <- data.frame(from = c("b", "c"), to = c("a", "b"), stringsAsFactors = F)
> nodes <- data.frame(name = letters[1:3], stringsAsFactors = F)
> tbl_graph(nodes, el)
# A tbl_graph: 3 nodes and 2 edges
#
# A rooted tree
#
# Node Data: 3 x 1 (active)
name
<chr>
1 a
2 b
3 c
#
# Edge Data: 2 x 2
from to
<int> <int>
1 2 1
2 3 2
The issue occurs in the as_graph_node_edge
when the method evaluates whether the edgelist columns are of class character
. Currently, the evaluation reads: if (is.character(edges[, 1]))
and then proceeds to match the edgelist names to the node names. If edges
is a tibble, this will always evaluate to false
, since the subset edges[, 1]
produces a one column tibble and not a vector of characters.
> el <- data.frame(from = c("b", "c"), to = c("a", "b"), stringsAsFactors = F)
> class(el[, 1])
[1] "character"
> el <- tibble(from = c("b", "c"), to = c("a", "b"))
> class(el[, 1])
[1] "tbl_df" "tbl" "data.frame"
As a result, the matching of the names between the edgelist and nodes list does not occur, since if (is.character(edges[, 1]))
evaluates to false
. If the evaluation uses double bracket notation-- if (is.character(edges[[1]]))
-- it evaluates to true
and the matching occurs.
> el <- tibble(from = c("b", "c"), to = c("a", "b"))
> class(el[[1]])
[1] "character"
Replacing the single bracket notation for double bracket notation in as_graph_node_edge
solves the problem.
from tidygraph.
I have filed a pull request fixing the issue. This is my very first pull request. I hope I have done it well and the request is clear 😬. #53
from tidygraph.
Thanks @ramorel - much appreciated!
The PR was well explained and executed - Congrats on becoming a contributor 🎉
from tidygraph.
Related Issues (20)
- Add node_is_connected()
- add "resolution" argument to group_louvain
- Error: unable to load R code in package ‘tidygraph’ HOT 1
- access .orig_data after a graph contraction HOT 1
- New CRAN release timeline? HOT 1
- Release tidygraph 1.2.3
- `trunc_mat()` deprecated in tibble
- betweenness_centrality() does not return normalized values HOT 1
- Size aesthetic is deprecated for edges HOT 1
- Upkeep for tidygraph (2023)
- Feature request: add support for class "dagitty" to as_tbl_graph HOT 1
- Release tidygraph 1.3.0 HOT 5
- Printing grouped til_graphs will error if grouping is an expression
- Creating a tbl_graph from data frames with sticky columns
- Add new features from igraph HOT 2
- bind_graphs() for list of tbl_graph objects has broken
- igraph 2.0.0 installation failed HOT 1
- dfs_rank seems to give wrong results with v1.3.1
- bfs_rank returns 0 instead of NA for unreachable nodes with tidygraph v1.3.1
- Regression in edgelist import with as_tbl_graph HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tidygraph.