@@ -390,14 +390,17 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) {
390390 for (i in 1 : nodeLen ) {
391391 processClosure(node [[i ]], oldEnv , defVars , checkedFuncs , newEnv )
392392 }
393- } else { # if node[[1]] is length of 1, check for some R special functions.
393+ } else {
394+ # if node[[1]] is length of 1, check for some R special functions.
394395 nodeChar <- as.character(node [[1 ]])
395- if (nodeChar == " {" || nodeChar == " (" ) { # Skip start symbol.
396+ if (nodeChar == " {" || nodeChar == " (" ) {
397+ # Skip start symbol.
396398 for (i in 2 : nodeLen ) {
397399 processClosure(node [[i ]], oldEnv , defVars , checkedFuncs , newEnv )
398400 }
399401 } else if (nodeChar == " <-" || nodeChar == " =" ||
400- nodeChar == " <<-" ) { # Assignment Ops.
402+ nodeChar == " <<-" ) {
403+ # Assignment Ops.
401404 defVar <- node [[2 ]]
402405 if (length(defVar ) == 1 && typeof(defVar ) == " symbol" ) {
403406 # Add the defined variable name into defVars.
@@ -408,14 +411,16 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) {
408411 for (i in 3 : nodeLen ) {
409412 processClosure(node [[i ]], oldEnv , defVars , checkedFuncs , newEnv )
410413 }
411- } else if (nodeChar == " function" ) { # Function definition.
414+ } else if (nodeChar == " function" ) {
415+ # Function definition.
412416 # Add parameter names.
413417 newArgs <- names(node [[2 ]])
414418 lapply(newArgs , function (arg ) { addItemToAccumulator(defVars , arg ) })
415419 for (i in 3 : nodeLen ) {
416420 processClosure(node [[i ]], oldEnv , defVars , checkedFuncs , newEnv )
417421 }
418- } else if (nodeChar == " $" ) { # Skip the field.
422+ } else if (nodeChar == " $" ) {
423+ # Skip the field.
419424 processClosure(node [[2 ]], oldEnv , defVars , checkedFuncs , newEnv )
420425 } else if (nodeChar == " ::" || nodeChar == " :::" ) {
421426 processClosure(node [[3 ]], oldEnv , defVars , checkedFuncs , newEnv )
@@ -429,7 +434,8 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) {
429434 (typeof(node ) == " symbol" || typeof(node ) == " language" )) {
430435 # Base case: current AST node is a leaf node and a symbol or a function call.
431436 nodeChar <- as.character(node )
432- if (! nodeChar %in% defVars $ data ) { # Not a function parameter or local variable.
437+ if (! nodeChar %in% defVars $ data ) {
438+ # Not a function parameter or local variable.
433439 func.env <- oldEnv
434440 topEnv <- parent.env(.GlobalEnv )
435441 # Search in function environment, and function's enclosing environments
@@ -439,20 +445,24 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) {
439445 while (! identical(func.env , topEnv )) {
440446 # Namespaces other than "SparkR" will not be searched.
441447 if (! isNamespace(func.env ) ||
442- (getNamespaceName(func.env ) == " SparkR" &&
443- ! (nodeChar %in% getNamespaceExports(" SparkR" )))) { # Only include SparkR internals.
448+ (getNamespaceName(func.env ) == " SparkR" &&
449+ ! (nodeChar %in% getNamespaceExports(" SparkR" )))) {
450+ # Only include SparkR internals.
451+
444452 # Set parameter 'inherits' to FALSE since we do not need to search in
445453 # attached package environments.
446454 if (tryCatch(exists(nodeChar , envir = func.env , inherits = FALSE ),
447455 error = function (e ) { FALSE })) {
448456 obj <- get(nodeChar , envir = func.env , inherits = FALSE )
449- if (is.function(obj )) { # If the node is a function call.
457+ if (is.function(obj )) {
458+ # If the node is a function call.
450459 funcList <- mget(nodeChar , envir = checkedFuncs , inherits = F ,
451460 ifnotfound = list (list (NULL )))[[1 ]]
452461 found <- sapply(funcList , function (func ) {
453462 ifelse(identical(func , obj ), TRUE , FALSE )
454463 })
455- if (sum(found ) > 0 ) { # If function has been examined, ignore.
464+ if (sum(found ) > 0 ) {
465+ # If function has been examined, ignore.
456466 break
457467 }
458468 # Function has not been examined, record it and recursively clean its closure.
@@ -495,7 +505,8 @@ cleanClosure <- function(func, checkedFuncs = new.env()) {
495505 # environment. First, function's arguments are added to defVars.
496506 defVars <- initAccumulator()
497507 argNames <- names(as.list(args(func )))
498- for (i in 1 : (length(argNames ) - 1 )) { # Remove the ending NULL in pairlist.
508+ for (i in 1 : (length(argNames ) - 1 )) {
509+ # Remove the ending NULL in pairlist.
499510 addItemToAccumulator(defVars , argNames [i ])
500511 }
501512 # Recursively examine variables in the function body.
0 commit comments