| Title: | 'RDF' and 'SPARQL' for R using 'Oxigraph' |
|---|---|
| Description: | Provides 'RDF' storage and 'SPARQL' 1.1 query capabilities by wrapping the 'Oxigraph' graph database library <https://github.com/oxigraph/oxigraph>. Supports in-memory and persistent ('RocksDB') storage, multiple 'RDF' serialization formats ('Turtle', 'N-Triples', 'RDF-XML', 'N-Quads', 'TriG'), and full 'SPARQL' 1.1 Query and Update support. Built using the 'extendr' framework for 'Rust'-R bindings. |
| Authors: | Carl Boettiger [aut, cre] (ORCID: <https://orcid.org/0000-0002-1642-628X>), Oxigraph Contributors [cph] (Oxigraph Rust library), Authors of the dependency Rust crates [aut] (see inst/AUTHORS file) |
| Maintainer: | Carl Boettiger <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-06-03 11:47:31 UTC |
| Source: | https://github.com/cboettig/roxigraph |
Adds a single triple to the store.
rdf_add(store, subject, predicate, object, graph = NULL)rdf_add(store, subject, predicate, object, graph = NULL)
store |
An RDF store handle |
subject |
Subject IRI (e.g., |
predicate |
Predicate IRI (e.g., |
object |
Object: IRI, blank node, or literal (e.g., '"value"') |
graph |
Optional named graph IRI |
Invisibly returns NULL
store <- rdf_store() rdf_add(store, "<http://example.org/s>", "<http://example.org/p>", '"hello"') rdf_size(store)store <- rdf_store() rdf_add(store, "<http://example.org/s>", "<http://example.org/p>", '"hello"') rdf_size(store)
Loads RDF data into the store from a string.
rdf_load(store, data, format = "turtle", base_iri = NULL)rdf_load(store, data, format = "turtle", base_iri = NULL)
store |
An RDF store handle |
data |
RDF data as a character string |
format |
RDF format: "turtle", "ntriples", "rdfxml", "nquads", or "trig" |
base_iri |
Optional base IRI for resolving relative URIs |
Invisibly returns NULL
store <- rdf_store() rdf_load(store, '<http://example.org/s> <http://example.org/p> "value" .', format = "ntriples")store <- rdf_store() rdf_load(store, '<http://example.org/s> <http://example.org/p> "value" .', format = "ntriples")
Loads RDF data into the store from a file.
rdf_load_file(store, file, format = NULL, base_iri = NULL)rdf_load_file(store, file, format = NULL, base_iri = NULL)
store |
An RDF store handle |
file |
Path to the RDF file |
format |
RDF format. If NULL, guessed from file extension. |
base_iri |
Optional base IRI for resolving relative URIs |
Invisibly returns NULL
store <- rdf_store() # Create a temporary RDF file tmp <- tempfile(fileext = ".nt") writeLines('<http://example.org/s> <http://example.org/p> "value" .', tmp) rdf_load_file(store, tmp) rdf_size(store)store <- rdf_store() # Create a temporary RDF file tmp <- tempfile(fileext = ".nt") writeLines('<http://example.org/s> <http://example.org/p> "value" .', tmp) rdf_load_file(store, tmp) rdf_size(store)
Removes a single triple from the store.
rdf_remove(store, subject, predicate, object, graph = NULL)rdf_remove(store, subject, predicate, object, graph = NULL)
store |
An RDF store handle |
subject |
Subject IRI or blank node |
predicate |
Predicate IRI |
object |
Object: IRI, blank node, or literal |
graph |
Optional named graph IRI |
Invisibly returns NULL
store <- rdf_store() rdf_add(store, "<http://example.org/s>", "<http://example.org/p>", '"hello"') rdf_remove(store, "<http://example.org/s>", "<http://example.org/p>", '"hello"') rdf_size(store)store <- rdf_store() rdf_add(store, "<http://example.org/s>", "<http://example.org/p>", '"hello"') rdf_remove(store, "<http://example.org/s>", "<http://example.org/p>", '"hello"') rdf_size(store)
Serializes the store contents to a string.
rdf_serialize(store, format = "turtle")rdf_serialize(store, format = "turtle")
store |
An RDF store handle |
format |
RDF format: "turtle", "ntriples", "rdfxml", "nquads", or "trig" |
The serialized RDF data as a character string
store <- rdf_store() rdf_load(store, '<http://example.org/s> <http://example.org/p> "value" .', format = "ntriples") rdf_serialize(store, format = "turtle")store <- rdf_store() rdf_load(store, '<http://example.org/s> <http://example.org/p> "value" .', format = "ntriples") rdf_serialize(store, format = "turtle")
Returns the number of quads (triples) in the store.
rdf_size(store)rdf_size(store)
store |
An RDF store handle |
The number of quads as an integer
store <- rdf_store() rdf_size(store)store <- rdf_store() rdf_size(store)
Creates a new RDF store, either in-memory or backed by persistent storage.
rdf_store(path = NULL)rdf_store(path = NULL)
path |
Optional path for persistent storage. If NULL (default), creates an in-memory store. |
An RDF store handle (integer)
# In-memory store store <- rdf_store() # Persistent store (not supported on Windows) if (.Platform$OS.type != "windows") { store <- rdf_store(file.path(tempdir(), "my_store")) }# In-memory store store <- rdf_store() # Persistent store (not supported on Windows) if (.Platform$OS.type != "windows") { store <- rdf_store(file.path(tempdir(), "my_store")) }
Executes a SPARQL query against the RDF store.
sparql_query(store, query)sparql_query(store, query)
store |
An RDF store handle |
query |
A SPARQL query string |
For SELECT queries, a data.frame with results. For ASK queries, a logical. For CONSTRUCT/DESCRIBE queries, a data.frame with subject, predicate, object columns.
store <- rdf_store() rdf_load(store, '<http://example.org/s> <http://example.org/p> "hello" .', format = "ntriples") sparql_query(store, "SELECT * WHERE { ?s ?p ?o }")store <- rdf_store() rdf_load(store, '<http://example.org/s> <http://example.org/p> "hello" .', format = "ntriples") sparql_query(store, "SELECT * WHERE { ?s ?p ?o }")
Executes a SPARQL UPDATE query to modify the store.
sparql_update(store, update)sparql_update(store, update)
store |
An RDF store handle |
update |
A SPARQL UPDATE query string |
Invisibly returns NULL
store <- rdf_store() sparql_update(store, "INSERT DATA { <http://example.org/s> <http://example.org/p> 'value' }")store <- rdf_store() sparql_update(store, "INSERT DATA { <http://example.org/s> <http://example.org/p> 'value' }")