sparqlchunks

Allows to run SPARQL chunks in R-markdown files. Also privides inline functions to send a SPARQL query to an endpoint and retrieve data in dataframe or list form.

https://github.com/aourednik/sparqlchunks

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.6%) to scientific vocabulary

Keywords

rstats rstats-package sparql
Last synced: 10 months ago · JSON representation

Repository

Allows to run SPARQL chunks in R-markdown files. Also privides inline functions to send a SPARQL query to an endpoint and retrieve data in dataframe or list form.

Basic Info
Statistics
  • Stars: 7
  • Watchers: 1
  • Forks: 1
  • Open Issues: 2
  • Releases: 0
Topics
rstats rstats-package sparql
Created about 4 years ago · Last pushed 12 months ago
Metadata Files
Readme Changelog Contributing License Codemeta

README.md

SPARQLchunks

Lifecycle: stable Codecov test coverage R-CMD-check <!-- badges: end -->

Coding in R is useless without interesting research questions; and even the best questions remain unanswered without data. RStudio provides a number of convenient ways to access data, among which the possibility to write SQL code chunks in Rmarkdown, to run these chunks and to assign the value of the query result directly to a variable of your choice. No such thing is available yet for SPARQL queries: the ones that allow you to navigate gigantic knowledge graphs that incarnate the conscience of the semantic web. This is where the SPARQLchunks package steps in.

This package allows you to query SPARQL endpoints in two different ways:

  1. It allows you to run SPARQL chunks in Rmarkdown files.
  2. It provides inline functions to send SPARQL queries to a user-defined endpoint and retrieve data in dataframe form (sparql2df) or list form (sparql2list).

Endpoints can be reached from behind corporate firewalls on Windows machines thanks to automatic proxy detection. See Execute SPARQL chunks in R Markdown.

Installation

Most users can install by running this command

r remotes::install_github("aourednik/SPARQLchunks", build_vignettes = TRUE)

If you are behind a corporate firewall on a Windows machine, direct access to GitHub might be blocked. If that is your case, run this installation code instead:

r proxy_url <- curl::ie_get_proxy_for_url("https://github.com") httr::set_config(httr::use_proxy(proxy_url)) remotes::install_url("https://github.com/aourednik/SPARQLchunks/archive/refs/heads/main.zip", build_vignettes = TRUE)

Use

To use the full potential of the package you need to load the library and tell knitr that a SPARQL engine exists:

{r setup, include=FALSE} library(SPARQLchunks) knitr::knit_engines$set(sparql = SPARQLchunks::eng_sparql)

Once you have done so, you can run SPARQL chunks:

Chunks

Retrieve a data frame

output.var: the name of the data frame you want to store the results in

endpoint: the URL of the SPARQL endpoint

autoproxy: whether or not try to use the automatic proxy detection

auth: authentication information for the sparql endpoint (as an httr authentication object, optional)

Example 1 (Swiss administration endpoint)

markdown ```{sparql output.var="queryres_df", endpoint="https://lindas.admin.ch/query"} PREFIX schema: <http://schema.org/> SELECT * WHERE { ?sub a schema:DataCatalog . ?subtype a schema:DataType . } ```

Example 2 (Uniprot endpoint)

Note the use of attempt at automatic proxy detection.

markdown ```{sparql output.var="tes5", endpoint="https://sparql.uniprot.org/sparql", autoproxy=TRUE} PREFIX up: <http://purl.uniprot.org/core/> SELECT ?taxon FROM <http://sparql.uniprot.org/taxonomy> WHERE { ?taxon a up:Taxon . } LIMIT 500 ```

Example 3 (WikiData endpoint):

markdown ```{sparql output.var="res.df", endpoint="https://query.wikidata.org/sparql"} SELECT DISTINCT ?item ?itemLabel ?country ?countryLabel ?linkTo ?linkToLabel WHERE { ?item wdt:P1142 ?linkTo . ?linkTo wdt:P31 wd:Q12909644 . VALUES ?type { wd:Q7278 wd:Q24649 } ?item wdt:P31 ?type . ?item wdt:P17 ?country . MINUS { ?item wdt:P576 ?abolitionDate } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . } } ```

