6

R5ジェネレーターオブジェクトを使用してR5のクラスメソッドの定義を表示する公式の方法はありますか?

> cls <- setRefClass("cls", methods = list(f1 = function() {1}))
> 
> # of course we can get the definition via the instance
> a1 <- new("cls")
> a1$f1
Class method definition for method f1()
function () 
{
    1
}
<environment: 0x101d5d3f0>
> 
> # but how to get the difinition via the generator object, i.e., cls?
> cls$f1
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘f1’ is not a valid field or method name for reference class “refGeneratorSlot”
> 
> # here is a workaround, but probably unofficial and no warranty for future behavior
> cls$def@refMethods$f1
Class method definition for method f1()
function () 
{
    1
}
4

1 に答える 1

0
cls@generator$def@refMethods$f1

これはインスタンスを作成しません。ただし、おそらく標準的でも安定的でもありません。

于 2013-07-01T17:25:32.997 に答える