Code Monkey home page Code Monkey logo

rneo4j's Introduction

RNeo4j Build Status

RNeo4j is Neo4j's R driver. It allows you to read and write data from / to Neo4j directly from your R environment.

Contents

Install

Neo4j

First and foremost, download Neo4j!

Windows

If you're on Windows, download the .exe and follow the instructions. You'll get a GUI where you simply press "Start" to start Neo4j.

OS X

If you're on OS X, you can download either the .dmg or the .tar.gz. The .dmg will give you a GUI where you simply press "Start" to start Neo4j. Otherwise, download the .tar.gz, unzip, navigate to the directory and execute ./bin/neo4j start.

Linux

If you're on Linux, you have to use the .tar.gz. Download the .tar.gz, unzip, navigate to the directory and execute ./bin/neo4j start.

You may also find neo4j in your distribution's package manager.

Bolt dependencies

These depencies are are only required if you want to use the Bolt interface. They must be present at build time, and libneo4j-client must also be present at runtime.

Windows

  • Rust: https://rustup.rs
  • Clang: binary releases are available at http://releases.llvm.org/download.html
  • libneo4j-client:
    • Make sure you have RTools installed (necessary for building R packages on Windows)
    • Open your MinGW shell (check in start menu, C:\RTools\MinGW\bin, and C:\MinGW\bin)
    • See "Installing libneo4j-from source" section