Retrieve a list

output.var: the name of the list you want to store the results in

endpoint: the URL of the SPARQL endpoint

output.type : when set to "list", retrieves a list (tree structure) instead of a data-frame

autoproxy: whether or not try to use the automatic proxy detection

markdown ```{sparql output.var="queryres_list", endpoint="https://lindas.admin.ch/query", output.type="list"} PREFIX schema: <http://schema.org/> SELECT * WHERE { ?sub a schema:DataCatalog . ?subtype a schema:DataType . } ```

Inline code

The inline functions sparql2df and sparql2list both have the same pair of arguments: a SPARQL endpoint and a SPARQL query. Queries can be multi-line:

r endpoint <- "https://lindas.admin.ch/query" query <- "PREFIX schema: <http://schema.org/> SELECT * WHERE { ?sub a schema:DataCatalog . ?subtype a schema:DataType . }"

Retrieve a data frame

r result_df <- sparql2df(endpoint,query)

The same but with attempt at automatic proxy detection:

r result_df <- sparql2df(endpoint,query,autoproxy=TRUE)

Retrieve a list

r result_list <- sparql2list(endpoint,query)

The same but with attempt at automatic proxy detection:

r result_list <- sparql2list(endpoint,query,autoproxy=TRUE)

Owner

  • Name: André Ourednik
  • Login: aourednik
  • Kind: user
  • Location: Europe

From Prague. PhD in Geography at the EPFL. Writer, lecturer, data scientist. Catography, visuliazation, text mining, remote reading.

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "SPARQLchunks",
  "description": "Allows to run 'SPARQL' chunks in R-markdown files. Also provides inline functions to send a 'SPARQL' query to an endpoint and retrieve data in data frame or list form. ",
  "name": "SPARQLchunks: Run 'SPARQL' Chunks and Inline Functions to Retrieve Data",
  "codeRepository": "https://github.com/aourednik/SPARQLchunks",
  "issueTracker": "https://github.com/aourednik/SPARQLchunks/issues",
  "license": "https://spdx.org/licenses/GPL-3.0",
  "version": "0.3",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.5.0 (2025-04-11)",
  "author": [
    {
      "@type": "Person",
      "givenName": "Andre",
      "familyName": "Ourednik",
      "email": "andre.ourednik@epfl.ch",
      "@id": "https://orcid.org/0000-0002-0309-8715"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Andre",
      "familyName": "Ourednik",
      "email": "andre.ourednik@epfl.ch",
      "@id": "https://orcid.org/0000-0002-0309-8715"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "curl",
      "name": "curl",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=curl"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "httr",
      "name": "httr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=httr"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "magrittr",
      "name": "magrittr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=magrittr"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "xml2",
      "name": "xml2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=xml2"
    },
    "SystemRequirements": null
  },
  "fileSize": "24.002KB",
  "citation": [
    {
      "@type": "SoftwareSourceCode",
      "datePublished": "2025",
      "author": [
        {
          "@type": "Person",
          "givenName": "Andr",
          "familyName": "Ourednik",
          "email": "andre.ourednik@epfl.ch"
        }
      ],
      "name": "SPARQLChunks: Query SPARQL endpoints and run SPARQL chunks in R-markdown files.",
      "url": "https://github.com/aourednik/SPARQLchunks",
      "description": "R package version 0.3"
    }
  ],
  "readme": "https://github.com/aourednik/SPARQLchunks/blob/main/README.md",
  "contIntegration": [
    "https://app.codecov.io/gh/aourednik/SPARQLchunks",
    "https://github.com/aourednik/SPARQLchunks/actions/workflows/R-CMD-check.yaml"
  ],
  "developmentStatus": "https://lifecycle.r-lib.org/articles/stages.html#stable",
  "keywords": [
    "rstats",
    "rstats-package",
    "sparql"
  ]
}

GitHub Events

Total
  • Issues event: 4
  • Issue comment event: 5
  • Push event: 10
  • Create event: 2
Last Year
  • Issues event: 4
  • Issue comment event: 5
  • Push event: 10
  • Create event: 2