17

Is there a R library that supports neo4j? I would like to construct a R graph (e.g. igraph) from neo4j or - vice versa - store a R graph in neo4j.

More precisely, I am looking for something similar to bulbflow for Python.


Update

There is a new neo4j driver for R that looks promising: http://nicolewhite.github.io/RNeo4j/. I changed the correct answer.

Martin Preusse
  • 9,151
  • 12
  • 48
  • 80
  • Since neo4j has a [REST API](http://docs.neo4j.org/chunked/1.6/rest-api.html), you should be able to connect to it by hand, with the `RJSONIO` package to handle JSON data and `RCurl` to send the queries. – Vincent Zoonekynd Jun 26 '12 at 00:41
  • A direct access via REST is possible of course, thanks for RJSONIO. What I am looking for is a more convenient R binding for neo4j. something like: "g <- graph.neo4j(), g.addNode(x), g.addEdge(from, to)" . – Martin Preusse Jun 26 '12 at 08:49
  • Also, you probably could import and export GraphML?, See http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-load-a-sample-graph for loading, exporting is similar. – Peter Neubauer Jul 04 '12 at 13:10
  • I'm not sure if there are any R libraries. May be this will be helpful to look at [Neo4j-Cypher-R Example Code](https://gist.github.com/1178110) – darshan Aug 13 '12 at 14:56

4 Answers4

13

This link might be helpful. I'm going to connect ne04j with R in the following days and will try first with the provided link. Hope it helps.

I tried it out and it works well. Here is the function that works: First, install and load packages and then execute function:

install.packages('RCurl')
install.packages('RJSONIO')

library('bitops')
library('RCurl')
library('RJSONIO')

query <- function(querystring) {
  h = basicTextGatherer()
  curlPerform(url="localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query",
    postfields=paste('query',curlEscape(querystring), sep='='),
    writefunction = h$update,
    verbose = FALSE
  )           
  result <- fromJSON(h$value())
  #print(result)
  data <- data.frame(t(sapply(result$data, unlist)))
  print(data)
  names(data) <- result$columns

}

and this is an example of calling function:

q <-"start a = node(50) match a-->b RETURN b"
 data <- query(q)
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
  • 1
    Good to know that I'm not alone in this ;) Would be interesting to know why you're working on this and how you use neo4j. – Martin Preusse Sep 04 '12 at 08:35
11

Consider the RNeo4j driver. The function shown above is incomplete: it cannot return single column data and there is no NULL handling.

https://github.com/nicolewhite/RNeo4j

Nicole White
  • 7,720
  • 29
  • 31
1

I tried to use the R script (thanks a lot for providing it) and it seems to me that you can directly use : /db/data/cypher instead of db/data/ext/CypherPlugin/graphdb/execute_query (with neo4j 2.0).

0

Not sure if it fits your requirements but have a look at Gephi. http://gephi.org/.

carpamon
  • 6,515
  • 3
  • 38
  • 51
  • 1
    This does not really relate to my question ... I am looking for a R package that allows easy access to neo4j. Gephi is nice though :) – Martin Preusse Jun 25 '12 at 15:43
  • I use Gephi as an intermediate to neo. There's a good plugin if you export igraph to GEXF, then import that to gephi. Then you can export to neo4j. It's a little circuitous, but easy in a point-and-click kind of way. – Mittenchops Sep 28 '12 at 19:38