[R] Partial file name

Duncan Murdoch murdoch at stats.uwo.ca
Thu Feb 8 13:03:58 CET 2007


On 2/8/2007 6:51 AM, Jerry Pressnell wrote:
> Hello all,
> 
>  
> 
> I wish to write an R script to read a specific .txt file each day. The file
> is downloaded from a external source and the file name is the same three
> letters followed by the date and time of download.
> 
>  
> 
> For example
> 
>  
> 
> Day 1
> 
>  
> 
> AAA_08_02_2007_06_18_98.txt
> 
>  
> 
> Day 2
> 
>  
> 
> AAA_09_02_2007_10_12_03.txt
> 
>  
> 
> Is it possible to use read.table() in such a way that it only needs the
> start of the file name?

read.table() would need the full name, but other functions could give 
that to you.  For example, this should work, assuming there's always 
just one file that will match:

read.table( list.files( pattern = "^AAA_" ) )

or if you like file system wildcards better than regular expressions,

read.table( list.files( pattern = glob2rx("AAA_*") ) )

Duncan Murdoch



More information about the R-help mailing list