[R] check for new files in a given directory

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Jul 28 13:23:21 CEST 2009


On Tue, Jul 28, 2009 at 12:04 PM, Andreas Posch<andreas.posch at tugraz.at> wrote:
> I am trying to continuously evaluate online created data files using
> R-algorithms. Is there any simple way to let R iteratively check for new
> files in a given directory, load them and process them?
>
> Any help would be highly appreciated.

 list.files(dir) will tell you what files are in a directory.

 file.info(filepath) will tell you things about a file (modification time etc).

 Sys.sleep(n) will put R to sleep for n seconds so you don't have a
tight loop checking the directory every millisecond.

That's probably all the functionality you need, except maybe to keep
track of what files you consider 'new', and some way of deciding if
something has already been processed. But that's a bit
application-specific!

Barry




More information about the R-help mailing list