list.fileswill only be evaluated once when you use it in a for loop, like the one you suggest. The easiest way to check this is to wrap the call list.filesin another function call, for example:
f <- function() { print("Calling f"); list.files() }
and use this for for loop:
for (infile in f())
{
print(infile)
}
source
share