Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Reference Class be made to Log Calls

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.

like image 594
Ramnath Avatar asked Nov 02 '22 23:11

Ramnath


1 Answers

As @hadley stated:

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

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

like image 200
Thell Avatar answered Nov 12 '22 10:11

Thell