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 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.
?list.files -- Bert On Mon, May 14, 2012 at 12: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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Seemingly Similar Threads
- zero index and lazy evaluation in ifelse()
- lazy evaluation and DUP=F
- Re: Fwd: [PATCH] v2v: virtio-win: include *.dll too
- Problem using findVar( ) in combination with R's lazy evaluation
- [PATCH 0/3] v2v: windows: Use '*.inf' files to control how Windows drivers are installed.