MyNixOS website logo
Description

Bindings for Stencila Schema.

Provides R bindings for the Stencila Schema <https://schema.stenci.la>. This package is primarily aimed at R developers wanting to programmatically generate, or modify, executable documents.

Stencila Schema for R

Build Status Code coverage CRAN Docs

This package provides R bindings for the Stencila Schema. It is primarily aimed at R developers wanting to programmatically generate, or modify, executable documents. For example, it is used in rasta, a Stencila plugin for R.

Install

This package isn't on CRAN yet, but you can install it directly from this repository using the remotes package,

remotes::install_github("stencila/schema", subdir = "r", upgrade = "ask")

Use

This package exports a factory function for each type of document node in the Stencila Schema e.g. Article, Paragraph, CodeChunk.

For example,

chunk <- CodeChunk(
  text = "SELECT * FROM data",
  programmingLanguage = "sql"
)
> names(chunk)
[1] "type"                "text"                "programmingLanguage"
> chunk$type
[1] "CodeChunk"
attr(,"class")
[1] "scalar"    "character"

Note that the type property is set automatically. The class of the node also includes the full hierarchy of ancestor types, so you can use the inherits function as needed:

> class(chunk)
[1] "list"      "Entity"    "Code"      "CodeBlock" "CodeChunk"
> inherits(chunk, "CodeChunk")
[1] TRUE
> inherits(chunk, "Code")
[1] TRUE
> inherits(chunk, "Pizza")
[1] FALSE

Each constructor function checks that the arguments provided conform to the Schema. For example,

# Wrong type for a property supplied
Article(
  authors = Paragraph('My article title')
)
Error: CreativeWork$authors is type Paragraph, expected type Array(Union(Person, Organization))

# Required property not supplied
Article(
  authors = list(Person(givenNames = 'John',  familyNames = 'Smith'))
)
Error: Article$title is required

# Success!
Article(
  authors = list(Person(givenNames = 'John',  familyNames = 'Smith')),
  title = 'My article title'
)

Develop

Get started by cloning this repository,

git clone [email protected]:stencila/schema
cd schema/r

Most development tasks can be run from R, using make shortcuts, or RStudio keyboard shortcuts.

TaskmakeR/RStudio
Install development dependenciesmake setup
Regenerate R/types.Rmake regen
Run lintingmake lintlintr::lint_package()
Run testsmake testdevtools::test() or Ctrl+Shift+T
Re-run tests on changesmake autotesttestthat::auto_test_package()
Run tests with coveragemake covercovr::package_coverage()
Build documentationmake docsdevtools::document()
Check the packagemake checkCtrl+Shift+E
Build the packagemake builddevtools::build() or Ctrl+Shift+B
Cleanmake clean

Testing

Unit tests live in the tests folder and are written using testthat.

Documentation

Documentation is written using roxygen2 and the documentation site is generated by pkgdown into the docs folder and published on GitHub pages.

Continuous integration

Tests are run on Azure Pipelines and code coverage tracked at Codecov.

Metadata

Version

1.0.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows