The scaffolder package provides a comprehensive set of tools to automate the process of scaffolding interfaces to modules, classes, functions, and documentations written in other programming languages. As initial proof of concept, scaffolding R interfaces to Python packages is supported via reticulate.

Why do we need this package?

Let’s say if we want to write an interface to an existing Python package. reticulate package is the perfect tool to facilitate that. reticulate package contains a powerful set of tools for interoperability between Python and R. It allows R users to call Python from R in many different ways and automatically translate between different R and Python objects.

However, if we use reticulate often enough, we will face many challenges, for example:

  • We need to copy-paste doc-strings from Python API and then edit it in order to provide API references for the R wrapper functions. This requires a lot of editing and endless maintenance efforts in the future to keep the consistency between the API references in both Python and R.
  • We need to copy-paste the default values for all the parameters and translate Python objects to R objects when writing the R wrapper functions (e.g. None -> NULL, True -> TRUE, convert Python list literals in the docs to R lists, massage R numeric values to Python integers via as.integer where required, etc.). And then again, this requires future maintenance in order to keep them up-to-date.

The scaffolder package comes to the rescue. It provides functions to automatically scaffold and customize the R wrapper interfaces to modules, classes, functions, and documentations written in other programming languages. Users are able to customize different parts of the scaffolding process in order to avoid the additional editing that we mentioned above. For example, users can implement a function to cast parameters with default values that contains “L” to integers.

History

The core functionalties of this package were originally developed as part of reticulate’s scaffolding functionalities to facilitate the process of writing different components of the R interface to TensorFlow. We found the process of writing R wrappers very tedious and then developed the scaffolding functionalities in reticulate that are marked for internal use only. It was then further developed and experimented to automate the generation of h2oai/h2o4gpu’s R package.

Getting started

Installation

Install the scaffolder package from CRAN as follows:

install.packages("scaffolder")

Or you can install it from GitHub as follows:

install.packages("remotes")
remotes::install_github("terrytangyuan/scaffolder")

Examples

Please checkout the examples here.