Albert Vilella
2010-Jan-15 11:43 UTC
[R] processing all files with certain extension in a directory
Hi all, I'm trying to process all files with a certain extension "*.ext" in a directory like this:> R --slave --args /my/dir < dir_plot.rwhere I then I want to do something like: myarg <- commandArgs() inputdir <- myarg[length(myarg)] print(inputdir) "for file with extension "*.ext in inputdir" do data = process.data(file) outfile = paste(file,".png",sep="") png(outfile,width=3200,height=2400) do.a.plot(data) dev.off() done q() How can I do the file looping bit? Thanks in advance, Cheers, Albert.
Remko Duursma
2010-Jan-15 11:54 UTC
[R] processing all files with certain extension in a directory
Albert, try something like this: extfiles <- list.files(pattern=".ext") for(f in extfiles){ process.data(f) #etc } greetings, Remko ------------------------------------------------- Remko Duursma Post-Doctoral Fellow Centre for Plants and the Environment University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie University North Ryde NSW 2109 Australia Mobile: +61 (0)422 096908 www.remkoduursma.com On Fri, Jan 15, 2010 at 10:43 PM, Albert Vilella <avilella at gmail.com> wrote:> Hi all, > > I'm trying to process all files with a certain extension "*.ext" in a > directory like this: > >> R --slave --args /my/dir < dir_plot.r > > where I then I want to do something like: > > myarg <- commandArgs() > inputdir <- myarg[length(myarg)] > print(inputdir) > "for file with extension "*.ext in inputdir" > do > ?data = process.data(file) > ?outfile = paste(file,".png",sep="") > ?png(outfile,width=3200,height=2400) > ?do.a.plot(data) > ?dev.off() > done > q() > > How can I do the file looping bit? > > Thanks in advance, > > Cheers, > > Albert. > > ______________________________________________ > 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. >
Benilton Carvalho
2010-Jan-15 11:55 UTC
[R] processing all files with certain extension in a directory
theFiles <- list.files(inputdir, full=T, pattern="\\.[eE][xX][tT]$") for (file in theFiles){ ... } On Fri, Jan 15, 2010 at 11:43 AM, Albert Vilella <avilella at gmail.com> wrote:> Hi all, > > I'm trying to process all files with a certain extension "*.ext" in a > directory like this: > >> R --slave --args /my/dir < dir_plot.r > > where I then I want to do something like: > > myarg <- commandArgs() > inputdir <- myarg[length(myarg)] > print(inputdir) > "for file with extension "*.ext in inputdir" > do > data = process.data(file) > outfile = paste(file,".png",sep="") > png(outfile,width=3200,height=2400) > do.a.plot(data) > dev.off() > done > q() > > How can I do the file looping bit? > > Thanks in advance, > > Cheers, > > Albert. > > ______________________________________________ > 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. >