A new environment clone.out is created and passed around throughout the process of preparing tree data and creating tree grobs (for context).
This approach seems to have been chosen to imitate the behaviour of mutable data structures in other programming languages. This is a valid concern, as R's default behaviour has the potential to create numerous full copies of the input data. With large trees, this would be hugely memory inefficient.
However, this non-standard pattern will be unclear to anyone reading the code that is not completely familiar with the full codebase. I think that the same benefits could be achieved without a new environment through restructuring the data prep and grob creation function calls. Specifically, taking a more "step-by-step" approach (rather than using deeply nested functions) would improve both the readability and the maintainability of the codebase as a whole.
Related to #121
A new environment
clone.out
is created and passed around throughout the process of preparing tree data and creating tree grobs (for context).This approach seems to have been chosen to imitate the behaviour of mutable data structures in other programming languages. This is a valid concern, as R's default behaviour has the potential to create numerous full copies of the input data. With large trees, this would be hugely memory inefficient.
However, this non-standard pattern will be unclear to anyone reading the code that is not completely familiar with the full codebase. I think that the same benefits could be achieved without a new environment through restructuring the data prep and grob creation function calls. Specifically, taking a more "step-by-step" approach (rather than using deeply nested functions) would improve both the readability and the maintainability of the codebase as a whole.