OS X (with Homebrew installed)

  • Rust: brew install rust (or https://rustup.rs but see "Rust Path" section)
  • Clang: brew install llvm
  • libneo4j-client: brew install cleishm/neo4j/libneo4j-client

Linux

  • Rust:
    • Debian based (e.g. Mint, Ubuntu): sudo apt-get install cargo
    • Arch Linux: sudo pacman -S rust
    • Building from source: https://rustup.rs but see "Rust Path" section
  • Clang: get it from your package manager
    • Debian based (e.g. Mint, Ubuntu): sudo apt-get install clang libclang-dev
    • Arch Linux: sudo pacman -S clang
    • Other: your package manager almost certainly has clang. It may be called llvm.
  • libneo4j-client:
    • Debian based: sudo apt-get install libneo4j-client-dev
    • Other: See "Installing libneo4j-client from source"

Rust Path

By default, on *nix systems (such as Linux and OS X), rustup only sets the PATH in your shell. That means that if you try to build RNeo4j in a GUI application like RStudio, it may fail. To work around this issue, simply build RNeo4j in a terminal.

Installing libneo4j-client from source

Newer versions of GCC require removing the -Werror from GCC_CFLAGS in configure.ac.

Run these commands in your shell:

git clone https://github.com/cleishm/libneo4j-client
cd libneo4j-client
./autogen.sh
./configure --disable-tools
sudo make install

See https://github.com/cleishm/libneo4j-client for more details

RNeo4j

From CRAN

install.packages("RNeo4j")

From GitHub

devtools::install_github("nicolewhite/RNeo4j")

From Source

Go to the latest release and download the source code. You can then install with install.packages.

install.packages("/path/to/file.tar.gz", repos=NULL, type="source")

Load the Package

library(RNeo4j)

Connect

graph = startGraph("http://localhost:7474/db/data/")

If you have authentication enabled, pass your username and password.

graph = startGraph("http://localhost:7474/db/data/", username="neo4j", password="password")

Nodes

nicole = createNode(graph, "Person", name="Nicole", age=24)
greta = createNode(graph, "Person", name="Greta", age=24)
kenny = createNode(graph, "Person", name="Kenny", age=27)
shannon = createNode(graph, "Person", name="Shannon", age=23)

Relationships

r1 = createRel(greta, "LIKES", nicole, weight=7)
r2 = createRel(nicole, "LIKES", kenny, weight=1)
r3 = createRel(kenny, "LIKES", shannon, weight=3)
r4 = createRel(nicole, "LIKES", shannon, weight=5)

Cypher

If you're returning tabular results, use cypher, which will give you a data.frame.

query = "
MATCH (nicole:Person)-[r:LIKES]->(p:Person)
WHERE nicole.name = 'Nicole'
RETURN nicole.name, r.weight, p.name
"

cypher(graph, query)
##   nicole.name r.weight  p.name
## 1      Nicole        5 Shannon
## 2      Nicole        1   Kenny

For anything more complicated, use cypherToList, which will give you a list.

query = "
MATCH (nicole:Person)-[:LIKES]->(p:Person)
WHERE nicole.name = 'Nicole'
RETURN nicole, COLLECT(p.name) AS friends
"

cypherToList(graph, query)
## [[1]]
## [[1]]$nicole
## < Node > 
## Person
## 
## $name
## [1] "Nicole"
## 
## $age
## [1] 24
## 
## 
## [[1]]$friends
## [[1]]$friends[[1]]
## [1] "Shannon"
## 
## [[1]]$friends[[2]]
## [1] "Kenny"

Both cypher and cypherToList accept parameters. These parameters can be passed individually or as a list.

query = "
MATCH (p1:Person)-[r:LIKES]->(p2:Person)
WHERE p1.name = {name1} AND p2.name = {name2}
RETURN p1.name, r.weight, p2.name
"

cypher(graph, query, name1="Nicole", name2="Shannon")
##   p1.name r.weight p2.name
## 1  Nicole        5 Shannon
cypher(graph, query, list(name1="Nicole", name2="Shannon"))
##   p1.name r.weight p2.name
## 1  Nicole        5 Shannon

Shortest Paths

p = shortestPath(greta, "LIKES", shannon, max_depth=4)
n = nodes(p)
sapply(n, "[[", "name")
## [1] "Greta"   "Nicole"  "Shannon"

Weighted Shortest Paths

p = shortestPath(greta, "LIKES", shannon, max_depth=4, cost_property="weight")
n = nodes(p)
sapply(n, "[[", "name")
## [1] "Greta"   "Nicole"  "Kenny"   "Shannon"
p$weight
## [1] 11

Graph Algorithms

library(igraph)

query = "
MATCH (n)-->(m)
RETURN n.name, m.name
"

edgelist = cypher(graph, query)
ig = graph.data.frame(edgelist, directed=F)

betweenness(ig)
##  Nicole   Greta   Kenny Shannon 
##       2       0       0       0
closeness(ig)
##    Nicole     Greta     Kenny   Shannon 
## 0.3333333 0.2000000 0.2500000 0.2500000

Visualizations

igraph

plot(ig)

plot of chunk unnamed-chunk-16

ggnet

library(network)
library(GGally)

net = network(edgelist)
ggnet(net, label.nodes=TRUE)

plot of chunk unnamed-chunk-17

visNetwork

Read this blog post and check out this slide deck.

Import

library(hflights)
hflights = hflights[sample(nrow(hflights), 1000), ]
row.names(hflights) = NULL

head(hflights)
##   Year Month DayofMonth DayOfWeek DepTime ArrTime UniqueCarrier FlightNum
## 1 2011     1         15         6     927    1038            XE      2885
## 2 2011    10         10         1    2001    2322            XE      4243
## 3 2011     6         15         3    1853    2108            CO       670
## 4 2011     4         10         7    2100     102            CO       410
## 5 2011     1         25         2     739    1016            XE      3083
## 6 2011     9         13         2    1745    1841            CO      1204
##   TailNum ActualElapsedTime AirTime ArrDelay DepDelay Origin Dest Distance
## 1  N34110               131     113      -10       -3    IAH  COS      809
## 2  N13970               141     127        2       19    IAH  CMH      986
## 3  N36207               255     231       15       -2    IAH  SFO     1635
## 4  N76517               182     162      -18        5    IAH  EWR     1400
## 5  N12922               157     128        0       -6    IAH  MKE      984
## 6  N35271                56      34       -7       -5    IAH  SAT      191
##   TaxiIn TaxiOut Cancelled CancellationCode Diverted
## 1      6      12         0                         0
## 2      4      10         0                         0
## 3      5      19         0                         0
## 4      7      13         0                         0
## 5      4      25         0                         0
## 6      3      19         0                         0
addConstraint(graph, "Carrier", "name")
addConstraint(graph, "Airport", "name")

query = "
CREATE (flight:Flight {number: {FlightNum} })
SET flight.year = TOINT({Year}),
    flight.month = TOINT({DayofMonth}),
    flight.day = TOINT({DayOfWeek})

MERGE (carrier:Carrier {name: {UniqueCarrier} })
CREATE (flight)-[:OPERATED_BY]->(carrier)

MERGE (origin:Airport {name: {Origin} })
MERGE (dest:Airport {name: {Dest} })

CREATE (flight)-[o:ORIGIN]->(origin)
CREATE (flight)-[d:DESTINATION]->(dest)

SET o.delay = TOINT({DepDelay}),
    o.taxi_time = TOINT({TaxiOut})

SET d.delay = TOINT({ArrDelay}),
    d.taxi_time = TOINT({TaxiIn})
"

tx = newTransaction(graph)

for(i in 1:nrow(hflights)) {
  row = hflights[i, ]
  
  appendCypher(tx, query,
               FlightNum=row$FlightNum,
               Year=row$Year,
               DayofMonth=row$DayofMonth,
               DayOfWeek=row$DayOfWeek,
               UniqueCarrier=row$UniqueCarrier,
               Origin=row$Origin,
               Dest=row$Dest,
               DepDelay=row$DepDelay,
               TaxiOut=row$TaxiOut,
               ArrDelay=row$ArrDelay,
               TaxiIn=row$TaxiIn)
}

commit(tx)

summary(graph)
##     This          To    That
## 1 Flight OPERATED_BY Carrier
## 2 Flight      ORIGIN Airport
## 3 Flight DESTINATION Airport

Connection Issues

Couldn't connect to server

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Couldn't connect to server

Neo4j probably isn't running. Make sure Neo4j is running first. It's also possible you have localhost resolution issues; try connecting to http://127.0.0.1:7474/db/data/ instead.

No authorization header supplied

Error: client error: (401) Unauthorized
Neo.ClientError.Security.AuthorizationFailed
No authorization header supplied.

You have auth enabled on Neo4j and either didn't provide your username and password or they were invalid. You can pass a username and password to startGraph.

graph = startGraph("http://localhost:7474/db/data/", username="neo4j", password="password")

You can also disable auth by editing the following line in conf/neo4j-server.properties.

# Require (or disable the requirement of) auth to access Neo4j
dbms.security.auth_enabled=false

Contribute

Check out the contributing doc if you'd like to contribute!

rneo4j's People

Contributors

ajkl avatar boltomli avatar darrkj avatar jexp avatar mpancia avatar nicolewhite avatar plasmapower avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rneo4j's Issues

Error on: importSample(graph, "dfw");

Hello,

I am seeing following error while running a shiny app (http://nicolewhite.github.io/2014/06/30/create-shiny-app-neo4j-graphene.html) :
importSample(graph, "dfw");
You are about to delete all nodes, relationships, indexes, and constraints from the graph database. Are you sure? Y/N
1: Y
Error: Client error: (400) Bad Request
Neo.ClientError.Statement.SyntaxError
Parentheses are required to identify nodes in patterns, i.e. (_5) (line 288, column 8 (offset: 10571))
"create _5-[:IN_TERMINAL]->_0"

Am I missing something?

Best,
Vijay

clear(graph) RNeo4j issues client error: (400) Bad Request

I am using RStudio to create and run the Neo4j graph, and it suddenly started the client error: (400) Bad Request when I try to clear the graph.

clear(graph)
You are about to delete all nodes, relationships, indexes, and constraints from the graph database. Are you sure? Y/N
1: Y
Error: client error: (400) Bad Request

Graph version is
< Graph >
$version
[1] "2.3.0"

RStudio is Version 0.99.489

Please help.

Clear Graph throws 404 error

I am trying to clear my graph after playing around.

> clear(graph)
You are about to delete all nodes, relationships, indexes, and constraints from the graph database. Are you      sure? Y/N
1: Y
Error: 404 Not Found

Here is my version:

> graph$version  
[1] "2.0.0-RC1" 

And to verify that I have some data, a few queries:

query = "MATCH (n) RETURN COUNT(n) as total LIMIT 100"
cypher(graph, query)
total
1 2

query = "MATCH (n) RETURN n.name as Name"
cypher(graph, query)
Name
1 Alice
2 Bentley University

getLabel(graph)
[1] "College" "Person"

More than likely, this is something on my end, but I wasn't sure why this would error out.

image

In case it helps, here is my session info:

image

RNeo4j handling NA properties

Hi Nicole,
Not sure if this is to be discussed in another forum.
For the label "User" with a constraint on field user_id_hash, if we try the following -

n=getOrCreateNode(g,"User",user_id_hash="john",age=NA,address="") #1
n=getOrCreateNode(g,"User",user_id_hash="john",address="") #2
Here the command #1 does not return any error, but it does not result in the creation of a node/vertex and hence n is NULL.
Whereas #2 creates a node with the two properties user_id_hash and address (value is empty for address).

1 will be encountered frequently if we are trying to create nodes/relationships from the data frame.

Is it expected to silently skip records if fields are NA? Because it would be convenient for troubleshooting if it throws an error related to NA.

Thanks for this package!,
John

list returned by cypherToList results in error when list evaluated by str

When executing the following:

p =  cypherToList(neo4j, query)
str(p)

str indicates the following error:

file.info(x) File name argument is invalid

This behavior is not observed when using deprecated getPaths (str evaluates successfully)

p = getPaths(neo4j, query)
str(p)

Let me know if you need any further details.

Error in httr::content(response)$errors

"""
Hello Nicole,

I'm new to both R and Neo4j. Please could you help me with the following issue?

I have a graph in Neo4j. It was built by someone not using RNeo4j. I can make queries in Neo4j directly, and it gives me the results I expect. In R, I get errors as follows:

In R:

  1. I use graph= startGraph(my machine, login, password) , and that executes OK.
  2. I set a query string, query="MATCH (some parameters)"
  3. call cypher(graph, query)

The output is:

Error in httr::content(response)$errors :
$ operator is invalid for atomic vectors

I get the same output also if I try to return anything.
Please could you give me some advice? Thank you.
"""

"""
I found the problem 30 minutes ago. I was missing the slash at the end of the url.
"""

neo4j default security config and cURL

I downloaded / installed a default configuration of neo4j 2.2.3 and attempted to connect using the startGraph function.

However, I kept receiving the following curl error from RNeo4j

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Couldn't connect to server

Even though I was connecting via localhost, it turns out that I had to modify/enable the following directive in the neo4j-server.properties file

# Let the webserver only listen on the specified IP. Default is localhost (only
# accept local connections). Uncomment to allow any connection. Please see the
# security section in the neo4j manual before modifying this.
org.neo4j.server.webserver.address=0.0.0.0

I hope this helps someone else out.

Error loading RNeo4j

Hi, I downloaded the RNeo4j from github with the install_github function from devtools R package .

> devtools::install_github("nicolewhite/RNeo4j")
Downloading github repo nicolewhite/RNeo4j@master
Installing RNeo4j
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore CMD INSTALL  \
  '/private/var/folders/m4/j55x1ddj58b2jtmjppvcs5fr0000gr/T/Rtmp7tPczw/devtools347f4798c51b/nicolewhite-RNeo4j-13e8bfe'  \
  --library='/Users/sawsimeon/Library/R/3.1/library' --install-tests 

* installing *source* package ‘RNeo4j’ ...
** R
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (RNeo4j)

It was successfully installed. However, when I try to load the RNeo4j package.

> library(RNeo4j)
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
  namespace ‘httr’ 0.6.1 is already loaded, but >= 1.0.0 is required
Error: package or namespace load failed for ‘RNeo4j’

From the complains, it just said that my httr package version is out-of-date. But, this is not the case because from my sessionInfo() i have a httr version of 1.0.0

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] parallel  stats4    grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] devtools_1.8.0       httr_1.0.0           seqinr_3.1-3         ade4_1.7-2           Rcpi_1.2.0          
 [6] AnnotationDbi_1.28.2 GenomeInfoDb_1.2.5   IRanges_2.0.1        S4Vectors_0.4.0      Biobase_2.26.0      
