[R] Doubt about pattern

Gabor Grothendieck ggrothendieck at myway.com
Fri Jan 30 14:56:59 CET 2004


Your question has by now been answered but I thought
I would add that if you want to do it via file globbing on Windows
rather than regular expressions then this function would help:


list.files.glob <- function( spec ) {
   # returns list of files or NULL if none: spec uses globbing and can
   # use either forward or backward slashes. 
   # e.g list.files.glob( "c:/a*.*" )
   # e.g. list.files.glob( "c:/myfolder/my*.dat")
   # only works on Windows
   if ( substring(spec,2,2) != ":" ) spec <- paste( "C", spec, sep= ":" )
   z <- system( paste("cmd /c attrib", spec), intern = T, invisible = T)
   if ( !pmatch("File not found - ", z[1], nomatch = 0) )  substring(z,12)
}


For example:

   list.files.glob( "*.sens" )


On Thu, Jan 29, 2004 at 11:33:25AM -0300, Marcelo Luiz de Laia 
(mlaia at fcav.unesp.br) wrote:
> Hi All,
> 
> I have a very simple problem. I have several files in a same directory. I would like to send for an object only the files that finish in ".sens.". I execute the command below,
> 
> files <- dir(pattern="*.sens")
> 
> but it includes all of the files that have "sens", independent of they be in the end or in the middle of the name of the file. How could I solve this? I sought in the html_help but I didn't find similar to this.
> 
> My files
> 
> "script_sens.txt", "Sen_155_01_R1.sens", "Sen_155_01_R2.sens", "Sen_155_01_R3.sens", "Sen_155_02_R1.sens", "Sen_155_02_R2.sens", "Sen_155_02_R3.sens", "Sen_155_03_R1.sens", "Sen_155_03_R2.sens", "Sen_155_03_R3.sens", "tome2sens_time1sens.txt"
> 
> Tahnks very much
> 
> -- 
> Marcelo Luiz de Laia, M.Sc.
> Dep. de Tecnologia, Lab. Bioquímica e de Biologia Molecular
> Universidade Estadual Paulista - UNESP
> Via de Acesso Prof. Paulo Donato Castelane, Km 05
> 14.884-900 - Jaboticabal, SP, Brazil
> PhoneFax: 16 3209-2675/2676/2677 R. 202/208/203 (trab.)
> HomePhone: 16 3203 2328 - www.lbm.fcav.unesp.br - mlaia at yahoo.com
>




More information about the R-help mailing list