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

Cloned R6 objects are detected as different #84

Closed
krlmlr opened this issue Jul 4, 2021 · 1 comment · Fixed by #85
Closed

Cloned R6 objects are detected as different #84

krlmlr opened this issue Jul 4, 2021 · 1 comment · Fixed by #85

Comments

@krlmlr
Copy link
Member

krlmlr commented Jul 4, 2021

but shouldn't?

MyClass <- R6::R6Class(
  "MyClass",
  public = list(
    some_value = 1,
    some_other_value = "a",
    some_method = function() {},
    some_other_method = function(x) x
  )
)

obj <- MyClass$new()
cloned <- obj$clone()

waldo::compare(obj, cloned)
#>     names(old)          | names(new)             
#> [1] "some_other_value"  -                        
#> [2] "some_value"        | "some_value"        [1]
#> [3] "clone"             - "some_other_value"  [2]
#> [4] "some_other_method" | "some_other_method" [3]
#> [5] "some_method"       | "some_method"       [4]
#>                         - "clone"             [5]

Created on 2021-07-04 by the reprex package (v2.0.0)

@krlmlr
Copy link
Member Author

krlmlr commented Jul 4, 2021

Looks like as.list.environment(sorted = TRUE) is broken, at least in R 4.0.5 and 4.1.0?

MyClass <- R6::R6Class(
  "MyClass",
  public = list(
    some_value = 1,
    some_other_value = "a",
    some_method = function() {},
    some_other_method = function(x) x
  )
)

obj <- MyClass$new()
cloned <- obj$clone()

names(as.list(obj, sorted = TRUE))
#> [1] ".__enclos_env__"   "some_other_value"  "some_value"       
#> [4] "clone"             "some_other_method" "some_method"
names(as.list(cloned, sorted = TRUE))
#> [1] "some_value"        "some_other_value"  "some_other_method"
#> [4] "some_method"       "clone"             ".__enclos_env__"

Created on 2021-07-04 by the reprex package (v2.0.0)

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