フィールドの 1 つをロックしていない場合は R5 参照クラスをコピーできますが、フィールドの 1 つがロックされている場合はコピーされません。サンプル コードは次のとおりです (lock 呼び出しはコメント アウトされています)。私の質問: copy() メソッドを使用して、ロックされたフィールドを持つインスタンスのコピーを作成できないのはなぜですか?
example <- setRefClass('example',
fields = list(
count = 'numeric',
data = 'data.frame',
d.accessor = function(x) {
if ( !missing(x) )
data <<- x
else
.self$data
}
),
methods = list(
initialize = function( data ) {
if (!missing( data ))
d.accessor <<- data
count <<- 0
},
finalize = function()
print('Bye Bye'),
accumulate = function(x)
count <<- count + x
)
)
#example$lock('data') # write-1, read-many
instance <- example$new() # instantiation
df <- data.frame(x=1, y=2)# example df
instance$d.accessor <- df # 1st set - okay!
copyInst <- instance$copy()