Title: | Neo4j to R |
---|---|
Description: | The aim of neo2R is to provide simple and low level connectors for querying neo4j graph databases (<https://neo4j.com/>). The objects returned by the query functions are either lists or data.frames with very little post-processing. It allows fast processing of queries returning many records. And it let the users handle post-processing according to the data model and their needs. |
Authors: | Patrice Godard [aut, cre, cph] , Eusebiu Marcu [ctb] |
Maintainer: | Patrice Godard <[email protected]> |
License: | GPL-3 |
Version: | 2.4.2 |
Built: | 2024-11-03 03:49:48 UTC |
Source: | https://github.com/patzaw/neo2r |
Run a cypher query
cypher( graph, query, parameters = NULL, result = c("row", "graph"), arraysAsStrings = TRUE, eltSep = " || " )
cypher( graph, query, parameters = NULL, result = c("row", "graph"), arraysAsStrings = TRUE, eltSep = " || " )
graph |
the neo4j connection |
query |
the cypher query |
parameters |
parameters for the cypher query. |
result |
the way to return results. "row" will return a data frame and "graph" will return a list of nodes, a list of relationships and a list of paths (vectors of relationships identifiers). |
arraysAsStrings |
if result="row" and arraysAsStrings is TRUE (default) array from neo4j are converted to strings and array elements are separated by eltSep. |
eltSep |
if result="row" and arraysAsStrings is TRUE (default) array from neo4j are converted to strings and array elementes are separated by eltSep. |
The "result" of the query (invisible). See the "result" param.
multicypher()
, startGraph()
, prepCql()
,
readCql()
and graphRequest()
## Not run: # 2 identical queries result <- cypher( graph=graph, query='match (n {value:$value}) return n', parameters=list(value="100"), result="graph" ) result <- cypher( graph=graph, query='match (n {value:"100"}) return n', result="graph" ) ## End(Not run)
## Not run: # 2 identical queries result <- cypher( graph=graph, query='match (n {value:$value}) return n', parameters=list(value="100"), result="graph" ) result <- cypher( graph=graph, query='match (n {value:"100"}) return n', result="graph" ) ## End(Not run)
Run a curl request on a neo4j graph
graphRequest(graph, endpoint, customrequest = c("POST", "GET"), postText)
graphRequest(graph, endpoint, customrequest = c("POST", "GET"), postText)
graph |
the neo4j connection |
endpoint |
the endpoint for the request. To list all the available
endpoints:
|
customrequest |
the type of request: "POST" (default) or "GET" |
postText |
the request body |
A list with the "header" and the "result" of the request (invisible)
startGraph()
and cypher()
This function only works with localhost Neo4j instances.
import_from_df(graph, cql, toImport, periodicCommit = 1000, by = Inf, ...)
import_from_df(graph, cql, toImport, periodicCommit = 1000, by = Inf, ...)
graph |
the neo4j connection |
cql |
the CQL query to be applied on each row of toImport. Use the 'row' prefix to refer to the data.frame column. |
toImport |
the data.frame to be imported as "row". Use "row.FIELD" in the cql query to refer to one FIELD of the toImport data.frame |
periodicCommit |
use periodic commit when loading the data (default: 10000). |
by |
number of rows to send by batch (default: Inf). Can be an alternative to periodic commit. |
... |
further parameters for |
Run a multiple cypher queriers
multicypher( graph, queries, parameters = NULL, result = c("row", "graph"), arraysAsStrings = TRUE, eltSep = " || " )
multicypher( graph, queries, parameters = NULL, result = c("row", "graph"), arraysAsStrings = TRUE, eltSep = " || " )
graph |
the neo4j connection |
queries |
queries to submit. It can be either a character vector for which each element corresponds to a cypher query. Or it can be a list of lists with the following slots:
|
parameters |
default parameters for the cypher queries. |
result |
default way to return results. "row" will return a data frame and "graph" will return a list of nodes, a list of relationships and a list of paths (vectors of relationships identifiers). |
arraysAsStrings |
if result="row" and arraysAsStrings is TRUE (default) array from neo4j are converted to strings and array elements are separated by eltSep. |
eltSep |
if result="row" and arraysAsStrings is TRUE (default) array from neo4j are converted to strings and array elementes are separated by eltSep. |
A list of "result" of the queries (invisible). See the "result" param.
cypher()
, startGraph()
, prepCql()
,
readCql()
and graphRequest()
## Not run: result <- multicypher( graph, queries=list( q1="match (n) return n.value limit 5", q2=list( query="match (f {value:$val})-[r]->(t) return f, r, t limit 5", result="graph", parameters=list(val=100) ) ) ) ## End(Not run)
## Not run: result <- multicypher( graph, queries=list( q1="match (n) return n.value limit 5", q2=list( query="match (f {value:$val})-[r]->(t) return f, r, t limit 5", result="graph", parameters=list(val=100) ) ) ) ## End(Not run)
Prepares a CQL query from a character vector
prepCql(...)
prepCql(...)
... |
character vectors with cQL commands |
A well formated CQL query
prepCql(c( "MATCH (n)", "RETURN n" ))
prepCql(c( "MATCH (n)", "RETURN n" ))
Parse a CQL file and returned the prepared queries
readCql(file)
readCql(file)
file |
the name of the file to be parsed |
A character vector of well formated CQL queries
Prepare connection to neo4j database
startGraph( url, database = NA, username = NA, password = NA, importPath = NA, .opts = list(), check = TRUE )
startGraph( url, database = NA, username = NA, password = NA, importPath = NA, .opts = list(), check = TRUE )
url |
the DB url |
database |
the name of the database. If NA (default) it will use "data" with versions 3.. of Neo4j and "neo4j" with versions 4.. |
username |
the neo4j user name (default: NA; works only if authentication has been disabled in neo4j by setting NEO4J.AUTH=none) |
password |
the neo4j user password (default: NA; works only if authentication has been disabled in neo4j by setting NEO4J.AUTH=none) |
importPath |
path to the import directory (default: NA => no import directory). Import only works with local neo4j instance. |
.opts |
a named list identifying the curl
options for the handle (see |
check |
check the connection before returning it (default: TRUE). Set to false when connection to the "system" database |
The "ssl.verifypeer" logical option available in the RCurl package
used in former versions of neo2R (<= 2.2.0) is
not recognized by httr::config()
.
However, for backward compatibility, if it used, it is translated into
"ssl_verifypeer" integer option recognized by the httr package with a
warning message.
Headers in .opts$extendedHeaders
are added to, or overwrite,
the default Neo4j headers.
If there is a .opts$extendedHeaders[["Authorization"]]
value, the
default Neo4j "Authorization" header (user credentials) is provided
automaticaly as "X-Authorization". This mechanism is used for OAuth access
delegation.
A connection to the graph DB: a list with the url and necessary headers