Explore making IndirectCallFunList a list so can have more than one function parameter.
[low priority] getFunctionDefs(, recursive = TRUE) doesn't handle chained assignment \code{a <- b <- function(...) ...}. See R/varsInLoop.R.
add recursive parameter to extractFunctions to control nested functions, e.g., top-level function that contains fun1 which itself contains fun2
2 bugs shown in extractFunctions and related to findNamedFunctions. Doesn't handle
a <- b <- function()...
var = if(...) function() ... else function( ) ...
See get_CITATION_entry_fields and check_doi_db in tools package.
Combine and rationalize mkGlobalsLocal's .addDefault and addDefault parameters.
added the latter very quickly when reimplementing functions w/o rstatic and didn't read the code.
Document getIndirectCallFunList
have procIndirectCal... match the parameter names.
source("~/Books/NextLevelComputationalReasoning/ExploreCode/Variety_trial_analysis/code/uc_ipm_funs.R")
getGlobals(get_stn_info, indirectCallFunctions = names(CodeAnalysis:::getIndirectCallFunList(xpathSApply = "fun", xpathApply = "fun")))
√ getInputFiles, etc. - optionally allow/disallow calls/language objects in the results. Sometimes just want the literal strings.
getSourceInfo()
√ make recursive.
getFunctionDefs for call
getFunctionDefs(quote(function(x) function(mu, sd) prod(dnorm(x, mu, sd))))
returns both when recursive is either TRUE or FALSE√ example for ifCall and whileCall gives very nested list.
callGraph() - add special edges between generic function and its methods
Could also find the as(x, "class") and try to figure out which setAs() is in effect, but need to know the class of x.
getGlobals() doesn't detect local variable in the code blocks in an if()-else could be a global
same with x < 0 || (w <- any(is.na(x))) when x is < 0 and second term not evaluated.
Find unused parameters and local variables
can we adapt getGlobals() to identify local variable creation and then if it is used.
isIndidrectCall - errors in call to match.call()
√ for now, tryCatch() and if isLHS is NA or TRUE, try the funName<-
version of the function.
[check] programmatically determine if a function returns a function - returnsFunction()
fix to deal with processing assignments in subfunctions and not the function itself.
[check] findCallsTo - extend to identify do.call and *apply calls.
√ when processing a call, check if isCallTo(x, OneOfTheseFunctions) and if so, is the FUN argument (or corresponding argument) a call to the target functions.
getFunctionDefs() - have it find functions in setMethod(), i.e. the fun in the setMethod(meth, sig, fun)
perhaps put better name on "these" (what ?) methods and generics.
circular references in parameters
See explorations/findSelfRef.R.
fix callGraph(fun) and the name used is obj. (meaning what??).
obj is the name of the first argument.
implement findOS()/mkOSWalker for finding code that depends on the platform/OS
use of .Platform$field
[check. Seems done. ] Fix mkGlobalsLocal() to optionally not add a default value to a parameter e.g. not replace Jvar with .Jvar = Jvar
Have mkGlobalsLocal() return the entire list, not just the ones that were changed. Make this an option.
mkGlobalsLocal() not changing references inside return() clause. See rstatic probably.
example/test?
for loop concatenation, rewrite the code. We need type information about the elements to be able to initialize the answer vector.
[low priority] code analysis example (unrelated to highlighting, just the example)
if (grepl(sprintf("%s$", extension, ignore.case = TRUE), name))
check whether a named argument in a call makes sense in the parent call.
[check/robustify] isAssignTo - make it handle complex left hand side.
x$y <- value
is a call to $<-
(x, y) and misses value. Need to go back up the
tree. x$y <-value
is parsed as <-(x$y, value)
findAssignsTo(findCallsTo, "isEnv") doesn't find the assignment in the if condition.
findCallsTo and findCallsToFunctions - check if should consolidate/remove one
same with getAllCalls
Allow control of reporting non-local variables in nested functions.
√ [tests/getGlobalsSkipCalls.R] See skip in getGlobals() so can avoid NSE functions such as until() and friends in GSPAutoTest.
√ Check substitute() calls for non-local variables in the expression that are in the second argument.
√ if(cond) warning else stop
detects warning, but not stop, as a global variable.
√ remoteDriver$new()
in GSPAutoTest::getDriver() - reports remoteDriver as a global variable. Allow caller to specify
what is available in the imports/search path.
If add a parameter to a function, what calls do we need to change.
√ [test] fix findCallsParam to handle indirect calls.
√ [yes] equivalent to rstatic::find_nodes
mkCallWalkerPred()
√ Fix mkGlobalsLocal when no named arguments and match.call() doesn't put any names on them.
√ getInputFiles and getOutputFiles and getGraphicOutputFiles
process the correct argument in the call.
√ getGraphicsOutputFiles and for Output functions.
make getGraphicsDevFuns()
√ listReadDataFuns() and listWriteDataFuns() - allow return a list if any elements have a different number
listWriteDataFuns( myWrite = c("a", "b"))
Don't break the other uses of the primitive function underlying this.
√ callGraph(".") for CodeAnalysis/R gives an error cannot change value of locked binding for
'isAssignReturn
√ If a function has a literal externalptr inlined, then getGlobals() fails in lapply(els, fun, w)
p = new('externalptr')
f = function() return(x)
body(f)[[2]] = p
getGlobals(f)
g = function() { if(x < 0) y else p}
body(g)[[2]][[4]] = p
getGlobals(g)
g = function(a = 1) { if(x < 0) y else p}
formals(g)$a = p
getGlobals(g)
Done for the other code walker generators and top-level functions that call them
√ Check uses of isAssignTo/isSimpleAssignTo and ensure they are okay with the check the RHS is a name, not a complex LHS.
Checked where they were used and made this change.
√ in findCallsTo(), if parse fails, make it happen silently.
findFunctionDefs()/getFunctionDefs() doesn't handle name = name2 = function() ...
Old
Re. above - should we get rid of findFunctionDefs()
getFunctionDefs("tests/chainedAssigns.R")
Fix message from getGlobals
In procIndirectFunCall(e, funName) :
cannot currently determine function in empty call to match.call. That uses the context of the call.1
remove this message. It occurs with calls to match.call() and formals() with no arguments. There are no variables there - global or local.
√ false positive for global variables in R CMD check for textConnection("bob", "w", local = TRUE); bob
√ We can make getGlobals() understand it.
removeAfterReturn should work recursively to process blocks within functions.
remove unused parameters - see findUnusedArgs/findUnusedParams. also unusedParams
remove unused assignments if we can tell there are no side effects of the RHS.
findFunctionDefs picks up x$fun = function which is not necessarily good
z = getFunctionDefs("getFunctionDefsEg2.R") # file
z3 = getFunctionDefs(".") # directory
e = new.env(); source("getFunctionDefsEg2.R", e); ze = getFunctionDefs(e) # environment
z4 = getFunctionDefs(as.list.environment(e, TRUE)) # list
getFunctionDefs(z4$rec) # function object
getFunctionDefs(quote(function(x) x + 1)) # call
getFunctionDefs(quote(x <- function(x) x + 1)) # assignment call
z = getFunctionDefs("getFunctionDefsEg2.R", recursive = TRUE)
e = parse("getFunctionDefsEg2.R")
z2 = getFunctionDefs(e)
z2r = getFunctionDefs(e, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.