[11] BiocGenerics_0.12.1  RSQLite_1.0.0        DBI_0.3.1            Rwebdriver_0.1       RJSONIO_1.3-0       
[16] manipulate_0.98.1103 igraph_0.7.1         XML_3.98-1.1         stringr_1.0.0        RCurl_1.95-4.7      
[21] bitops_1.0-6         cowplot_0.3.1        ggplot2_1.0.1       

loaded via a namespace (and not attached):
 [1] Biostrings_2.34.1 ChemmineR_2.18.1  codetools_0.2-11  colorspace_1.2-6  digest_0.6.8      doParallel_1.0.8 
 [7] fingerprint_3.5.2 fmcsR_1.8.0       foreach_1.4.2     git2r_0.10.1      GO.db_3.0.0       GOSemSim_1.24.1  
[13] gtable_0.1.2      iterators_1.0.7   labeling_0.3      magrittr_1.5      MASS_7.3-40       memoise_0.2.1    
[19] munsell_0.4.2     plyr_1.8.2        png_0.1-7         proto_0.3-10      rcdk_3.3.2        rcdklibs_1.5.8.4 
[25] Rcpp_0.11.6       reshape2_1.4.1    rJava_0.9-6       rjson_0.2.15      rversions_1.0.0   scales_0.2.4     
[31] stringi_0.4-1     tools_3.1.2       XVector_0.6.0     zlibbioc_1.12.0  

