Quantcast

processing all files with certain extension in a directory

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

processing all files with certain extension in a directory

Albert Vilella
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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: processing all files with certain extension in a directory

Remko Duursma
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: processing all files with certain extension in a directory

Benilton Carvalho-2
In reply to this post by Albert Vilella
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Loading...