Querying Neo4J

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The function neo4j_query() can be used to send a query to a local or remote Neo4J server. This function uses cypher-shell to send the query to Neo4J, and so the cypher-shell executable needs to be installed and available locally. See the README file for further information on configuration of the cypher-shell executable.

neo4j_query() takes the following arguments:

Example, assuming a local Neo4J instance running the movies graph:

library(neo4jshell)

neo4j_local <- list(address = "bolt://localhost", uid = "neo4j", pwd = "password")
CQL <- 'MATCH (p1:Person {name: "Kevin Bacon"})-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(p2:Person)
        RETURN p2.name AS Name, m.title AS Title'
cypher_path <- path.expand("~/neo4j-community-4.0.4/bin/cypher-shell")
neo4j_query(con = neo4j_local, qry = CQL, shell_path = cypher_path)

This query should return this dataframe:

``` {r example-output, echo = FALSE}

data.frame(Name = c("Ron Howard", "Rob Reiner", "Ron Howard"), Title = c("Frost/Nixon", "A Few Good Men", "Apollo 13"))

```

neo4j_query() accepts multiple query statements separated by ;. The function returns one of the following:

Note for Windows users

Paths to executable files that are provided as arguments to functions may need to be provided with appropriate extensions (eg cypher-shell.bat).



Try the neo4jshell package in your browser

Any scripts or data that you put into this service are public.

neo4jshell documentation built on April 11, 2022, 5:08 p.m.