[R] Inf and lazy evaluation
J Toll
jctoll at gmail.com
Mon May 14 21:34:18 CEST 2012
Hi,
I have a question involving Inf, lazy evaluation, and maybe argument
recycling. I have a directory where I am trying to check for the
existence of files of a certain pattern, basically something like
"filename-#", where # is an integer. I can do something like this,
which works.
file.exists(paste(filename, "-", 1:100, sep = ""))
But I don't like the fact that I am only checking the first 100
possibilities. What I would prefer is this:
file.exists(paste(filename, "-", 1:Inf, sep = ""))
But that doesn't work, I get the error:
Error in 1:Inf : result would be too long a vector
On one hand, with lazy evaluation, you would think that 1:Inf should
work. On the other hand, I'm not quite sure what the output would be
if it was working, especially if there were large gaps in the
integers. Is there a way to get the behavior I seek (i.e. the lazy
evaluation of 1:Inf).
Thanks,
James
More information about the R-help
mailing list