knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) skip_vignette <- !reticulate::py_module_available("kuzu")
Welcome to kuzuR! This guide will walk you through the basic steps to get started with kuzuR, from installation to running your first query.
First, ensure you have the kuzuR package installed from GitHub. You will also need reticulate to manage the Python environment.
Development Version
remotes::install_github("WickM/kuzuR")
Cran Version
install.packages("kuzuR")
The first step is to create a connection to a Kuzu database. You can create an in-memory database or connect to a database on disk.
library(kuzuR) # Create an in-memory database connection con <- kuzu_connection(":memory:")
Next, define your graph schema using Cypher queries. Let's create a simple schema with Person nodes and Knows relationships.
kuzu_execute(con, paste("CREATE NODE TABLE Person(name STRING, age INT64,", "PRIMARY KEY (name))")) kuzu_execute(con, "CREATE REL TABLE Knows(FROM Person TO Person, since INT64)")
You can load data from R data frames directly into your Kuzu database.
# Create a data frame of persons persons_df <- data.frame( name = c("Alice", "Bob", "Carol"), age = c(35, 45, 25) ) # Create a data frame of relationships knows_df <- data.frame( from_person = c("Alice", "Bob"), to_person = c("Bob", "Carol"), since = c(2010, 2015) ) # Load data into Kuzu kuzu_copy_from_df(con, persons_df, "Person") kuzu_copy_from_df(con, knows_df, "Knows")
Finally, you can query your graph using Cypher and retrieve the results as an R data frame.
# Execute a query result <- kuzu_execute(con, paste("MATCH (a:Person)-[k:Knows]->(b:Person)", "RETURN a.name, b.name, k.since")) # Convert the result to a data frame df <- as.data.frame(result) print(df)
This concludes the "Getting Started" guide. For more advanced topics, please see the other articles and the function reference.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.