0
votes

I'm trying to send queries from my R session to neo4j

Looking at the REST API docs provided by neo4j: http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html I've formulated a successful curl query below

curl -X POST -d @test.json http://localhost:7474/db/data/cypher -H "Content-Type: application/json"

where the contents of test.json are as follows

{"query": "start pathway=node:pathwayid(pathway={pathway}) match pathway--(ko:`ko`)<-[r]-(cpd:`cpd`) return ko.ko,r,cpd.cpd limit 5;","params": {"pathway":"path:ko00010"} }

Solutions given so far on SO in Use neo4j with R where the query is stored in querystring (see code below) do not utilise ability to parameterise the cypher query. eg:

library(RCurl)
library(RJSONIO)

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())

in this case querystring is:

start pathway=node:pathwayid('pathway:"path:ko00010"') match pathway--(ko:`ko`)<-[r]-(cpd:`cpd`) return ko.ko,r,cpd.cpd limit 5;

I'm curious how do i parse parameters into the RCurl.

1
I'm guessing I'll have to change this portion of the r code postfields=paste('query',curlEscape(querystring), sep='=')altimit

1 Answers

0
votes

Used this instead

fromJSON(
getURL("http://localhost:7474/db/data/cypher", 
    customrequest='POST', 
    httpheader=c('Content- Type'='application/json'),
    postfields=toJSON(list(query=q2,params=list(pathway=q3)))
  )
)

code modified from : http://pastebin.com/FAeJ0b2R