Skip to content
This repository was archived by the owner on May 23, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Version: 1.0
Date: 2014-05-02
Author: Nicole White
License: GPL-3
Imports: RCurl, RJSONIO
Imports: RCurl, RJSONIO, igraph, pryr
Maintainer: <nicole@neotechnology.com>
Description: Easily interact with a Neo4j graph database from your R environment.
URL: nicolewhite.github.io/RNeo4j
10 changes: 9 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ S3method(getUniqueNode,graph)
S3method(importSample,default)
S3method(importSample,graph)
S3method(incomingRels,default)
S3method(ingest,default)
S3method(ingest,igraph)
S3method(incomingRels,node)
S3method(newTransaction,default)
S3method(newTransaction,graph)
Expand Down Expand Up @@ -121,6 +123,7 @@ export(getType)
export(getUniqueNode)
export(importSample)
export(incomingRels)
export(ingest)
export(newTransaction)
export(nodes)
export(outgoingRels)
Expand All @@ -135,4 +138,9 @@ importFrom(RCurl,curlPerform)
importFrom(RCurl,basicTextGatherer)
importFrom(RCurl,basicHeaderGatherer)
importFrom(RJSONIO,toJSON)
importFrom(RJSONIO,fromJSON)
importFrom(RJSONIO,fromJSON)
importFrom(igraph,vertex.attributes)
importFrom(igraph,edge.attributes)
importFrom(igraph,get.edgelist)
importFrom(igraph,is.directed)
importFrom(pryr,do_call)
46 changes: 46 additions & 0 deletions R/ingest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

ingest <- function(network, ...) UseMethod("ingest", network)

ingest.default = function(x, ...) {
stop("Invalid object. Must supply network type object.")
}


ingest.igraph = function(network, how, domain = NULL) {
# Add some domain info if nothing was passed.
if (is.null(domain)) domain <- deparse(substitute(network))

# Capture the node attributes in a data frame.
nodes <- as.data.frame(vertex.attributes(network))
nodes$domain <- domain

# Add all of the nodes to the database.
name <- list()
for (i in 1:nrow(nodes)) {
name[[i]] <- do_call(createNode, quote(graph), as.list(nodes[i, ]))
}

# Capture all of the imformation about edges, both incident vertices and attributes.
edges <- as.data.frame(get.edgelist(network))
edges <- cbind(edges, as.data.frame(edge.attributes(network)), domain = domain)

# Capture the name given to a node.
n <- sapply(name, `[[`, 'name')

# Add the edges to the database.
for (i in 1:nrow(edges)) {
# Find the incedent nodes from the list of nodes.
from <- name[which(edges$V1[i] == n)][[1]]
to <- name[which(edges$V2[i] == n)][[1]]

do_call(createRel, quote(from), how, quote(to), as.list(edges[i, -c(1, 2)]))
# If the network is undirected add the reverse edge.
if (!is.directed(karate)) {
do_call(createRel, quote(to), how, quote(from), as.list(edges[i, -c(1, 2)]))
}
}
return(invisible(NULL))
}



26 changes: 26 additions & 0 deletions man/ingest.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
\name{ingest}
\alias{ingest}
\title{Add igraph objects to Neo4j}
\description{
Take and igraph object from the igraph package and add it allong with any
node or edge attributes to the Neo4j.
}
\usage{
ingest(karate, 'knows')
}
\arguments{
\item{network}{An igraph object.}
\item{how}{What type of relationship should be created.}
\item{domain}{A string that either denotes the dataset name or a way to label the subgraph.}
}

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

require("igraph")
require("igraphdata")

data(karate)
ingest(karate, 'knows')
}