Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, develop]
pull_request:
name: R-CMD-check.yaml
permissions: read-all
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v6
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ Description: The main goal is to connect to SPARQL endpoints and bering their st
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
LazyData: true
Imports:
S7,
tools,
httr2,
stats
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Depends:
R (>= 4.3)
Config/roxygen2/version: 8.0.0
77 changes: 77 additions & 0 deletions R/endpoint_class.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#' 'SPARQL' endpoint (base class)
#'
#' The base S7 class every endpoint backend inherits from. You will
#' not normally call `sparql_endpoint()` directly -- use a specific
#' constructor like `new_generic_endpoint()`.
#'
#' @param url Character. The SPARQL endpoint URL (the address a query
#' is sent to).
#' @param name Character. A short label for the endpoint, used for
#' caching and messages.
#' @param headers A named list of extra HTTP headers sent with every
#' request (for example a custom `User-Agent`).
#' @param timeout Numeric. Request timeout in seconds.
#'
#' @export
sparql_endpoint <- S7::new_class(
"sparql_endpoint",
properties = list(
url = S7::new_property(
S7::class_character,
validator = function(value) {
if (length(value) != 1 || !nzchar(value)) "must be a single non-empty string"
}
),
name = S7::new_property(
S7::class_character,
default = quote(NA_character_),
validator = function(value) {
if (length(value) != 1) "must be a single string (or NA)"
}
),
headers = S7::new_property(
S7::class_list,
default = quote(list()),
validator = function(value) {
if (length(value) > 0 && (is.null(names(value)) || any(!nzchar(names(value))))) {
"must be a fully named list"
}
}
),
timeout = S7::new_property(
S7::class_numeric,
default = 60,
validator = function(value) {
if (length(value) != 1 || is.na(value) || value <= 0) "must be a single positive number"
}
)
)
)

#' Generic 'SPARQL' 1.1 backend
#'
#' The fallback backend used for any endpoint that isn't registered
#' under a more specific class.
#'
#' @param url,name,headers,timeout See [sparql_endpoint()].
#' @export
generic_endpoint <- S7::new_class("generic_endpoint", parent = sparql_endpoint)

#' Discover the classes used by an endpoint
#' @param endpoint A `sparql_endpoint` object.
#' @param ... Passed on to methods (commonly `limit`).
#' @return A data frame with columns `class` and `n`.
#' @export
ep_classes <- S7::new_generic("ep_classes", "endpoint")

#' Discover the properties (predicates) used by an endpoint
#' @inheritParams ep_classes
#' @return A data frame with columns `property` and `n`.
#' @export
ep_properties <- S7::new_generic("ep_properties", "endpoint")

#' Discover which classes are linked by which properties
#' @inheritParams ep_classes
#' @return A data frame with columns `from_class`, `property`, `to_class`, `n`.
#' @export
ep_class_links <- S7::new_generic("ep_class_links", "endpoint")
5 changes: 5 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NULL

.onLoad <- function(libname, pkgname) {
S7::methods_register()
}
19 changes: 19 additions & 0 deletions man/ep_class_links.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/ep_classes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/ep_properties.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/generic_endpoint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions man/sparql_endpoint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions man/sparql_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-endpoint_class.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("sparql_endpoint validator rejects a bad url", {
expect_error(sparql_endpoint(url = ""))
expect_error(sparql_endpoint(url = c("a", "b")))
})
Loading