neo4j-rstats / neo4r

A Modern and Flexible Neo4J Driver
https://neo4j-rstats.github.io/user-guide/
Other
106 stars 30 forks source link

'names' attribute [2] must be the same length as the vector [1] #71

Open paul-shannon opened 4 years ago

paul-shannon commented 4 years ago
call_neo4j("MATCH (r) WHERE r.name='Carboplatin' RETURN ID(r), labels(r)",  neo4r)

fails in neo4r with this message:

Error in names(object) <- nm : 
  'names' attribute [2] must be the same length as the vector [1]

The same query, copy & pasted into the neo4j browser returns:


ID(r)      |     labels(r)      
11288      |    ["Compound"]
ciaran8065 commented 4 years ago

Experiencing same issue when I try to return more than 1 variable form a query

ciaran8065 commented 3 years ago

Probably a little late but I've found the best way around this is to not apply any function to what you return. I've had trouble with using collect(user_id), distinct(id) etc etc It works for me when I return full results and then in post-processing I extract exactly what I need

wjholden commented 3 years ago

For anyone reading this later -- a potential workaround is to set output = "json". This will reveal to you that the arrays of the output are not of uniform length.

For example, this is a valid Neo4j query, but it fails in neo4r:

# fails in Neo4r 0.1.3
"
CALL gds.louvain.write('GoT', {
    writeProperty: 'community'
})
" %>% call_neo4j(con)

If you add change the output type to JSON, then the query will succeed.

"
CALL gds.louvain.write('GoT', {
  writeProperty: 'community'
})
" %>% call_neo4j(con, output="json")

Another option is to return a single value to suppress the error.

"
CALL gds.louvain.write('GoT', {
  writeProperty: 'community'
})
YIELD communityCount
" %>% call_neo4j(con)

Yet another workaround can be to join your collect statement into a string. For example:

match (p:Person)
return p.community as Community,
    apoc.text.join(collect(p.name), ', ') as Members