Skip to contents

The R package redland provides methods to create, query and write information stored in the Resource Description Framework (RDF). This package is implemented as R scripts that provide an R interface (aka "wrapper") to the Redland RDF C libraries. Documentation for the redland R package classes and functions are available from the standard R help facility, for example, 'help("Node-class")', '?getNodeType', etc.

An overview of the redland R package is available with the R command: 'vignette("redland_overview")'.

The Redland C library functions are described at https://librdf.org/docs/api/index.html.

An introduction to RDF can be found at https://www.w3.org/TR/rdf-primer/.

Details

The redland R package classes and the corresponding Redland C library types are shown in the following table:

ConceptRedland C typeredland R classPurpose
Resource / Literallibrdf_nodeNodeRDF Model & Syntax nodes
Statement / Triplelibrdf_statementStatementRDF Model & Syntax arcs (statements, triples)
Modellibrdf_modelModelSet of Statements usually held in one Storage.
Nodelibrdf_nodeNodeThe subject, predicate or object of a Statement
Storagelibrdf_storageStorageStorage for Models either persistent or in-memory.
Parserlibrdf_parserParserSyntax parsers delivering Stream of Statements or writing to a Model
Querylibrdf_queryQueryQuerying of an Model delivering a QueryResults
QueryResultslibrdf_query_resultsQueryResultsResults of applying an Query to a Model giving either variable bindings with Node values or Stream of Statements
Serializerlibrdf_serializerSerializerSerializes a Model into a syntax such as RDF/XML
Worldlibrdf_worldWorldRDF wrapper class handling Redland startup/shutdown

Note

In order to communicate with the Redland RDF C libraries, the redland R package uses an interface layer that is created with the software package Simplified Wrapper and Interface Generator (SWIG). The relationship between the redland R package and the Redland C libraries is:

User script -> redland R package -> SWIG R interface -> Redland C libraries -> RDF data

It is recommended that the redland package R classes be used to interact with RDF, as these higher level classes take care of many of the the details of communicating with the Redland C libraries. However, all of the lower level R interface functions generated by SWIG are made available by the redland package. These interface functions usually have names beginning with 'librdf_', 'rasqal_' or 'raptor_' and are usually the same name as the underlying C library function. Documentation for the R SWIG interface functions can be found via R help i.e. '?librdf_iterator'.

Author

Matthew B. Jones (NCEAS) and Peter Slaughter (NCEAS)

Examples

# This example creates the necessary R objects to hold an RDF model and reads 
# in a file that contains RDF/XML statements. This model is then queried for 
# and the query results inspected.
world <- new("World")
storage <- new("Storage", world, "hashes", name="", options="hash-type='memory'")
model <- new("Model", world, storage, options="")
filePath <- system.file("extdata/example.rdf", package="redland")
parser <- new("Parser", world)
parseFileIntoModel(parser, world, filePath, model)
queryString <- paste("PREFIX dc: <http://purl.org/dc/elements/1.1/> ",
                     "SELECT ?a ?c WHERE { ?a dc:description ?c . }", sep="")
query <- new("Query", world, queryString, base_uri=NULL, 
             query_language="sparql", query_uri=NULL)
results <- getResults(query, model, "rdfxml")

# When the query object is no longer needed, the resources it had allocated can be freed.
freeQuery(query)
#> NULL
rm(query)