Help is greatly appreciated.

Error on getNodes()

Following code

tweets = getNodes(Graph, "MATCH (t:Tweet) WHERE HAS(t.text) RETURN t")

gives error
Error in fromJSON(content, handler, default.size, depth, allowComments, :
invalid JSON input

This is on a set of 50k+ tweets. If limit is used to return smaller set of tweets then works fine.

Functionality to leverage the Command Line

This is an idea for an enhancement, but admittedly I don't know how feasible it is or effecient. Is it possible to create a function that allows the user to call neo4j-shell through ?system and import a file of cypher statements?

Here is my use case. A nightly job that does:

  1. Data acquisition, cleansing, transforming done with R
  2. Save the data out to csv's for import (same file name/location each run)
  3. Using this library, call a function that would mirror something like $neo4j-shell -f /path/to/file.cql where the .cql file has the commands with the LOAD CSV statement referencing the CSV files from step 2.

I suppose we could do this all through bash, but given my strengths are mostly within R, I am trying to be lazy and automate my entire workflow totally within R.

Error in cypher() - invalid JSON

Running the following query:

match (g1:Gem)-[r:COAUTHOR]->(g2:Gem) 
return id(g1) as source, id(g2) as target, r.multiplicity as multiplicity,
r.source_since as `source.since`, r.source_until as `source.until`, r.source_ceased as `source.ceased`,
r.target_since as `target.since`, r.target_until as `target.until`, r.target_ceased as `target.ceased`;

results in the following error:

Error in fromJSON(content, handler, default.size, depth, allowComments,  : 
  invalid JSON input

While the following query:

match (g1:Gem)-[r:COAUTHOR]->(g2:Gem) 
return id(g1) as source, id(g2) as target, r.multiplicity as multiplicity,
r.source_since as `source.since`, r.source_until as `source.until`, r.source_ceased as `source.ceased`,
r.target_since as `target.since`, r.target_until as `target.until`, r.target_ceased as `target.ceased`
limit 1000000;

completes successfully.

Given that the query results in only 448005 records (the limit does not actually limit the results), I can't understand why the two queries behave differently. I tried changing names and labels, etc., but that did not improve the behaviour. By the way, both queries run fine on Neo4j.

`from` / `to` property names in `createRel`

Hi Nicole,

just came across this edge case when trying to create relationships with from and to properties. There seems to be conflict when dispatching createRel method, when properties are named as such:

n1 = createNode(graph, name="Node1")
n2 = createNode(graph, name="Node2")

createRel(n1, "HOLDS", n2, from="a") # Error: Invalid object. Must supply node object.
createRel(n1, "HOLDS", n2, to=1) # Error: "node" %in% class(toNode) is not TRUE
createRel(n1, "HOLDS", n2, othername=as.factor(2)) #ok
createRel(n1, "HOLDS", n2, From=123) #ok
createRel(n1, "HOLDS", n2, To="foo") #ok

Perhaps ?setAs arguments with the same name causing the conflict during dispatch process?

Returning pathways as R objects.

Per this question, adding pathway functionality would add a lot of value to those users using the low-level API endpoints.

Plans include:

query = "
MATCH p = shortestPath((n)-[:KNOWS*]-(m))
WHERE n.name = 'Nicole' AND m.name = 'Aaron'
RETURN p
"

path = getPath(graph, query)
start = startNode(path)
end = endNode(path)
rels = relationships(path)
nodes = nodes(path)
query = "
MATCH p = allShortestPaths((n)-[:KNOWS*]-(m))
WHERE n.name = 'Nicole' AND m.name = 'Aaron'
RETURN p
"

paths = getPaths(graph, query)
starts = lapply(paths, startNode)
ends = lapply(paths, endNode)
rels = lapply(paths, relationships)
nodes = lapply(paths, nodes)

namespace collision, on "connection"? Found more than one class "connection" in cache; using the first, from namespace 'BiocGenerics

Hi Nicole,

I think I have encountered an obscure and easily solved non-fatal problem in RNeo4j. It has to do, I think, with namespaces in R packages. Here is the text of the warning, followed by the identical problem cropping up in RStudio, which they quickly fixed.

The warning (issued once for every message sent between R and Neo4J:

Found more than one class "connection" in cache; using the first, from namespace 'BiocGenerics'

And the very similar report from RStudio (you keep good company!):

https://groups.google.com/forum/#!topic/shinyapps-users/OUC0J6ahYAc

My time with the Bioconductor project probably biases me somewhat, but I think that Martin Morgan, Herve and Dan probably refined Biocgenerics so that it follows all the rules.

Here's my sessionInfo:

R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)

locale:
[1] C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] edgeR_3.12.0 limma_3.26.7 RNeo4j_1.6.3 trena_1.0 RCyjs_1.3.5 graph_1.48.0
[7] BrowserViz_1.3.2 httpuv_1.3.3 jsonlite_0.9.19 BiocInstaller_1.20.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.3 mime_0.4 R6_2.1.2 stats4_3.2.3 magrittr_1.5 httr_1.1.0
[7] curl_0.9.5 RJSONIO_1.3-0 tools_3.2.3 igraph_1.0.1 compiler_3.2.3 parallel_3.2.3
[13] BiocGenerics_0.16.1

Error Message appendCypher(): "code" : "Neo.ClientError.Security.AuthorizationFailed"...

I have just started with Neo4j v2.2.1,

I followed the link: http://stackoverflow.com/questions/25295590/how-to-create-nodes-in-rneo4j-using-vectors-or-dataframes
and also the demo: http://watch.neo4j.org/video/105896138?_ga=1.174865570.1897839624.1431007064

However, when I try the code within the 1st link, in particular:
appendCypher(t, query, origin_name = origin_name, dest_name = dest_name, flight_num = flight_num)

I get the error message:
Error: 401 Unauthorized
``{ "errors" : [ {`
`"code" : "Neo.ClientError.Security.AuthorizationFailed",`
`"message" : "No authorization header supplied."`
`} ]`
`}`

(this is the same error I got by doing when typing
graph = startGraph("http://localhost:7474/db/data/")
which I solved by including username and password, but here this does not seem to apply...)

I am sure I am doing something wrong and surely the solution is fairly trivial, but after some time trying, I could make use of some help.

By the way, I just though that posting this issue in Stackoverflow (http://stackoverflow.com/questions/30221409/rneo4j-appendcypher-error-error-401-unauthorized) would perhaps reach more RNeo4j users, and it seems I cannot remove it from here. Therefore, whoever replies can do it either here or there, whatever he/she things is better (and sorry for the duplicate).

Thanks in advance for your time.

Plot method

I have a package where I have been playing with analytic type functionality on top of Neo4j. I added a method to generate a sankey plot from all of the edges and nodes in the database. I think it would be a better fit in RNeo4j though, maybe as plot.graph. Here is an example: https://github.com/darrkj/labyrinth/blob/master/sankey.md

It shows how all of the nodes are connected to all of the other nodes, via the type of edge. Would you be interested in moving this into RNeo4j?

Collection coercion.

RNeo4j coerces the types of a collection to strings. This is a problem when the collection introduced to the db has different types.

[TRUE, "Sam"]
-> "TRUE", "Sam"

Where the expected behavior would be an error because Neo4j only allows for one type for all members in collections.

RNeo4j 2.0

Changes I want to make for RNeo4j 2.0

  • Consistent return types, e.g. return an empty data.frame instead of NULL when there are no results from cypher()
  • Change the default direction to direction="all" in shortestPath and allShortestPaths
  • Remove deprecated functions like getNodes
  • Rename startGraph to Graph
  • Basically just copy py2neo

Array properties

Hello Nicole,

is it possible to create nodes or relationships with array properties?

library(RJSONIO)
n1 = createNode(graph, name="Node1")
n2 = createNode(graph, name="Node2")
createRel(n1, type="HOLDS", n2, arrayproperty=RJSONIO::toJSON(c(1, 3, 8)))

This query returned NA:

cypher(graph, "MATCH (a)-[r:HOLDS]->(b) RETURN r.arrayproperty[2]")

is.request(y) is not TRUE

Just upgraded R to 3.2.1 this morning, Neo4j to 2.2.3, and RNeo4j to 1.4.1. I'm able to create a graph object (with authentication) but when I try to create a node I get this:

alice = createNode(graph, "Person", name="Alice")
Error: is.request(y) is not TRUE

I get the same response if I try to clear(graph). Cypher create and match queries from the browser appear to work fine. Any ideas?

possible encoding issue?

Hi
I am having some issues with encoding.
Reproducible example here:

library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")
graph$version
clear(graph)
mugshots = createNode(graph, "Bar", name = "Mugshots", location = "México")
mugshots$location
#[1] "México"

Any ideas?
My guess is that for some reason RNeo4j is not keeping UTF-8 encoding when parsing json responses

Cheers

RNeo4j compatible with Neo4j 3.0.3

Hi,

I hope you are doing well.

I was wondering if RNeo4j is compatible with Neo4j 3.0.3?

Many thanks in advance for your help.

Bastian

Clear Graph without Manual Input

Not really an issue per se, but a feature request.

Would you consider adding an option to the clear function in which the user can automatically wipe the database without the need for user input on the keyboard?

My use-case is in scripting in RMD files as well as bootstrapping analyses on smaller graphs.

Construct graph & Append new node/edge based on path only?

Hi,

I wanted to create a graph without having to define node info and purely based on the list of relation info (linear).

for example, RelA,RelB,RelC,RelD, in this path, it involves 5 nodes (anonymous) and 4 defined edges.
what I did manually is below:
CREATE (n)-[:RelA]->(m)

MATCH (x)-[:RelA]->(n)
WITH n
CREATE (n)-[:RelB]->(m)

MATCH (x)-[:RelA]->(y)-[:RelB]->(n)
WITH n
CREATE (n)-[:RelC]->(m)

MATCH (x)-[:RelA]->(y)-[:RelB]->(z)-[:RelC]->(n)
WITH n
CREATE (n)-[:RelC]->(b)

The reason for the complicated matching is because there might be other paths which indicate a different branch, for example:
RelA,RelB1,RelC,RelD In this case, the starting node and 2nd node will be identical with the nodes created above, however, the 3rd node (after RelB1) is different from the 3rd node above. Consequently, the 4th and 5th Node will be different although the relation is the same. They are different because the starting point (3rd node) is different now.

updateProps doesn't seem to work with arrays/vectors

Hi again Nicole ;)

updateProps is not working when one tries to update properties that are vectors(R)/arrays(Neo4j)

I guess the problem lies here:
https://github.com/nicolewhite/RNeo4j/blob/master/R/updateProp.R#L18-19
Maybe using toJSON instead of the hardcoded " " surrounding the properties will fix it.

Here is a reproducible example:

library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")
graph$version
clear(graph)
mugshots = createNode(graph, "Bar", name = "Mugshots", locations = c("México","USA"))
mugshots$locations

query = "MATCH (p:Bar {name:{name}})
         RETURN p"
m = getSingleNode(graph, query, name = "Mugshots")

updateProp(m, name = "Mugs") 
#OK
updateProp(m,locations = c("México","USA","Canada")) 
#ERROR

ig = graph.data.frame gives error

Hi,

I am going through your tutorial (https://github.com/nicolewhite/RNeo4j).

When I am in the Graph Algorithms part (https://github.com/nicolewhite/RNeo4j#graph-algorithms) and I execute the following:
query = "MATCH (n)-->(m) RETURN n.name, m.name "

edgelist = cypher(graph, query)

ig = graph.data.frame(edgelist, directed=F)

I get the following error:
Error: could not find function "graph.data.frame"

What could it be?

Many thanks in advance for your help.

By the way, great job on the RNeo4j package - it's a blast.

Greetings from Switzerland,

Bastian

Installation fails with 'Error: contains a blank line'

Install via R studio cmd line trace follows

install.packages("devtools")
Installing package(s) into ‘C:/Program Files/R/R-2.15.3/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/windows/contrib/2.15/devtools_1.4.1.zip'
Content type 'application/zip' length 238988 bytes (233 Kb)
opened URL
downloaded 233 Kb

package ‘devtools’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\XYZ\AppData\Local\Temp\Rtmpo1GABU\downloaded_packages

devtools::install_github("nicolewhite/RNeo4j")
Installing github repo RNeo4j/master from nicolewhite
Downloading RNeo4j.zip from https://github.com/nicolewhite/RNeo4j/archive/master.zip
Installing package from C:\Users\XYZ\AppData\Local\Temp\Rtmpo1GABU/RNeo4j.zip
Installing RNeo4j
"C:/PROGRA1/R/R-2151.3/bin/x64/R" --vanilla CMD INSTALL
"C:\Users\XYZ\AppData\Local\Temp\Rtmpo1GABU\devtools240442544a26\RNeo4j-master" --library="C:/Program
Files/R/R-2.15.3/library" --install-tests

Error: contains a blank line
Error: Command failed (1)

Get full graph into json format gives error?

I think sometimes it is useful to get the full graph (or in alternative a chunk of it) into a json format for later manipulation in R.
From the cypher console I can do the following:

:POST /db/data/transaction/commit
  {"statements":[{"statement":"MATCH path = (n)-[r]->(m) RETURN path", "resultDataContents":["graph"]}]}

And I can download a json source will all nodes / labels etc.: it sounds exactly what I need: I then can use different types of graph visualisations in R htmlwidgets-based.

I cannot do the same with rneo4j as the query crashes:

> jsonGraph <- '
+ :POST /db/data/transaction/commit
+   {"statements":[{"statement":"MATCH path = (n)-[r]->(m) RETURN path", "resultDataContents":["graph"]}]}
+ '
> jsonStr <- cypher(graph, jsonGraph)
Error: 400 Bad Request

{"message":"Invalid input ':': expected <init> (line 1, column 1 (offset: 0))\n\":POST /db/data/transaction/commit\"\n ^","exception":"SyntaxException","fullname":"org.neo4j.cypher.SyntaxException","stacktrace":["org.neo4j.cypher.internal.compatibility.exceptionHandlerFor2_2$.syntaxException(CompatibilityFor2_2.scala:53)","org.neo4j.cypher.internal.compatibility.exceptionHandlerFor2_2$.syntaxException(CompatibilityFor2_2.scala:52)","org.neo4j.cypher.internal.compiler.v2_2.SyntaxException.mapToPublic(CypherException.scala:128)","org.neo4j.cypher.internal.compatibility.exceptionHandlerFor2_2$.runSafely(CompatibilityFor2_2.scala:109)","org.neo4j.cypher.internal.compatibility.CompatibilityFor2_2$$anon$2.plan(CompatibilityFor2_2.scala:149)","org.neo4j.cypher.ExecutionEngine$$anonfun$liftedTree1$1$1$$anonfun$apply$1.apply(ExecutionEngine.scala:149)","org.neo4j.cypher.ExecutionEngine$$anonfun$liftedTree1$1$1$$anonfun$apply$1.apply(ExecutionEngine.scala:146)","org.neo4

What do I do wrong?

graph connection error via https self signed certificates

In R-Studio I get the following error:

graph
< Graph Object >
$version
[1] "2.2.0"
library(RNeo4j)
graph = startGraph("https://localhost:7473/db/data/")
Error in function (type, msg, asError = TRUE) :
SSL certificate problem: self signed certificate

In case you want to reproduce the Neo4J setup, I configured the SSL certificate as follows:
$ sudo mkdir -p /var/ssl/neo4j
$ sudo openssl genrsa -des3 -out /var/ssl/ca.key 4096
$ sudo openssl req -new -x509 -days 365 -key /var/ssl/ca.key -out /var/ssl/ca.crt
$ sudo openssl genrsa -des3 -out /var/ssl/neo4j/server.key 4096
$ sudo openssl req -new -key /var/ssl/neo4j/server.key -out /var/ssl/neo4j/server.csr
$ sudo openssl x509 -req -days 365 -in /var/ssl/neo4j/server.csr -CA /var/ssl/ca.crt -CAkey /var/ssl/ca.key -set_serial 01 -out /var/ssl/neo4j/server.crt

Regards,
Rob

Passing Numeric Version of Sys.time() back and forth

I had an idea to store my date/times as numerics, so I could at least do some simple math operations on them. I also assume it's less expensive to store a numeric value over the string version of "2015-06-14 17:11:34".

The code below didn't return the value back to me as expected. More than likely it is something obvious that I am overlooking, but I would have guessed that these two values would have been the same.

library(RNeo4j)

##  connect to a clean graph
graph = startGraph("http://localhost:7474/db/data/", 
                   user = "neo4j", 
                   password = "password")
clear(graph, input = F)

## make sure there are no data - sanity check
cypher(graph, "MATCH (n) RETURN COUNT(n) as TOTAL")

## create a timsstamp
time_stamp = as.numeric(Sys.time())

## put into neo4j
cypher(graph, "MERGE (n:Node {time:toFloat({TIME_STAMP})}) ", TIME_STAMP = time_stamp)

## bring it back
time_stamp_check = cypherToList(graph, "MATCH (n:Node) RETURN n")
length(time_stamp_check)
time_test = time_stamp_check[[1]]$n$time

## check
time_test ==  time_stamp
time_test
time_stamp

## print the system info
sessionInfo()
graph$version

> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RNeo4j_1.4.0

loaded via a namespace (and not attached):
[1] httr_0.6.1           tools_3.2.0          rstudioapi_0.3.1     RCurl_1.95-4.5       RJSONIO_1.3-0       
[6] jsonlite_0.9.16.9000 stringr_0.6.2        mime_0.3             bitops_1.0-6        
> graph$version
[1] "2.2.0"

RNeo4j not connecting with dbms.security.auth_enabled=true

By default Neo4j is now configured with authentication on.

cat neo4j/conf/neo4j-server.properties | grep auth

... dbms.security.auth_enabled=true

It would be nice to connect from RNeo4j and be able to authenticate.

In R-Studio I get the following error:

graph
< Graph Object >
$version
[1] "2.2.0"
library(RNeo4j)
graph = startGraph("http://192.168.178.88:7474/db/data/")
Error: 401 Unauthorized

{
"errors" : [ {
"code" : "Neo.ClientError.Security.AuthorizationFailed",
"message" : "No authorization header supplied."
} ]
}

Documentation Method

I was wondering if you had any interest in starting to document this package using Roxygen. Here is a link which introduces some concepts related to roxygen, http://cran.r-project.org/web/packages/roxygen2/vignettes/roxygen2.html.

You can also modify the project in RStudio to run the documentation function when building so updating the help files is automatic. Another perk is since the roxy style comments are near the actual source code it is easier to keep the two in sync. It also manages the NAMESPACE and DESCRIPTION files by adding functions that use the export tag.

A more detailed discussion can be found here, http://r-pkgs.had.co.nz/man.html

Is RNeo4j Transactional Endpoint slow?

Got used to import a csv via the neo4j console. I had 50000 rows.
After setting up an index I imported them in about 0.8 sec

Tried the same thing today with the transactional endpoint and it took 3 mins.

Is it that slow or am I doing something wrong?

Error in appendCypher.transaction(): Neo.DatabaseError.Statement.ExecutionFailure Could not create token

This post relates to the issue: #23 . There was a bug that has now been fixed (54139ed).

I then re-installed the whole RNeo4j package:

devtools::install_github("nicolewhite/RNeo4j")

I know do not see the previous Authorization error. Instead, I get the following one:

Error in appendCypher.transaction(t, query, origin_name = origin_name, : Neo.DatabaseError.Statement.ExecutionFailure Could not create token

I am using Neo4j 2.2.1.

I have tried to specify the Authorization token when starting the graph with startGraph but it does not work. Moreover, I read here (http://stackoverflow.com/questions/29434079/how-to-get-neo4j-2-2-auth-api-token) that api token authentication has been removed.

It seems that this error is not related to this line of code:
attr(transaction, "auth_token") = attr(graph, "auth_token")
in the newTransaction function.

At this stage I do not know what to try other than testing with previous versions of Neo4j

Fuzzy search

Hi Nicole,
just curious, do you intend to develop a fuzzy full-text search function, retrieving list of node matches in descending order based on some distance measure?
http://linkurio.us/ utilizes such a search on top of Neo4j, using elasticsearch technology. There seem to be a elasticsearch package for R now. Maybe integrating that into RNeo4j would be worth considering.
Fuzzy search is quite a common exploration use case.
Thanks, Daniel

SSL certificate problem

Hi,
When I try to install per the README.md, I get the following error:

"Downloading github repo nicolewhite/RNeo4j@master
Error in function (type, msg, asError = TRUE) :
certificate problem: self signed certificate in certificate chain"

Could you review?

Thanks!
Jesse Madsen

interfacing mazerunner from r with RNeo4j

I've been playing with @kbastani mazerunner: very interesting stuff. On the other hand I am still very much using R for reporting / graph visualisation and generally to talk to the neo4j instance.

To be able to avoid to interact with neo4j browser entirely I would need to be able to submit to neo4j the get to mazerunner via REST. In Kenny's example below, I need to be able to send:

:GET /service/mazerunner/analysis/pagerank/KNOWS

As the above is not cypher I cannot use RNeo4j cypher. Is there a way in the package to send a REST GET like the above (and to which endpoint should it go?)

If there isn't a way in RNeo4j (and assuming that this usecase is not general enough to develop one), would you be so kind to point me in the right direction - endpoint :) to develop this with say httr?

odd "Error: Success: (200) OK" maybe json related?

First let me say: a very fine package! Thanks.
Second: I have been using it, in a learning mode, these last few days, and everything has worked great. I suspect the odd error I get now (see subject line) may be the result of my getting some package updates (maybe httr_1.1.0?) due to other work I am doing. sessionInfo() below...

The error:

   library(RNeo4j)
   gdb <- startGraph("http://localhost:7474/db/data/", username="neo4j", password="isb");
   Error: Success: (200) OK

This stackoverflow post reports a similar-seeming error, though in a quite different context
stackoverflow post

sessionInfo()
sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RNeo4j_1.6.2         jsonlite_0.9.19      httr_1.1.0           BiocInstaller_1.20.1

loaded via a namespace (and not attached):
[1] compiler_3.2.3 R6_2.1.2       tools_3.2.3    curl_0.9.5    

Many thanks!

Paul Shannon
Institute for Systems Biology

Escape characters

Currently the package does not offer any automated way to escape Neo4j special characters in strings. This is particularly an issue when trying to batch import large data frames containing several character variables.

Perhaps a function similar to dbEscapeStrings() in RMySQL would bring an effective way to deal with this (see here: https://cran.r-project.org/web/packages/RMySQL/RMySQL.pdf)?

Thanks

authorization tokens in neo4j 2.2

I'm trying to connect to a neo4j 2.2 server with a user name and password, and am getting the following error:

Error: 401 Unauthorized

{
  "errors" : [ {
    "message" : "No authorization token supplied.",
    "code" : "Neo.ClientError.Security.AuthorizationFailed"
  } ],
  "authentication" : "http://some.ip.address:7474/authentication"
}

I know my authorization token: how do I pass it to startGraph?

createRel requires graph to be named 'graph'

I'm pretty new to R and this library but since finding both I am a million times more productive at working things out about my graph compared to Python. So thank you for that!

Small issue. I initialise my graph like so:

neo4j = startGraph("http://localhost:7474/db/data/")

and add a couple of nodes:

java = createNode(neo4j, "Subject", name="Java")
programming_language = createNode(neo4j, "Subject", name="Programming Language")

then create a relationship:

createRel(java, "IS_A", programming_language, weight=1.0)

gives me:

Error in configure_result(result, attr(graph, "username"), attr(graph,  : 
  object 'graph' not found

Adding:

graph = startGraph("http://localhost:7474/db/data/")

then adding the relationship seems to work. Like I said not a big deal but would help with users like me that are new to the API:+1:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.