findLoopConcat: Identify loop code that concatenates results

Description Usage Arguments Value Author(s) Examples

Description

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.

Usage

1
findLoopConcat(expr, possibleVars = character())

Arguments

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.

Value

Currently, this returns a character vector identifying the variables that are concatenated using this idiom.

Author(s)

Duncan Temple Lang

Examples

1
2
 e = quote({ x = c(); for(i in z)  x = c(x, f(i)) })
 findLoopConcat(e)

duncantl/CodeAnalysis documentation built on Aug. 11, 2019, 12:35 a.m.