Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with $clone(deep = TRUE) when private object has a Rcpp class #253

Closed
stla opened this issue Mar 23, 2022 · 0 comments · Fixed by #274
Closed

Issue with $clone(deep = TRUE) when private object has a Rcpp class #253

stla opened this issue Mar 23, 2022 · 0 comments · Fixed by #274

Comments

@stla
Copy link

stla commented Mar 23, 2022

Hello,

> map1$clone(deep = TRUE)
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘.__enclos_env__’ is not a valid field or method name for reference class “uMAPR”
> class(map1$.__enclos_env__$private$.map)
[1] "uMAPR"
attr(,"package")
[1] "mapR"
> typeof(map1$.__enclos_env__$private$.map)
[1] "S4"

uMAPR is a class created with Rcpp:

uMAPR <- setRcppClass("uMAPR")

Such an object is an environment:

> is.environment(map1$.__enclos_env__$private$.map)
[1] TRUE
> ls(map1$.__enclos_env__$private$.map)
 [1] "callSuper"        "copy"             "erase"           
 [4] "field"            "getClass"         "getRefClass"     
 [7] "initialize"       "keys"             "merge"           
[10] "ptr"              "show"             "show#envRefClass"
[13] "size"             "usingMethods"     "values"    

But when you $-subset it with an unexisting field:

> map1$.__enclos_env__$private$.map$xxx
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘xxx’ is not a valid field or method name for reference class “uMAPR”

Thus the error is caused by this piece of code in map1$clone:

      deep_clone <- function(name, value) {
        if (is.environment(value) && !is.null(value$.__enclos_env__)) {
          return(value$clone(deep = TRUE))
        }
        value
      }

There is no error if one replaces !is.null(value$.__enclos_env__) with ".__enclos_env__" %in% ls(value).

cc @eddelbuettel

By the way, there is an external pointer in this object, and the "deep clone" doesn't work: if I modify the deep clone (obtained by the above correction of map1$clone), the modification is also performed on the original object, because of the pointer.

Cheers.

zeehio added a commit to zeehio/R6 that referenced this issue Apr 16, 2023
zeehio added a commit to zeehio/R6 that referenced this issue Apr 16, 2023
zeehio added a commit to zeehio/R6 that referenced this issue Apr 16, 2023
@wch wch closed this as completed in #274 Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant