
Load Data from a Data Frame or Tibble into a Ladybug Table
Source:R/lb_load_data.R
lb_copy_from_df.RdEfficiently copies data from an R data.frame or tibble into a specified
table in the Ladybug database.
Details
When loading into a relationship table, Ladybug assumes the first two columns in the file are: FROM Node Column: The primary key of the FROM nodes. TO Node Column: The primary key of the TO nodes.
Examples
if (FALSE) { # \dontrun{
conn <- lb_connection(":memory:")
lb_execute(conn, "CREATE NODE TABLE User(name STRING, age INT64,
PRIMARY KEY (name))")
lb_execute(conn, "CREATE REL TABLE Knows(FROM User TO User)")
# Load from a data.frame
users_df <- data.frame(name = c("Carol", "Dan"), age = c(35, 40))
lb_copy_from_df(conn, users_df, "User")
# Load from a tibble (requires pre-existing nodes)
lb_execute(conn, "CREATE (u:User {name: 'Alice'}), (v:User {name: 'Bob'})")
knows_df <- data.frame(from_person = c("Alice", "Bob"),
to_person = c("Bob", "Carol"))
lb_copy_from_df(conn, knows_df, "Knows")
result <- lb_execute(conn, "MATCH (a:User) RETURN a.name, a.age")
print(as.data.frame(result))
result_rel <- lb_execute(conn, "MATCH (a:User)-[k:Knows]->(b:User)
RETURN a.name, b.name")
print(as.data.frame(result_rel))
} # }