passing reference class method within the class as an argument

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

passing reference class method within the class as an argument

Eric Berger
Here is the code of a reproducible example:

foo <- setRefClass("foo",
                   fields=list(x="numeric"),
                   methods=list(
                       initialize=function(a) {
                           x <<- a
                       },
                       funcA=function(f) {
                           f(x)+f(x)
                       },
                       funcB=function(y) {
                           y^2
                       },
                       funcC=function() {
                           u <- funcA(funcB)
                           u
                       }
                   ))

w <- foo(2)
z <- w$funcC()
print(z)

When I run this code it gives the following error:

Error in funcA(funcB) : object 'funcB' not found

How am I supposed to pass funcB?

Thanks,
Eric

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.