0
library(R6) 
pre <- R6Class("pre",

public = list(
    dbl = NULL,
initialize = function(){},
functionA = function(){},
functionB = function() {}
) )

Here is the code I want:

FunctionA ()
{
    FunctionB ()
}

But there is an error here.

Error: could not find function "functionB"

Please let me know how to fix it.

markalex
  • 8,623
  • 2
  • 7
  • 32

1 Answers1

0
FunctionA = function()
{
  self$FunctionB ()
}    

should do the trick. It is necessary to put self before the name of the memberfunction unless you make your class non-portable. Here is a complete example

library(R6) 
pre <- R6Class(public = list(
  functionA = function(){self$functionB()},
  functionB = function(){"output from B"}
))

obj <- pre$new()
obj$functionA()
# "output from B"
obj$functionB()
# "output from B"
Gregor de Cillia
  • 7,397
  • 1
  • 26
  • 43