Learn R Programming

dataset (version 0.4.1)

dataset_to_triples: Dataset to triples (three columns or N-Triples)

Description

Converts a dataset to RDF-style triples with subject, predicate, and object columns. Supports semantic expansion via variable metadata.

Usage

dataset_to_triples(x, idcol = NULL, expand_uri = TRUE, format = "data.frame")

Value

Either a data.frame with columns s, p, and o, or a character vector of N-Triple lines.

Arguments

x

A dataset_df or data.frame.

idcol

Name or index of the subject column. If NULL, defaults to "rowid" or rownames.

expand_uri

Logical; if TRUE, expands URIs using namespaces and definitions.

format

Output format: "data.frame" (default) or "nt" for N-Triples.

Details

For publishing examples, a minimal serverless scaffold is provided at https://github.com/dataobservatory-eu/dataset-template, which shows how to host CSV + RDF serialisations on GitHub Pages without any server setup.

Examples

Run this code
# A minimal example with just rowid and geo
data("gdp", package = "dataset")
small_geo <- dataset_df(
  geo = defined(
    gdp$geo[1:3],
    label = "Geopolitical entity",
    concept = "http://example.com/prop/geo",
    namespace = "https://dd.eionet.europa.eu/vocabulary/eurostat/geo/$1"
  )
)

# View as triple table
dataset_to_triples(small_geo)

# View as N-Triples
dataset_to_triples(small_geo, format = "nt")

Run the code above in your browser using DataLab