1

How can I get the formals for a method definition in an R6 class definition?

A = R6Class("MyClass",inherit=NULL,
    public = list(
        fun = function(a,b,c){
            # Do Something
        }
    )
)

So for example, in the above, I would like to get the formals for the fun definition, in the same way one can execute, for example, formals(lm)

Nicholas Hamilton
  • 10,044
  • 6
  • 57
  • 88

1 Answers1

2

You can do this by creating an instance of the class:

A = R6Class("MyClass",
        inherit=NULL,
        public = list(
            a = NA,
            initialize = function(a){
                self$a <- a
            },
            fun = function(a,b,c){
                # Do Something
            }
        )
)
B <- A$new(5)
formals(B$fun)

or by accessing the public methods of the class

formals(A$public_methods$fun)
Tutuchan
  • 1,527
  • 10
  • 19