[R] Run script automatically on several input files in the directory and produce separate outputs?

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Dec 5 15:20:47 CET 2014

Dear Thomas,

list.files() will be your new best friend.

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx op inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: R-help [mailto:r-help-bounces op r-project.org] Namens Thomas Barningham
Verzonden: vrijdag 5 december 2014 14:41
Aan: r-help op r-project.org
Onderwerp: [R] Run script automatically on several input files in the directory and produce separate outputs?


I have written a script that currently reads in a .txt file where I specify the name e.g

mydata<-read.table("a_date.txt", header=TRUE)

The script eventually produces a plot, e.g:


What I want to do is run this script on several input files in my directory, without having to manually change the input file name each time, and produce the output plot pdf with the input file name as the output file name. It would also be handy if my plot title is also the input file name.

I'm relatively new to R so i'm not sure how to approach this. I presume it's some sort of loop function, but i've never implemented one of these before - any advice would be greatly appreciated!

Thanks in advance!
Thomas Barningham
Centre for Ocean and Atmospheric Sciences School of Environmental Sciences University of East Anglia Norwich Research Park Norwich

R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
**** D I S C L A I M E R ****
Bezoek onze website/Visit our website<https://drupal.inbo.be/nl/disclaimer-mailberichten-van-het-inbo>

More information about the R-help mailing list