findLoopConcat | R Documentation |
This function helps to identify for
loops in R code
that uses the idiom
x = c() ; for(i in y) x = c(x, g(i))
This is a somewhat common idiom used by new R programmers.
It is very costly in memory and hence time.
Accordingly, we want to identify it as a problem.
At present, this function identifies the variables which are used in this concatenating manner. It does not currently rewrite the expressions.
findLoopConcat(expr, possibleVars = character())
expr |
the R expressions to search for the use of the concatenation idiom. |
possibleVars |
a character vector of names of variables that might be concatenated. This should not be provided by the caller. It is provided in recursive calls to the function. |
Currently, this returns a character vector identifying the variables that are concatenated using this idiom.
Duncan Temple Lang
e = quote({ x = c(); for(i in z) x = c(x, f(i)) })
findLoopConcat(e)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.