An R package for literate programming for embedding programming languages like R, Python, Tcl or Octave, display the output of diagram tools like PlantUML, GraphViz, Ditaa or Kroki, embedding citations and much more.
The package pantcl4r is a small scale alternative to Sweave, Rmarkdown, Knitr etc. It is essentially a wrapper for the pantcl application which does not need an installed version of pandoc or any other R package. The package pantcl4r has no dependencies on other non-standard R packages and is currently less than 400kb in size for downloading.
It allows currently the embedding for the following programming languages and tools:
- filter-abc - visualize ABC music notation
- filter-cmd - execute shell scripts for instance Lilypond music scripts, GraphViz scripts, Python, Lua, R scripts, sqlite3 scripts, or code for languages like C, C++, Go, Rust, V etc.
- filter-dot - GraphViz dot filter
- filter-emf - Jasspa MicroEmacs macros filter
- filter-eqn - visualize mathematical equations using eqn2graph, see here Guide for typesetting using eqn
- filter-julia - statistical language Julia (slow for embedding, use R instead) Julia Website
- filter-kroki - visualize diagram code using the kroki webservice
- filter-mmd - visualize diagram code using the mermaid command line tool
- filter-mtex - visualize mathematical equations using LaTeX
- filter-pic - visualize diagram and flowcharts using the PIC language
- filter-pik - visualize diagram code or flowcharts uing pikchr or fossil
- filter-pipe - embed R, Python or Octave code or plots into Markdown
- filter-puml - embed PlantUML code
- filter-rplot - embed R plots
- filter-sqlite - embed Sqlite3 SQL database statements
- filter-tcl - embed Tcl statements
- filter-tcrd - embed Tcl music chords.
- filter-tdot - embed Tcl GraphViz diaragrams
- filter-tsvg - embed Tcl created SVG code
There are essentially four commands provided:
pantcl- converting Rmarkdown documents with embedded code to HTMLptangle- extract programming code into script files from the Markdown documentpangui- simple graphical interface to edit abc music, Graphviz dot, Eqn equations, Mermaid diagrams, Pikchr and Pic code, Plantuml code, R-plots and Tcl-svg or Tcl-dot codedf2md- display tabular data within your Markdown documentslipsum- embedding lipsum text in new manuscripts
Below you see an image of the graphical tool:
To install the latest release for R you can use the following commands from within a R console:
install.packages(
"https://github.com/mittelmark/pantcl4r/releases/download/v0.6.2/pantcl4r_0.6.2.tar.gz",
repos=NULL);
Thereafter you should check the package vignette:
library(pantcl4r)
vignette("tutorial",package="pantcl4r")
To process a Markdown file for example, with embedded R code, you can do the following:
pantcl4r::pantcl("input.Rmd","output.html")
Which will create a file output.html where the R code chunks or chunks of the other languages within input.html are evaluated and the results embedded into the output file if requested.
The package can be seen as a lightweight alternative to the rmarkdown or knitr
packages. In contrast to them you have embed plots using the png and the
dev.off commands within your Rmd document and then use Markdown image syntax
to embed the link after the code block.
If the PNG image is created but not embedded within your file, try to convert the document first to a Markdown document and then call the pantcl command again converting the Markdown to HTML with a second call like this:
pantcl('input.Rmd','output.md'); pantcl('output.md','output.html')
To install the latest development library you need the library 'remotes'.
library(remotes)
remotes::install_github("https://github.com/mittelmark/pantcl4r")
The main purpose of this package to have a simple replacement for the R packages knitr and rmarkdown as there installations are sometimes tricky on simple user accounts like on the University pool machines due to there many dependencies.
Furthermore the pantcl4r packages supports directly Python and Octave code chunks as well as Kroki diagrams which allow the embedding for instance of Ditaa, PlantUML and GraphViz.
Here is example code on how to embed R code:
```{r eval=TRUE}
print('Hello World!)
```
And short R expressions can be as well inlined directly into the text:
The iris data set has `r nrow(iris)` plants
Plots should be creates as PNG graphs like this (replace leading dot with backtick):
.``{r eval=TRUE}
png("iris.png")
pairs(iris)
dev.off()
.``

Table display is as well supported using the function df2md and the function can be used like this:
.``{r eval=TRUE,results="asis"}
cat(df2md(head(iris)))
.``
The code chunks can be hidden if you use the code chunk option echo=FALSE.
Mathematical equations using MathJax are as well supported since version 0.5.0. Just embed lines like:
some text \\( inline equation \\) and some more text.
Or:
\\[ block equation \\)
Or:
$$ block equation $$
into your text and use the argument mathjax=TRUE in your pantcl call like this:
pantcl("input.Rmd","output.html",mathjax=TRUE)
The package supports without external applications except for curl or wget to be installed as well diagram code display using the krokio webservice.
Here an example for a GraphViz diagram (replace singe quotes with backticks):
'''{.kroki dia=graphviz,eval=TRUE,echo=FALSE}
digraph {
node[style=filled,fillcolor=skyblue];
rankdir="LR";
A -> B;
}
'''
Which should embed the diagram like this:
There is as well support for other diagram types like Ditaa or PlantUML.
There is as well limited support for embedding citations using the [@key] syntax for BibTeX files. See the vignette for an example.
Author: Detlef Groth, University of Potsdam, Germany
License: MIT License see the file LICENSE for details.
In case of bugs and suggestions, use the issues link on top.
