From 4dba01a42bc90d55b21ade5ff7bf26bab9136907 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Mon, 17 Apr 2023 12:41:12 +0200 Subject: [PATCH] Fix performance impact (get0) R>=3.2 --- DESCRIPTION | 2 +- R/clone.R | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 037b389..3d1fce5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ License: MIT + file LICENSE URL: https://r6.r-lib.org, https://github.com/r-lib/R6/ BugReports: https://github.com/r-lib/R6/issues Depends: - R (>= 3.0) + R (>= 3.2) Suggests: lobstr, testthat (>= 3.0.0) diff --git a/R/clone.R b/R/clone.R index c63ca63..f9c0274 100644 --- a/R/clone.R +++ b/R/clone.R @@ -89,11 +89,9 @@ generator_funs$clone_method <- function(deep = FALSE) { # fields that are R6 objects. deep_clone <- function(name, value) { # Check if it's an R6 object. - if ( - is.environment(value) && - ".__enclos_env__" %in% ls(value, all.names = TRUE) && - !is.null(get(".__enclos_env__", value)) - ) { + is_r6_object <- is.environment(value) && + !is.null(get0(".__enclos_env__", value, inherits = FALSE)) + if (is_r6_object) { return(value$clone(deep = TRUE)) } value