Yes, I read the Hydrogen documentation and that’s when the magic began

Then I realised the following:

  1. In Archlinux, I would need to install Hydrogen from the terminal, apk install Hydrogen.
  2. Then, once I am inside Atom, I’d have to install R, and Python as processes inside Atom. So, I’d have to install apk install atom-language-r to get Hydrogen working in Atom.
  3. Then the beauty of working with Hydrogen unfolds. You start an asciidoc document, and you will need to install all the packages from asciidoctor, so install asciidoc-preview package within Atom.
  4. Now, start a new document and call it say mydocument.adoc This will open an asciidoc document within Atom with its own code segments. Let’s say your document looks like this:
= This is the title of my document== This is the second level header or a sectionThis is my regular text written in Asciidoc. For adding hyperlink to say Medium, I'd write something like  or say  or link:[Medium]. If you want to insert tables, you can do something like:
| Header 1 |Heading of table
|data for first column |data for second column
This will put a table in the document. And on you go, adding citations as <<citeid>> and add a reference block at the end of the document. == Now add a code block
Add a code block. We will do some simple analyses, see
[source, R]
data(mtcars) mtcars %>%
head() %>%
== References
* [[[citeid]]] Full reference ...

So far, it’d look like a regular asciidoc document. If you activated the asciidoc-preview component using ctrl-shift-a in Linux, you’d see a pane of html document and you keep working on the document. But you want a data driven document which is why you installed Hydrogen in the first place. So, now, you activate R instead of asciidoc and move your cursor inside the R code block. Then press ctrl-enter As you do, Hydrogen window opens and you get to see the code executed. Some points:

  • You need to use the R ascii package install.packages("ascii") to get full value of the tables. You cannot do this using kable or xtable to put out pretty tables.
  • Use the ascii(table_data) to output table formatted as asciidoc tables.

This is where magic happens now. You have the power of asciidoc+R all in the same document happening seamlessly. I am happier with this compared with my other workflow where I have to rely on knitr first to transform a file with the extension .Radoc and then weave with knitr again to get the full functionality. Here, you have ONE hydrogen document with the parts included and it just works.

Hydrogen rocks.

Associate Professor of Epidemiology and Environmental Health at the University of Canterbury, New Zealand. Also in:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store