A Method for Deriving Information from Running R Code

It is often useful to tap information from a running R script. Obvious use cases include monitoring the consumption of resources (time, memory) and logging. Perhaps less obvious cases include tracking changes in R objects or collecting the output of unit tests. In this paper, we demonstrate an approach that abstracts the collection and processing of such secondary information from the running R script. Our approach is based on a combination of three elements. The first element is to build a customized way to evaluate code. The second is labeled local masking and it involves temporarily masking a user-facing function so an alternative version of it is called. The third element we label local side effect. This refers to the fact that the masking function exports information to the secondary information flow without altering a global state. The result is a method for building systems in pure R that lets users create and control secondary flows of information with minimal impact on their workflow and no global side effects.

Mark P.J. van der Loo (Statistics Netherlands)
2021-07-13

Supplementary materials

Supplementary materials are available in addition to this article. It can be downloaded at RJ-2021-056.zip

References

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Loo, "A Method for Deriving Information from Running R Code", The R Journal, 2021

BibTeX citation

@article{RJ-2021-056,
  author = {Loo, Mark P.J. van der},
  title = {A Method for Deriving Information from Running R Code},
  journal = {The R Journal},
  year = {2021},
  note = {https://doi.org/10.32614/RJ-2021-056},
  doi = {10.32614/RJ-2021-056},
  volume = {13},
  issue = {1},
  issn = {2073-4859},
  pages = {42-52}
}