# Requirements
#sudo apt-get install libcurl4-gnutls-dev # for RCurl on linux
#install.packages('RCurl')
#install.packages('RJSONIO')
library('RCurl')
library('RJSONIO')
query <- function(querystring) {
h = basicTextGatherer()
curlPerform(url="http://localhost:7474/db/data/cypher",
postfields=paste('query',curlEscape(querystring), sep='='),
writefunction = h$update,
verbose = FALSE
)
result <- fromJSON(h$value())
data <- data.frame(t(sapply(result$data, unlist)))
names(data) <- result$columns
data
}
# EXAMPLE
# =======
# Cypher Query:
q <- "match (o:Organization)-[r]-(p:Person) return o.name,o.location,p.account,p.name,p.email limit 20"
data <-query(q)
head(data,20)
# Output:
# o.name o.location p.account p.name p.email
# 1 PerfectLine Estonia kritik
# 2 Sappho OSS London UK andrewheald
# 3 The 88 NYC aface1
# 4 The 88 NYC xbilldozer
# 5 The 88 NYC chadyj
# 6 The 88 NYC benmanns Benjamin Manns benmanns@gmail.net
# 7 simplabs Munich, Germany marcoow
# 8 Everyday Hero Brisbane, Australia soloman1124
# 9 Everyday Hero Brisbane, Australia orodio
# 10 Everyday Hero Brisbane, Australia justinhennessy
# 11 Everyday Hero Brisbane, Australia coop Tim Cooper coop@latrobest.org
# 12 Everyday Hero Brisbane, Australia evilmarty Marty Zalega marty@zalega.co
# 13 Sorenson Media Salt Lake City, UT & San Diego, CA bcarlson
# 14 Sorenson Media Salt Lake City, UT & San Diego, CA elmomalmo
# 15 Sorenson Media Salt Lake City, UT & San Diego, CA enthooz
# 16 3scale Barcelona, Spain and Sunnyvale, USA solso
# 17 3scale Barcelona, Spain and Sunnyvale, USA MarkCheshire
# 18 3scale Barcelona, Spain and Sunnyvale, USA rhoml
# 19 3scale Barcelona, Spain and Sunnyvale, USA mikz Michal Cichra
# 20 3scale Barcelona, Spain and Sunnyvale, USA njyx