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.
This package isn't on CRAN yet, but you can install it directly from this repository using the
remotes::install_github("stencila/schema", subdir = "r", upgrade = "ask")
This package exports a factory function for each type of document node in the Stencila Schema e.g.
chunk <- CodeChunk( text = "SELECT * FROM data", programmingLanguage = "sql" ) > names(chunk)  "type" "text" "programmingLanguage" > chunk$type  "CodeChunk" attr(,"class")  "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)  "list" "Entity" "Code" "CodeBlock" "CodeChunk" > inherits(chunk, "CodeChunk")  TRUE > inherits(chunk, "Code")  TRUE > inherits(chunk, "Pizza")  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' )
Get started by cloning this repository,
git clone email@example.com:stencila/schema cd schema/r
Most development tasks can be run from R, using
make shortcuts, or RStudio keyboard shortcuts.
| Task |
make | R/RStudio |
| -------------------------------- | --------------- | ------------------------------------- |
| Install development dependencies |
make setup |
make regen |
| Run linting |
make lint |
| Run tests |
make test |
| Re-run tests on changes |
make autotest |
| Run tests with coverage |
make cover |
| Build documentation |
make docs |
| Check the package |
make check |
| Build the package |
make build |
| Clean |
make clean |
Unit tests live in the
tests folder and are written using
Documentation is written using
roxygen2 and the documentation site is generated by
pkgdown into the
docs folder and published on GitHub pages.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.