Package 'openalexStandard'

Title: Check Packages and Corpora Against the openalexPro Ecosystem Standard
Description: Checks R packages and Parquet corpora against STANDARD.md of the openalexPro ecosystem (corpus layout, works schema, provenance files, identifiers, link table, package requirements) and writes compliance reports. Used in package tests and by the ecosystem's compliance workflow.
Authors: Rainer M. Krug [aut, cre] (ORCID: <https://orcid.org/0000-0002-7490-0066>)
Maintainer: Rainer M. Krug <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-11-30 15:11:58 UTC
Source: https://github.com/openalexPro/openalexPro_Ecosystem

Help Index


Check an annotation folder against STANDARD.md (N1-N3, T2)

Description

Check an annotation folder against STANDARD.md (N1-N3, T2)

Usage

check_annotation(dir, corpus = NULL)

Arguments

dir

The annotation folder, ⁠<project>/<prefix>_<name>/⁠.

corpus

Optional: the corpus it annotates. When given, the partitions and ids of the annotation must exist in it.

Value

A data frame of results, as check_corpus().


Check a corpus folder against STANDARD.md

Description

Runs every automatable corpus rule of STANDARD.md (sections 1-5 and 7, and T1/T2 for transformers) on a corpus folder and its sibling link table. The corpus is only read, never changed.

Usage

check_corpus(
  dir,
  links = file.path(dirname(dir), "links"),
  kind = c("writer", "transformer"),
  prefix = NULL,
  api = TRUE
)

Arguments

dir

The corpus folder: the folder a reader is given, with ⁠query=<name>/⁠ partitions and ⁠_dataset.json⁠.

links

The link table folder (K1). Defaults to ⁠links/⁠ next to dir.

kind

"writer" or "transformer"; transformers are also checked for T1 and T2.

prefix

The writer's prefix (I5), or the prefixes of all writers of a mixed corpus. Defaults to the prefix(es) in ⁠_dataset.json⁠.

api

Also run openalexAPI::prepare_corpus() (pseudo-rule API) when openalexAPI is installed.

Value

A data frame with one row per rule: rule, level, status (pass, fail, n/a, not verified, manual), evidence, fix.


Check an R package source against STANDARD.md

Description

Checks the package rules (P1-P7) from DESCRIPTION, NAMESPACE and the source, works out which kinds of package it is (writer, consumer, transformer, annotator; STANDARD.md section 8), and flags code to review for A1 and A3. Works for any package, in the ecosystem or not.

Usage

check_package(path, kind = NULL, manifest = NULL)

Arguments

path

Package source folder.

kind

Kinds to assume instead of detecting them.

manifest

Optional paths to the ecosystem's repos.tsv and/or compliance/external.tsv; when given, P6 also checks that the package is listed in one of them (by package name).

Value

A data frame of results, as check_corpus(), with attributes package, version, kind and prefix.


Write the index page of the report site

Description

Write the index page of the report site

Usage

compliance_index(
  site = "compliance",
  state = jsonlite::read_json(file.path(site, "state.json"))
)

Arguments

site

The report site folder.

state

The parsed state file (a named list, ⁠<owner>/<repo>@<branch>⁠).

Value

The path of index.md, invisibly.


Publish compliance reports into the report site

Description

Used by the ecosystem's compliance workflow. Each folder in artifacts holds the output of one compliance_report() run plus target.json (repo, branch, commit, private, standard, checker, deps). The reports are copied to ⁠<site>/<owner>/<repo>/<branch>.md|json⁠ (the redacted version for private repositories), state is updated, and ⁠<site>/index.md⁠ is rebuilt from all reports.

Usage

compliance_publish(
  artifacts,
  site = "compliance",
  state = file.path(site, "state.json")
)

Arguments

artifacts

Folder with one sub-folder per checked repository and branch.

site

The report site folder (⁠compliance/⁠ in the ecosystem repo).

state

The state file recording what was checked.

Value

The paths written, invisibly.


Compliance report for a package

Description

Checks a package source with check_package(). For writers and transformers it then builds the package's example corpus (⁠<prefix>_example_corpus()⁠, STANDARD.md P7) in a temporary folder and checks it with check_corpus(). Every rule of STANDARD.md gets one row: rules for other kinds of package are n/a, rules that need a review are manual, rules that could not be checked are ⁠not verified⁠.

Usage

compliance_report(
  path,
  out_dir = NULL,
  redact = FALSE,
  repo = NULL,
  ref = NULL,
  commit = NULL,
  kind = NULL,
  manifest = NULL,
  api = TRUE
)

Arguments

path

Package source folder.

out_dir

Folder to write report.md and report.json to; NULL writes nothing.

redact

Also write report_public.md / report_public.json without evidence and fixes (for private repositories).

repo, ref, commit

Shown in the report header (e.g. owner/name, branch, commit SHA).

kind, manifest

Passed to check_package().

api

Run openalexAPI::prepare_corpus() on the example corpus.

Details

The report is deterministic: it names the package commit, the standard version and the checker version, but no date, so re-checking an unchanged package gives an identical file.

Value

The results (a data frame) with attribute meta, invisibly.


Fingerprint of the data files of a corpus (STANDARD.md D5)

Description

SHA-256 of one line per Parquet file below dir (sorted by relative path): ⁠<relative path>\t<size>\t<SHA-256 of the last 65536 bytes>⁠. The last bytes hold the Parquet footer (row counts, schema, column statistics), so the fingerprint changes with the data but not when the corpus is copied.

Usage

content_fingerprint(dir)

Arguments

dir

A corpus (or annotation) folder.

Value

"sha256:<hex>".


Expect a corpus to comply with STANDARD.md

Description

A testthat expectation for package tests: fails when any MUST rule of check_corpus() fails, and lists them.

Usage

expect_compliant_corpus(dir, ...)

Arguments

dir

Corpus folder.

...

Passed to check_corpus().

Value

dir, invisibly.


Where a corpus or annotation comes from

Description

Follows derived_from in ⁠_dataset.json⁠ back to the sources, and checks each recorded content fingerprint against the input's current data (D5).

Usage

provenance(dir)

Arguments

dir

A corpus or annotation folder.

Value

A data frame: level (0 = dir), path, writer, checksum (ok, changed, none, missing, external).


A small corpus that follows STANDARD.md

Description

Writes three works (⁠zenodo:⁠ ids, as written by openalexImportZenodo) with ⁠_dataset.json⁠, ⁠_query.json⁠, ⁠_query.html⁠ and a link table below the project folder out, and returns the corpus folder. Used to test packages that read corpora (A2) and annotators (P7a).

Usage

standard_example_corpus(out = tempfile())

Arguments

out

Project folder to write into.

Value

The path of the corpus folder.


Registered prefixes (STANDARD.md I5) and identifier schemes (I7)

Description

Registered prefixes (STANDARD.md I5) and identifier schemes (I7)

Usage

standard_prefixes()

standard_schemes()

Value

standard_prefixes(): data frame prefix, package, kind. standard_schemes(): character vector.


Rules of STANDARD.md, as known to the checks

Description

One row per rule: rule, level (MUST/SHOULD/MAY), section, kinds (⁠;⁠-separated: writer, consumer, transformer, annotator), automated (yes/partly/manual) and a one-line summary. The pseudo-rule API is openalexAPI's prepare_corpus() on the corpus.

Usage

standard_rules()

Value

A data frame.


Version of STANDARD.md the checks implement

Description

Version of STANDARD.md the checks implement

Usage

standard_version()

Value

A string, e.g. "0.1".


Add compliance scaffolding to a package

Description

Like the usethis functions: adds what a package needs to be checked against STANDARD.md, and never overwrites an existing file.

Usage

use_compliance(path = ".", prefix = NULL, kind = NULL)

Arguments

path

Package source folder.

prefix

The package's registered prefix (I5). Defaults to the one registered for the package, if any.

kind

Kinds of package, as in check_package(); detected by default.

Details

  • Config/openalexPro/standard in DESCRIPTION (P2a), and openalexStandard and openalexAPI in Suggests and Remotes (with the desc package, if installed; else a message), whether or not they are installed;

  • writers and transformers: R/example_corpus.R with a stub of ⁠<prefix>_example_corpus(out)⁠ to fill in (P7), and tests/testthat/test-compliance.R running expect_compliant_corpus() and openalexAPI::prepare_corpus() on it (P4);

  • .github/workflows/compliance.yml calling the ecosystem's reusable compliance-check workflow with fail-on: none.

Run devtools::document() afterwards, so the stub is exported.

Value

The paths created or changed, invisibly.


Write ⁠_dataset.json⁠ for a corpus or annotation (STANDARD.md D1-D3, T2, N2)

Description

Writes a deterministic marker file: no timestamps, no absolute paths, fixed field order, so an unchanged corpus gets a byte-identical file. Call it after the data are written: it records their fingerprint (content, D5).

Usage

write_dataset_json(
  dir,
  package,
  version,
  prefix,
  id_format = NULL,
  type = c("works", "annotation"),
  partition_keys = "query",
  derived_from = NULL,
  method = NULL
)

Arguments

dir

The corpus (or annotation) folder.

package, version

The writing package and its version.

prefix

The writer's registered prefix (I5).

id_format

The template of id (I3), e.g. "zenodo:<conceptrecid>"; "https://openalex.org/<id>" for OpenAlex records.

type

"works" (a corpus) or "annotation".

partition_keys

The Hive partition keys, top level first.

derived_from

Inputs (transformers, annotators): corpus folders, stored relative to dir with their fingerprint (D5), and/or external sources as list(source = "openalex-snapshot", release = "2026-10-28").

method

For annotations (N2): a list with the method name, version and settings.

Value

The path of the file, invisibly.