The R Journal: accepted article

This article will be copy edited and may be changed before publication.

A Method for Deriving Information from Running R Code PDF download
Mark P.J. van der Loo

Abstract It is often useful to tap secondary information from a running R script. Obvious use cases include logging, and profiling of time or memory consuption. Perhaps less obvious cases include tracking changes in R objects or collecting output of unit tests (assertions). In this paper we demonstrate an approach that abstracts collection and processing of such secondary information from the code in the running script. The approach is implemented in pure R, and allows users to control the secondary information stream stream without global side effects and without altering existing code. Although some elements of the approach discussed here have been applied in existing packages, the combination of elements proposed here appears thus far to have been overlooked. Introduction The R language provides a convenient language to read, manipulate, and write data in the form of scripts. As with any other scripted language, an R script gives description of data manipulation activities, one after the other when read from top to bottom. The main advantage of a scripting approach is that it makes each aspect of the data stream completely visible and explicit. This point of strength also reflects as a weakness, namely every operation must necessarily be visible and explicit. Some details can be hidden through regular means of abstraction including functions or object-oriented data structures. But there are cases where functions or object types are not adequate for hiding implementation details. When we need to derive information about a running data processing script, creating a new object type or function will not do because deriving that information implies we need to somehow hamper with the process as it runs. As an example, consider a code fragment where the variable x is manipulated. x[x > threshold] threshold] Received: 2019-10-20; online 2021-06-21

CC BY 4.0
This article is licensed under a Creative Commons Attribution 4.0 International license.

  author = {Mark P.J. van der Loo},
  title = {{A Method for Deriving Information from Running R Code}},
  year = {2021},
  journal = {{The R Journal}},
  doi = {10.32614/RJ-2021-056},
  url = {}