The popular graph database Neo4j
can be used within R
thanks to the package/driver RNeo4j
(https://github.com/nicolewhite/Rneo4j).
The package author, @NicoleWhite, provides several great examples of its usage on GitHub.
Unfortunately for me, the examples given by @NicoleWhite and the documentation are a bit oversimplistic, in that they manually create each graph node and its associated labels
and properties
, such as:
mugshots = createNode(graph, "Bar", name = "Mugshots", location = "Downtown")
parlor = createNode(graph, "Bar", name = "The Parlor", location = "Hyde Park")
nicole = createNode(graph, name = "Nicole", status = "Student")
addLabel(nicole, "Person")
That's all good and fine when you're dealing with a tiny example dataset, but this approach isn't feasible for something like a large social graph with thousands of users, where each user is a node (such graphs might not utilize every node in every query, but they still need to be input to Neo4j
).
I'm trying to figure out how to do this using vectors or dataframes. Is there a solution, perhaps invoving an apply
statement or for
loop?
This basic attempt:
for (i in 1:length(df$user_id)){
paste(df$user_id[i]) = createNode(graph, "user", name = df$name[i], email = df$email[i])
}
Leads to Error: 400 Bad Request