HyukjinKwon commented on a change in pull request #26429: [SPARK-29777][SparkR] SparkR::cleanClosure aggressively removes a function required by user function URL: https://github.com/apache/spark/pull/26429#discussion_r346100705
########## File path: R/pkg/R/utils.R ########## @@ -546,8 +546,11 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) { ifelse(identical(func, obj), TRUE, FALSE) Review comment: No biggie but I think it could be better to combine the condition into here: ```diff --- a/R/pkg/R/utils.R +++ b/R/pkg/R/utils.R @@ -543,14 +543,15 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) { funcList <- mget(nodeChar, envir = checkedFuncs, inherits = F, ifnotfound = list(list(NULL)))[[1]] found <- sapply(funcList, function(func) { - ifelse(identical(func, obj), TRUE, FALSE) + ifelse( + identical(func, obj) && + # Also check if the parent environment is identical to current parent + identical(parent.env(environment(func)), func.env), + TRUE, FALSE) }) if (sum(found) > 0) { - # If function has been examined - if (identical(parent.env(environment(funcList[found][[1]])), func.env)) { - # If the parent environment is identical to current parent - break - } + # If function has been examined, ignore. + break } # Function has not been examined, record it and recursively clean its closure. assign(nodeChar, ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org