11  The {pegboard} package

11.1 Introduction

The {pegboard} package was the very first package written for The Carpentries Workbench. It’s initial purpose was to parse the lessons based on the styles lesson infrastructure to figure out how lesson authors and maintainers were using the challenges and solutions. You can see this analysis in a vignette I started in May 2020 1.

It’s purpose now is two-fold:

  1. parse and validate the lessons for structural markdown elements
  2. translate Carpentries-style materials from the styles lesson infrastructure (Jekyll-based) to The Workbench (Pandoc-based)

11.1.1 Dependencies

The dependency footprint of {pegboard} is intended to be small. The package is intended for validation and translation. It is meant to be stable.

Pegboard was built on top of the {tinkr} package, intially developed by Maëlle Salmon (rOpenSci) and now maintained by Zhian Kamvar. This package uses the CommonMark C library to parse Markdown into XML and then uses a custom XSLT stylesheet to translate Markdown back to XML. One of the key advantages that CommonMark’s XML gives us is the ability to extract line numbers and positions for markdown elements, which allows us to accurately report any Markdown issues to the user.

The objects used in pegboard are created with the {R6} package, which implements encapsulated object orientated programming for R. This style of programming is very similar to that of Python or Java. One of the reasons why we use {R6} is because objects created in this system are modified in place by their methods. This is important because the package to manipulate XML data, {xml2}, is built directly on top of the libxml2 C library, which also modifies objects in place, but it’s not inherently obvious when you work with them, so having a formal system like {R6} to encapsulate them makes more sense than a functional programming framework.


  1. This vignette no longer exists. It stopped working in November 2021, because of updates to the dependencies and the lessons. The vingette took a few minutes to build because it needed to download the lessons, and it was no longer appropriate as {pegboard} was shaping up to be the lesson validator and translator.↩︎