我在R
中构建了一个简单的Config引用类,我正在尝试调整它,以便'粘贴'包含Config对象的列表将起作用(类似于重载>>运算符在{{} 1}})。
代码段:
C++
R似乎在列表中忽略了我的覆盖。我想我在语法上缺少一些东西 - 但是找不到相关的足够的例子来让它起作用。
我希望得到:
Config <- setReferenceClass ("Config" , fields = c ("parameters" )
Config$methods (initialize = function (parameters) { .self$parameters = parameters })
setMethod ("as.character", "Config", function (conf) { return (paste (conf$parameters, sep="_", collapse = "_")})
foo = Config$new (list (gender="male", age = c(40,50)))
as.character (foo)
paste (list("a" , foo, 12), sep ="_" , collapse = "_")
相反,我得到:
male_40_50
a_male_40_50_12
和
[1] "male_40_50"