【问题标题】:R - How to format list of methods in Reference Class?R - 如何格式化参考类中的方法列表?
【发布时间】:2017-09-17 02:47:43
【问题描述】:

我有一个更复杂的参考类,我将其精简为以下代码:

make_LD <- setRefClass("Longitudinal_Data",
                       methods = list(
                         populator <- function() {
                           print("Working")
                         }))
make_LD$populator()

Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘populator’ is not a valid field or method name for reference class “refGeneratorSlot”

但出现上述错误。我根本不清楚我错过了什么。方法populator 显示在make_LD$methods() 下,但不在make_LD$getClass() 下。我已经为该方法尝试了几种不同的变量名称。

【问题讨论】:

    标签: r function class methods


    【解决方案1】:

    make_LD 是一个构造函数!您可以使用它来制作一个对象,然后您就可以使用该对象。
    要检查,请使用此代码

    make_LD <- setRefClass("make_LD",
                           methods = list(
                             populator = function() {
                               print("Working")
                             }
                           ))
    mkld <- make_LD()
    mkld$populator()
    

    【讨论】:

    • 也用“=”代替“
    猜你喜欢
    • 1970-01-01
    • 2010-09-16
    • 2021-04-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多