checkUsage() in the codetools package examines the function and report possible problems.
R functions look for a global variable if the variable is not found in the scope. If a function accidentally has an “orphan” variable which is not passed on to the function but has the same name as one of the global variables, the function will use the value of the global variable. It is a hard to find bug. checkUsage() will find such cases and report.