Suppose I have an R6 class and one of it's elements is an external pointer pointing to some C++ object.
So I have something like this:
myClass <- R6::R6Class(
"myClass",
public = list(
xp = NULL,
initialize = function(x) {
self$xp = cpp_fun_that_returns_a_pointer(x)
}
)
)
If I use myclass$clone()
it will still point to the same myclass$xp
. This will also happen if I do myclass$clone(deep = TRUE)
since it doesn't know how to clone in the C++ side.
In this case I could use a custom deep_clone
method...
But since in my use case it will always be wrong to clone the class without deep cloning it, I am wondering if it is possible to change the behavior of clone
directly.
I tried just creating a clone()
method and it's not allowed by R6.
Error in R6::R6Class("tensor", cloneable = FALSE, private = list(xp = NULL), :
Cannot add a member with reserved name 'clone'.