Yes, I read the Hydrogen documentation and that’s when the magic began
Then I realised the following:
- In Archlinux, I would need to install Hydrogen from the terminal,
apk install Hydrogen.
- 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-rto get Hydrogen working in Atom.
- Then the beauty of working with Hydrogen unfolds. You start an
asciidocdocument, and you will need to install all the packages from asciidoctor, so install
asciidoc-previewpackage within Atom.
- Now, start a new document and call it say
mydocument.adocThis 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 http://www.medium.com or say http://www.medium.com[Medium], or link:http://www.medium.com[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--
library(ascii)data(mtcars) mtcars %>%
* [[[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
xtableto 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.