Play Modules in R
Sign in to queue


useR!2017: Modules in R

Keywords: programming, functional-programming
In this talk I present the concept of modules inside the R language. The key idea of the modules package is to provide a unit of source code which is self contained, i.e. has it's own scope. The main and most reliable infrastructure for such organisational units of source code is a package. Compared to a package modules can be considered ad-hoc, but still self contained. That means they come with a mechanism to import dependencies and also to export member functions. However, modules do not act as replacements for packages. Instead they are a unit of abstraction in between functions and packages.
There are two use cases in which modules can be beneficial. First when we write scripts and want to use sourced functions or, in general, need more control of the enclosing environment of a function. Here we may be interested to be able to state the dependencies of a function close to its definition; and also without the typical side effects to the global environment of the current R session. Second, as an organisational unit inside packages. Here modules can act as similar entities as objects in object-oriented-programming. However, other languages with similar concepts are mostly functional and the design borrows from languages like julia, Erlang and F#. As a result modules are not designed to contain data. Furthermore there is no formal mechanism for inheritance. Instead several possibilities for module composition are implemented.





Right click to download this episode

The Discussion

Add Your 2 Cents