I'm trying to use a construct such as "with" to allow easier (lazier ?) manipulation of an R6 object. Consider the following (minimal) example:
library(R6)
ToyClass<-R6Class(classname = "ToyClass",
public = list(
data=data.frame(x=c(1,2,3),y=c(4,5,6)),
color = "red",
symbol = 16,
initialize=function(mult){
self$data$x <- self$data * mult
}
)
)
foo <- ToyClass$new(2)
I can, obviously, plot the data in my object with
plot(foo$data$x,foo$data$y,col=foo$color,pch=foo$symbol)
However, being lazy (and since I have a lot of such objects to plot, so copy/paste/edit is time-consuming and prone to errors) I'd like to do
with(foo,
plot(data$x,data$y,col=color,pch=symbol)
)
Which does not work:
Error in plot(data$x, data$y, col = color, pch = symbol) :
could not find function "plot"
I understand why (foo behaves as an environment, in which plot() is not defined), but I cannot find a solution. How can I look for function names, I presume, in the global environment ?