-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting an error on creating with convert_to("igraph") has error on result #43
Comments
This bug seems to be due to the fact that the properties returned by the query don't have the same length everywhere: library(neo4r)
con <- neo4j_api$new(url = "http://localhost:7474",
user = "neo4j", password = "neo4j")
res <- "MATCH a=(p:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(m:Movie) RETURN a;" %>%
call_neo4j(con, type = "graph")
res$nodes %>%
unnest_nodes()
#> # A tibble: 13 x 7
#> id label tagline title released born name
#> <chr> <chr> <chr> <chr> <int> <int> <chr>
#> 1 13313 Movie A stiff drink. A little m… Charlie … 2007 NA <NA>
#> 2 13225 Person <NA> <NA> NA 1956 Tom H…
#> 3 13316 Movie Once in a lifetime you ge… A League… 1992 NA <NA>
#> 4 13315 Movie This Holiday Season… Beli… The Pola… 2004 NA <NA>
#> 5 13304 Movie At the edge of the world,… Cast Away 2000 NA <NA>
#> 6 13298 Movie Houston, we have a proble… Apollo 13 1995 NA <NA>
#> 7 13284 Movie Walk a mile you'll never … The Gree… 1999 NA <NA>
#> 8 13265 Movie Break The Codes The Da V… 2006 NA <NA>
#> 9 13259 Movie Everything is connected Cloud At… 2012 NA <NA>
#> 10 13239 Movie In every life there comes… That Thi… 1996 NA <NA>
#> 11 13232 Movie A story of love, lava and… Joe Vers… 1990 NA <NA>
#> 12 13227 Movie What if someone you never… Sleeples… 1993 NA <NA>
#> 13 13221 Movie At odds in life... in lov… You've G… 1998 NA <NA>
# Doesn't work
res$relationships %>%
unnest_relationships()
#> Error: Can't coerce element 1 from a list to a character
library(tidyverse)
# Line 3 is a <list [6]>, while all other are <list [1]>
tidyr::unnest(res$relationships, properties)
#> # A tibble: 12 x 5
#> id type startNode endNode properties
#> <chr> <chr> <chr> <chr> <list>
#> 1 18917 ACTED_IN 13225 13313 <list [1]>
#> 2 18923 ACTED_IN 13225 13316 <list [1]>
#> 3 18921 ACTED_IN 13225 13315 <list [6]>
#> 4 18902 ACTED_IN 13225 13304 <list [1]>
#> 5 18891 ACTED_IN 13225 13298 <list [1]>
#> 6 18871 ACTED_IN 13225 13284 <list [1]>
#> 7 18824 ACTED_IN 13225 13265 <list [1]>
#> 8 18815 ACTED_IN 13225 13259 <list [4]>
#> 9 18777 ACTED_IN 13225 13239 <list [1]>
#> 10 18765 ACTED_IN 13225 13232 <list [1]>
#> 11 18758 ACTED_IN 13225 13227 <list [1]>
#> 12 18751 ACTED_IN 13225 13221 <list [1]>
# works
tidyr::unnest(res$relationships, properties) %>%
tidyr::unnest() %>%
dplyr::mutate(properties = as.character(properties))
#> # A tibble: 20 x 5
#> id type startNode endNode properties
#> <chr> <chr> <chr> <chr> <chr>
#> 1 18917 ACTED_IN 13225 13313 Rep. Charlie Wilson
#> 2 18923 ACTED_IN 13225 13316 Jimmy Dugan
#> 3 18921 ACTED_IN 13225 13315 Hero Boy
#> 4 18921 ACTED_IN 13225 13315 Father
#> 5 18921 ACTED_IN 13225 13315 Conductor
#> 6 18921 ACTED_IN 13225 13315 Hobo
#> 7 18921 ACTED_IN 13225 13315 Scrooge
#> 8 18921 ACTED_IN 13225 13315 Santa Claus
#> 9 18902 ACTED_IN 13225 13304 Chuck Noland
#> 10 18891 ACTED_IN 13225 13298 Jim Lovell
#> 11 18871 ACTED_IN 13225 13284 Paul Edgecomb
#> 12 18824 ACTED_IN 13225 13265 Dr. Robert Langdon
#> 13 18815 ACTED_IN 13225 13259 Zachry
#> 14 18815 ACTED_IN 13225 13259 Dr. Henry Goose
#> 15 18815 ACTED_IN 13225 13259 Isaac Sachs
#> 16 18815 ACTED_IN 13225 13259 Dermot Hoggins
#> 17 18777 ACTED_IN 13225 13239 Mr. White
#> 18 18765 ACTED_IN 13225 13232 Joe Banks
#> 19 18758 ACTED_IN 13225 13227 Sam Baldwin
#> 20 18751 ACTED_IN 13225 13221 Joe Fox Created on 2019-01-30 by the reprex package (v0.2.1) I should make the convert and unnest more smart. |
Hey @dfgitn4j So the issue with the unnesting should be solved by #d14b45db commit. As far as I can tell the igraph error is linked to the print method of igraph (how igraph prints its object to the console), not to the creation of the object itself. It seems to be due to the fact that the graph results contains NA at some point. library(neo4r)
con <- neo4j_api$new(url = "http://localhost:7474",
user = "neo4j", password = "neo4j")
res <- "MATCH a=(p:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(m:Movie) RETURN a;" %>%
call_neo4j(con, type = "graph")
res$nodes %>%
unnest_nodes()
#> # A tibble: 13 x 7
#> id label tagline title released born name
#> <chr> <chr> <chr> <chr> <int> <int> <chr>
#> 1 13313 Movie A stiff drink. A little m… Charlie W… 2007 NA <NA>
#> 2 13225 Person <NA> <NA> NA 1956 Tom H…
#> 3 13316 Movie Once in a lifetime you ge… A League … 1992 NA <NA>
#> 4 13315 Movie This Holiday Season… Beli… The Polar… 2004 NA <NA>
#> 5 13304 Movie At the edge of the world,… Cast Away 2000 NA <NA>
#> 6 13298 Movie Houston, we have a proble… Apollo 13 1995 NA <NA>
#> 7 13284 Movie Walk a mile you'll never … The Green… 1999 NA <NA>
#> 8 13265 Movie Break The Codes The Da Vi… 2006 NA <NA>
#> 9 13259 Movie Everything is connected Cloud Atl… 2012 NA <NA>
#> 10 13239 Movie In every life there comes… That Thin… 1996 NA <NA>
#> 11 13232 Movie A story of love, lava and… Joe Versu… 1990 NA <NA>
#> 12 13227 Movie What if someone you never… Sleepless… 1993 NA <NA>
#> 13 13221 Movie At odds in life... in lov… You've Go… 1998 NA <NA>
# Now works
res$relationships %>%
unnest_relationships()
#> # A tibble: 20 x 5
#> id type startNode endNode properties
#> <chr> <chr> <chr> <chr> <chr>
#> 1 18917 ACTED_IN 13225 13313 Rep. Charlie Wilson
#> 2 18923 ACTED_IN 13225 13316 Jimmy Dugan
#> 3 18921 ACTED_IN 13225 13315 Hero Boy
#> 4 18921 ACTED_IN 13225 13315 Father
#> 5 18921 ACTED_IN 13225 13315 Conductor
#> 6 18921 ACTED_IN 13225 13315 Hobo
#> 7 18921 ACTED_IN 13225 13315 Scrooge
#> 8 18921 ACTED_IN 13225 13315 Santa Claus
#> 9 18902 ACTED_IN 13225 13304 Chuck Noland
#> 10 18891 ACTED_IN 13225 13298 Jim Lovell
#> 11 18871 ACTED_IN 13225 13284 Paul Edgecomb
#> 12 18824 ACTED_IN 13225 13265 Dr. Robert Langdon
#> 13 18815 ACTED_IN 13225 13259 Zachry
#> 14 18815 ACTED_IN 13225 13259 Dr. Henry Goose
#> 15 18815 ACTED_IN 13225 13259 Isaac Sachs
#> 16 18815 ACTED_IN 13225 13259 Dermot Hoggins
#> 17 18777 ACTED_IN 13225 13239 Mr. White
#> 18 18765 ACTED_IN 13225 13232 Joe Banks
#> 19 18758 ACTED_IN 13225 13227 Sam Baldwin
#> 20 18751 ACTED_IN 13225 13221 Joe Fox
library(neo4r)
con <- neo4j_api$new(url = "http://localhost:7474",
user = "neo4j", password = "neo4j")
x <-"MATCH a=(p:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(m:Movie) RETURN a;" %>%
call_neo4j(con, type = "graph") %>%
convert_to("igraph")
plot(x) class(x)
#> [1] "igraph" Created on 2019-02-11 by the reprex package (v0.2.1) |
I create a graph using the Neo4j movie graph database with "graph" as the output type and then use convert_to with "igraph"
I get the following error referencing G:
Am thinking it might part of a different, but seemingly related error unnesting relationships when returned as a data.frame and not a graph:
The text was updated successfully, but these errors were encountered: