[R] Inf and lazy evaluation

R. Michael Weylandt michael.weylandt at gmail.com
Mon May 14 21:45:15 CEST 2012


R is lazy, but not quite that lazy ;-)

It's likely much easier to do this with regexps

something like

list.files()[grepl(paste0(filename, "-"[0123456789]+""), list.files())]

Michael


On Mon, May 14, 2012 at 3:34 PM, J Toll <jctoll at gmail.com> wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list