Skip to content

mittelmark/pantcl4r

Repository files navigation

pantcl4r

Release license Build filesize downloads all downloads latest

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:

Commands

There are essentially four commands provided:

  • pantcl - converting Rmarkdown documents with embedded code to HTML
  • ptangle - extract programming code into script files from the Markdown document
  • pangui - 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 code
  • df2md - display tabular data within your Markdown documents
  • lipsum - embedding lipsum text in new manuscripts

Below you see an image of the graphical tool:

Install and Use

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")

Motivation

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.

R Examples

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()
.``

![](iris.png)

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.

Equations

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)

Diagrams

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.

Citations

There is as well limited support for embedding citations using the [@key] syntax for BibTeX files. See the vignette for an example.

Author and Copyright

Author: Detlef Groth, University of Potsdam, Germany

License: MIT License see the file LICENSE for details.

Bug reporting

In case of bugs and suggestions, use the issues link on top.

About

Using the pantcl application as R package for literate programming

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published