Question

I have a question about Reference Classes. My question is in the context of an R package I am developing rCharts. It uses reference classes to create interactive plots from R.

Creating a plot involves a series of calls. Here is an example, where a scatterplot is created at first and then a line plot gets added.

p1 <- rPlot(mpg ~ cyl, data = mtcars, type = 'point')
p1$layer(copy_layer = T, type = 'line')

Now, since a Reference Class is like a closure, I was wondering if it was possible to log the calls made. The idea is that if I can log the sequence of calls made, then I can automagically insert the source code used to create a visualization, along with the html.

I was trying to see if I could make use of sys.function or match.call, but am not getting anywhere. If someone can point me to how I can approach this, it would be much appreciated.

Was it helpful?

Solution

As @hadley stated:

calls <<- c(calls, list(match.call()))

Glad that looks to have worked. Let's get this closed. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top