5
필드 중 하나를 잠근 적이없는 경우 R5 참조 클래스를 복사 할 수 있지만 필드 중 하나가 잠겨 있으면 복사되지 않습니다. 예제 코드는 다음과 같습니다 (잠금 호출이 주석으로 처리됨). 내 질문 : copy() 메서드를 사용하여 잠긴 필드가있는 인스턴스의 복사본을 만들 수없는 이유는 무엇입니까? 인스턴스를 복사 할 때, 필드 데이터가 잠금에 의해 금지되어 두 번가 할당되기 때문에잠긴 변수가있는 R5 참조 클래스 복사
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()