Travis-CI Build Status AppVeyor Build Status Coverage Status CRAN_Status_Badge DOI


A friendly and consise user interface for performing common tasks on rdf data, such as parsing and converting between formats including rdfxml, turtle, nquads, ntriples, and trig, creating rdf graphs, and performing SPARQL queries. This package wraps the redland R package which provides direct bindings to the redland C library. Additionally, the package supports parsing and serialization of rdf into json-ld through the json-ld package, which binds the official json-ld javascript API. The package interface takes inspiration from the Python rdflib library.


You can install rdflib from GitHub with:

# install.packages("devtools")

Basic use

While not required, rdflib is designed to play nicely with %>% pipes, so we will load the magrittr package as well:


Parse a file and serialize into a different format:

system.file("extdata/dc.rdf", package="redland") %>%
  rdf_parse() %>%
  rdf_serialize("test.nquads", "nquads")

Perform SPARQL queries:

sparql <-
 'PREFIX dc: <>
  SELECT ?a ?c
  WHERE { ?a dc:creator ?c . }'

system.file("extdata/dc.rdf", package="redland") %>%
rdf_parse() %>%
#> # A tibble: 1 x 2
#>   a                      c           
#>   <chr>                  <chr>       
#> 1 Dave Beckett

Initialize graph a new object or add triples statements to an existing graph:

x <- rdf()
x <- rdf_add(x, 
#> <> <> "en" .

Change the default display format (nquads) for graph objects:

options(rdf_print_format = "jsonld")
#> {
#>   "@id": "",
#>   "": "en"
#> }


We can also work with the JSON-LD format through additional functions provided in the R package, jsonld.

out <- tempfile()
rdf_serialize(x, out, "jsonld")
rdf_parse(out, format = "jsonld")
#> {
#>   "@id": "",
#>   "": "en"
#> }

For more information on the JSON-LD RDF API, see

Citing rdflib

Please also cite the underlying redland library when citing rdflib

Boettiger C (2018). rdflib: A high level wrapper around the redland package for common rdf applications. <URL:>.

Jones M, Slaughter P, Ooms J, Boettiger C and Chamberlain S (2016). redland: RDF Library Bindings in R. doi: 10.5063/F1VM496B (URL:, R package version 1.0.17-9, <URL:>.