| Title: | R Interface to the 'LadybugDB' Embedded Graph Database |
|---|---|
| Description: | Provides an R interface to 'LadybugDB', an embedded columnar graph database using the 'Cypher' query language. 'LadybugDB' was formerly known as 'Kuzu'. This package uses native 'Rcpp' bindings to the 'LadybugDB' C library, requiring no 'Python' runtime. |
| Authors: | Raden Muhammad Hadi [aut, cre] |
| Maintainer: | Raden Muhammad Hadi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.4 |
| Built: | 2026-10-16 18:30:38 UTC |
| Source: | https://github.com/cran/rladybugdb |
Convert a LadybugDB result to an Arrow Table
as_arrow_table(x, ...)as_arrow_table(x, ...)
x |
An |
... |
Unused. |
An arrow::Table containing all query rows and columns, backed by
LadybugDB's Arrow C Data export. The streaming cursor is preserved.
Extracts node and relationship columns from a LadybugDB query result and
constructs an igraph::graph_from_data_frame() object.
as_igraph(x, ...)as_igraph(x, ...)
x |
An |
... |
Unused; kept for S3 compatibility. |
Node columns must have LadybugDB type NODE and relationship columns type
REL/RELATIONSHIP. When the result contains no structural columns the
function aborts with an informative error.
A directed igraph object whose vertices and edges represent the
nodes and relationships in the query result. Database properties become
vertex and edge attributes; repeated internal identifiers are deduplicated.
if (requireNamespace("igraph", quietly = TRUE)) { with_lb_connection(":memory:", { lb_close(lb_execute( conn, "CREATE NODE TABLE Person (name STRING, PRIMARY KEY(name))" )) lb_close(lb_execute(conn, "CREATE REL TABLE Knows (FROM Person TO Person)")) lb_close(lb_execute( conn, "CREATE (:Person {name:'A'})-[:Knows]->(:Person {name:'B'})" )) result <- lb_execute( conn, "MATCH (a:Person)-[r:Knows]->(b:Person) RETURN a, r, b" ) graph <- as_igraph(result) lb_close(result) graph }, num_threads = 2) }if (requireNamespace("igraph", quietly = TRUE)) { with_lb_connection(":memory:", { lb_close(lb_execute( conn, "CREATE NODE TABLE Person (name STRING, PRIMARY KEY(name))" )) lb_close(lb_execute(conn, "CREATE REL TABLE Knows (FROM Person TO Person)")) lb_close(lb_execute( conn, "CREATE (:Person {name:'A'})-[:Knows]->(:Person {name:'B'})" )) result <- lb_execute( conn, "MATCH (a:Person)-[r:Knows]->(b:Person) RETURN a, r, b" ) graph <- as_igraph(result) lb_close(result) graph }, num_threads = 2) }
Convert an lb_result to a tbl_graph (tidygraph)
as_tbl_graph(x, ...)as_tbl_graph(x, ...)
x |
An |
... |
Unused. |
A tbl_graph object, inheriting from igraph, whose nodes and
edges represent the query's nodes and relationships, with their properties
available as attributes for tidygraph operations.
Convert a LadybugDB result to a tibble
as_tibble(x, ...)as_tibble(x, ...)
x |
An |
... |
Passed to |
A tibble (classes tbl_df, tbl, and data.frame) containing all
query rows, with one column per returned expression.
Materialization preserves the current streaming cursor, so it is repeatable
and does not change subsequent calls to lb_fetch().
## S3 method for class 'lb_result' as.data.frame(x, ...)## S3 method for class 'lb_result' as.data.frame(x, ...)
x |
An |
... |
Unused. |
A data.frame containing all query rows, with one column per
returned expression. Nested database values are stored in list columns.
Format a LadybugDB interval
## S3 method for class 'lb_interval' format(x, ...) ## S3 method for class 'lb_interval' print(x, ...)## S3 method for class 'lb_interval' format(x, ...) ## S3 method for class 'lb_interval' print(x, ...)
x |
An |
... |
Unused. |
format() returns a character string describing the interval's
months, days, and microseconds. print() displays that description and
returns the supplied lb_interval object invisibly.
interval <- structure( list(months = 1L, days = 2L, microseconds = 3000000), class = "lb_interval" ) format(interval) print(interval)interval <- structure( list(months = 1L, days = 2L, microseconds = 3000000), class = "lb_interval" ) format(interval) print(interval)
Create a LadybugDB DBI driver
Ladybug()Ladybug()
A LadybugDriver S4 object, inheriting from DBIDriver, for use with
DBI::dbConnect() to open a LadybugDB database.
LadybugDB DBI connection
databaseNative database object.
connectionNative connection object.
stateMutable connection state.
bigintINT64 conversion policy.
This function is deprecated. The C library is built from bundled source during package installation and no Python installation is required. This helper only issues a deprecation warning; it does not install any software.
ladybugdb_install(...)ladybugdb_install(...)
... |
Ignored. |
Invisible NULL, called for the side effect of issuing a
deprecation warning. No software is installed.
Returns TRUE if the native LadybugDB C library is loaded and functional.
ladybugdb_is_installed()ladybugdb_is_installed()
A logical scalar: TRUE if the native LadybugDB C library responds
to a version query, and FALSE if that query fails.
ladybugdb_is_installed()ladybugdb_is_installed()
Return the LadybugDB C library version string
ladybugdb_version()ladybugdb_version()
A character string identifying the bundled LadybugDB engine version,
e.g. "0.20.4".
ladybugdb_version()ladybugdb_version()
LadybugDB implements the standard DBI lifecycle, query, binding, fetch,
transaction, quoting, and table-metadata generics. LadybugDB's native schema
distinguishes node and relationship tables, so relational helpers outside
this documented subset are intentionally left to graph-specific Cypher and
the lb_* API. SQL SELECT, dbWriteTable(), and dbAppendTable() are not
translated. dbExecute() returns zero after successful DDL/DML because the
LadybugDB 0.20.4 C result summary does not expose a stable affected-row
count. Applicable driver behavior is exercised with a focused DBItest
subset.
The return value depends on the DBI method:
dbConnect() returns a LadybugConnection S4 object, inheriting from
DBIConnection, that owns an open database and native connection.
dbSendQuery() and dbSendStatement() return a LadybugResult S4 object,
inheriting from DBIResult, representing an executed statement or a
parameterized statement awaiting dbBind().
dbBind() returns the supplied LadybugResult invisibly after executing
the statement with the supplied parameters and resetting its fetch cursor.
dbFetch() and dbGetQuery() return a data.frame with one column per
returned expression and one row per query record. dbFetch() advances the
cursor; dbGetQuery() fetches all rows and clears its result.
dbExecute() and dbGetRowsAffected() return the numeric scalar 0.
The engine does not expose an affected-row count, so this value does not
indicate how many rows were changed.
dbGetRowCount() returns a numeric scalar counting rows fetched since
the result was created or most recently bound.
dbColumnInfo() returns a data.frame with character columns name and
type, giving each result column's name and LadybugDB type.
dbGetInfo() returns a named list. For a driver, driver.version and
client.version are character strings identifying the package and engine
versions. For a connection, dbname, bigint, and serverVersion are
character strings describing its path, integer conversion policy, and
engine version; read.only and valid are logical scalars. For a result,
statement is the Cypher string, row.count is the numeric fetched-row
count, and completed is a logical scalar. An unbound result also has
pending = TRUE; an executed, valid result also includes the metadata
described by lb_result_info().
dbIsValid(), dbHasCompleted(), and dbIsReadOnly() return a logical
scalar indicating whether the object is usable, fetching is complete, or
the database was opened read-only, respectively. Drivers are always valid.
dbExistsTable() returns a logical vector indicating whether each
supplied table name exists.
dbListTables() and dbListFields() return character vectors of table
names and field names, respectively; an empty vector means none were found.
dbDataType() returns a character string naming the LadybugDB type for
an R vector, or a named character vector of types for data-frame columns.
dbQuoteIdentifier() and dbQuoteString() return DBI::SQL objects
containing quoted identifiers or string literals, with the same length
as the input character vector.
dbDisconnect(), dbClearResult(), dbBegin(), dbCommit(),
dbRollback(), and dbUnloadDriver() return the logical scalar TRUE
after successfully releasing resources or completing transaction control.
show() returns invisible NULL, called for the side effect of
displaying a summary of the driver, connection, or result.
LadybugDB DBI result
connectionOwning DBI connection.
stateMutable result state.
statementOriginal Cypher statement.
Transaction control
lb_begin(conn) lb_commit(conn) lb_rollback(conn)lb_begin(conn) lb_commit(conn) lb_rollback(conn)
conn |
An |
The supplied lb_connection object invisibly, after starting,
committing, or rolling back its transaction, respectively.
Closing an object more than once is harmless. A connection cannot be closed while it owns open results, and a database cannot be closed while it owns open connections.
lb_close(x, ...)lb_close(x, ...)
x |
An |
... |
Unused. |
Invisible NULL, called for the side effect of releasing the
object's native resources.
Open a connection to a LadybugDB database
lb_connection(database, num_threads = NULL)lb_connection(database, num_threads = NULL)
database |
An |
num_threads |
Positive integer execution thread limit, or |
An lb_connection list containing a native connection pointer and
its owning database. Use it to execute queries, and release it with
lb_close() after its results are closed.
Registers a temporary Arrow-backed table through the Arrow C Data Interface, copies its rows into an existing native node table, and unregisters it. No data-frame or CSV conversion is performed.
lb_copy_from_arrow(conn, value, table)lb_copy_from_arrow(conn, value, table)
conn |
An |
value |
An Arrow Table, RecordBatch, or object accepted by
|
table |
Existing target node table name. |
An lb_result containing the COPY statement's metadata after
loading the Arrow rows into the target table. Release it with lb_close().
Load a CSV file into a LadybugDB table
lb_copy_from_csv(conn, path, table, header = TRUE, delim = ",", ...)lb_copy_from_csv(conn, path, table, header = TRUE, delim = ",", ...)
conn |
An |
path |
Path to a CSV file. |
table |
Existing target table name. |
header |
Does the file contain a header? |
delim |
One-character delimiter. |
... |
Named COPY options. Values must be scalar logical, numeric, or character values; option names are validated identifiers. |
An lb_result containing the COPY statement's metadata after
loading the CSV rows into the target table. Release it with lb_close().
Uses native Arrow transport when the optional arrow package is available.
Otherwise it uses the explicit CSV loader as a compatibility fallback.
lb_copy_from_df(conn, df, table)lb_copy_from_df(conn, df, table)
conn |
An |
df |
A data frame. |
table |
Existing target table name. |
An lb_result containing the COPY statement's metadata after
loading the data-frame rows into the target table. Release it with
lb_close().
Creates or opens a LadybugDB database. LadybugDB v0.20.4 can read the storage formats created by v0.15.x. For incompatible future formats, export with the original engine and import into a fresh database.
lb_database(path = ":memory:", read_only = FALSE, config = list())lb_database(path = ":memory:", read_only = FALSE, config = list())
path |
File-system path, or |
read_only |
Open in read-only mode? |
config |
Named list of LadybugDB system configuration overrides. Valid
names are |
An lb_database list containing a native database pointer, its path,
read-only flag, and configuration. It represents an open database that
should be released with lb_close() after its connections are closed.
Sends a Cypher query string to LadybugDB and returns an lb_result object.
For DDL or DML statements (CREATE TABLE, CREATE, MERGE, …) the result
contains metadata; for MATCH/RETURN it contains rows.
lb_execute(conn, query, parameters = NULL)lb_execute(conn, query, parameters = NULL)
conn |
An |
query |
A single character string containing a Cypher query. |
parameters |
A named list of query parameters for parameterised queries.
|
An lb_result list containing a native result pointer, its owning
connection, query text, column names and types, and row count. It represents
query rows or statement metadata and must be released with lb_close().
with_lb_connection(":memory:", { lb_close(lb_execute( conn, "CREATE NODE TABLE Person (name STRING, PRIMARY KEY(name))" )) result <- lb_execute(conn, "CREATE (:Person {name: $name})", parameters = list(name = "Alice")) print(result) lb_close(result) }, num_threads = 2)with_lb_connection(":memory:", { lb_close(lb_execute( conn, "CREATE NODE TABLE Person (name STRING, PRIMARY KEY(name))" )) result <- lb_execute(conn, "CREATE (:Person {name: $name})", parameters = list(name = "Alice")) print(result) lb_close(result) }, num_threads = 2)
Fetch rows from a LadybugDB result
lb_fetch(result, n = 10000) lb_has_next(result) lb_reset(result)lb_fetch(result, n = 10000) lb_has_next(result) lb_reset(result)
result |
An |
n |
Maximum rows to fetch. |
lb_fetch() returns a data.frame with up to n rows from the
current cursor position and one column per returned expression. Repeated
calls advance the cursor. lb_has_next() returns a logical scalar that is
TRUE when unfetched rows remain. lb_reset() returns the supplied
lb_result invisibly after moving its cursor back to the first row.
Fetch a chunk as an Arrow Table
lb_fetch_arrow(result, n = Inf)lb_fetch_arrow(result, n = Inf)
result |
An |
n |
Maximum rows to fetch. |
An arrow::Table containing up to n rows from the current cursor
position. The cursor advances by the number of rows returned.
These are thin wrappers around LadybugDB's extension Cypher commands.
Remote installation and updating are unavailable in the CRAN build because
those operations require a native networking stack. Compatible extensions
installed outside R can still be loaded with lb_load_extension().
lb_list_extensions(conn) lb_install_extension(conn, name) lb_load_extension(conn, name) lb_update_extension(conn, name)lb_list_extensions(conn) lb_install_extension(conn, name) lb_load_extension(conn, name) lb_update_extension(conn, name)
conn |
An |
name |
Official extension name. |
lb_list_extensions() returns a data.frame describing the
official extensions reported by the engine, with one row per extension.
lb_load_extension() returns an lb_result containing the LOAD
statement's metadata; release it with lb_close().
lb_install_extension() and lb_update_extension() always raise an error
of class rladybugdb_error_unsupported and return no value, because remote
installation and updates are unavailable in the CRAN build.
Retrieve the next result from a multi-statement query
lb_next_result(result)lb_next_result(result)
result |
An |
An lb_result representing the next statement's rows or metadata,
or NULL if no further result is available. Close each returned result
with lb_close().
Convenience wrapper around lb_execute() that immediately converts the
result to an R data.frame. Equivalent to
as.data.frame(lb_execute(conn, query, ...)).
lb_query(conn, query, parameters = NULL, ...)lb_query(conn, query, parameters = NULL, ...)
conn |
An |
query |
A single character string containing a Cypher query. |
parameters |
A named list of query parameters for parameterised queries.
|
... |
Passed to |
A data.frame containing all query rows, with one column per
returned expression. The underlying native result is closed automatically.
with_lb_connection(":memory:", { lb_close(lb_execute( conn, "CREATE NODE TABLE Person (name STRING, age INT64, PRIMARY KEY(name))" )) lb_close(lb_execute(conn, "CREATE (:Person {name: 'Alice', age: 30})")) lb_query(conn, "MATCH (p:Person) RETURN p.name AS name, p.age AS age") }, num_threads = 2)with_lb_connection(":memory:", { lb_close(lb_execute( conn, "CREATE NODE TABLE Person (name STRING, age INT64, PRIMARY KEY(name))" )) lb_close(lb_execute(conn, "CREATE (:Person {name: 'Alice', age: 30})")) lb_query(conn, "MATCH (p:Person) RETURN p.name AS name, p.age AS age") }, num_threads = 2)
Return query timing information
lb_query_summary(result)lb_query_summary(result)
result |
An |
A named list with numeric scalars compiling_time_ms and
execution_time_ms, measuring the query's compilation and execution times
in milliseconds.
Inspect result metadata
lb_result_info(result)lb_result_info(result)
result |
An |
A named list with character vectors column_names and
column_types; numeric scalars num_columns, num_tuples (total rows),
and rows_fetched (current cursor position); and logical scalars
complete (no unfetched rows remain) and has_next_result (another
statement's result is available).
Configure and interrupt queries
lb_set_timeout(conn, milliseconds) lb_interrupt(conn)lb_set_timeout(conn, milliseconds) lb_interrupt(conn)
conn |
An |
milliseconds |
Non-negative timeout in milliseconds. Zero disables the timeout. |
The supplied lb_connection object invisibly. lb_set_timeout()
changes its query timeout; lb_interrupt() requests interruption of its
running query.
Run code with an automatically closed LadybugDB connection
with_lb_connection(path = ":memory:", code, ..., num_threads = NULL)with_lb_connection(path = ":memory:", code, ..., num_threads = NULL)
path |
Database path. |
code |
Code evaluated with |
... |
Passed to |
num_threads |
Passed to |
The value produced by code, with its class and visibility
preserved. The connection and database are closed before returning.