Skip to content

Commit

Permalink
Avoid calling value$.__enclos_env__ on environments that may not ha…
Browse files Browse the repository at this point in the history
…ve it.

Closes #253.
  • Loading branch information
zeehio committed Apr 16, 2023
1 parent b3c9b05 commit 8b93f16
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/clone.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ generator_funs$.clone_method <- function(deep = FALSE, post_clone_args = list(),
# fields that are R6 objects.
deep_clone <- function(name, value) {
# Check if it's an R6 object.
if (is.environment(value) && !is.null(value$`.__enclos_env__`)) {
if (
is.environment(value) &&
".__enclos_env__" %in% ls(value, all.names = TRUE) &&
!is.null(value$`.__enclos_env__`)
) {
return(value$clone(deep = TRUE))
}
value
Expand Down

0 comments on commit 8b93f16

Please sign in to comment.