Skip to content
📦 High level wrapper around the redland package for common rdf applications
HTML R CSS Dockerfile TeX
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci test should error if we hit errors Mar 20, 2018
R update docs Nov 13, 2018
docs update docs for release Jan 16, 2019
inst 0.2.1 patch release Nov 25, 2018
man rebuild pkgdown with png logo for favicon Dec 24, 2018
pkgdown/favicon
slides move slides, streamline data-lake vignette Nov 2, 2018
tests Fix tests for readr 1.2.0 (#30) Nov 24, 2018
vignettes maybe a successful build of storage vignette this time? Nov 8, 2018
.Rbuildignore update build-ignore Jan 15, 2019
.gitignore update Nov 1, 2018
.travis.yml Update .travis.yml Jun 13, 2019
CONDUCT.md add code of conduct (devtools version) Jan 31, 2018
DESCRIPTION patch license Jan 14, 2019
LICENSE patch license Jan 14, 2019
NAMESPACE Storage vignette (#29) Oct 31, 2018
NEWS.md update docs for release Jan 16, 2019
README.Rmd add hex, update pkgdown Dec 23, 2018
README.md add hex, update pkgdown Dec 23, 2018
_pkgdown.yml add hex, update pkgdown Dec 23, 2018
appveyor.yml Update appveyor.yml Nov 13, 2018
codecov.yml badges! Aug 16, 2017
codemeta.json smaller file size Jan 15, 2019
cran-comments.md update build-ignore Jan 15, 2019
docker-compose.yml virtuoso working! Mar 20, 2018
paper.bib update description, add paper.md Dec 12, 2017
paper.md Work in progress: Feb 2, 2018
rdflib.Rproj add some basic tests, use non-conflicting function/method names, supp… Aug 17, 2017

README.md

rdflib

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Travis-CI Build Status Build status Coverage Status CircleCI CRAN_Status_Badge CRAN RStudio mirror downloads 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.

Installation

You can install rdflib from GitHub with:

# install.packages("devtools")
devtools::install_github("ropensci/rdflib")

Basic use

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

library(magrittr)
library(rdflib)

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: <http://purl.org/dc/elements/1.1/>
  SELECT ?a ?c
  WHERE { ?a dc:creator ?c . }'

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

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

x <- rdf()
x <- rdf_add(x, 
    subject="http://www.dajobe.org/",
    predicate="http://purl.org/dc/elements/1.1/language",
    object="en")
x
#> Total of 1 triples, stored in hashes
#> -------------------------------
#> <http://www.dajobe.org/> <http://purl.org/dc/elements/1.1/language> "en" .

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

options(rdf_print_format = "jsonld")
x
#> Total of 1 triples, stored in hashes
#> -------------------------------
#> {
#>   "@id": "http://www.dajobe.org/",
#>   "http://purl.org/dc/elements/1.1/language": "en"
#> }

JSON-LD

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")
#> Total of 1 triples, stored in hashes
#> -------------------------------
#> {
#>   "@id": "http://www.dajobe.org/",
#>   "http://purl.org/dc/elements/1.1/language": "en"
#> }

For more information on the JSON-LD RDF API, see https://json-ld.org/spec/latest/json-ld-rdf/.

Advanced Use

See articles from the documentation for advanced use including applications to large triplestores, example SPARQL queries, and information about additional database backends.


Citing rdflib

Please also cite the underlying redland library when citing rdflib

Carl Boettiger. (2018). rdflib: A high level wrapper around the redland package for common rdf applications (Version 0.1.0). Zenodo. https://doi.org/10.5281/zenodo.1098478

Jones M, Slaughter P, Ooms J, Boettiger C, Chamberlain S (2018). redland: RDF Library Bindings in R. doi: 10.5063/F1VM496B (URL: http://doi.org/10.5063/F1VM496B), R package version 1.0.17-10, <URL: https://github.com/ropensci/redland-bindings/tree/master/R/redland>.

rofooter

You can’t perform that action at this time.