[R] R: selecting and excluding files through a pattern

Phil Spector spector at stat.berkeley.edu
Fri Jun 11 00:43:37 CEST 2010


Here's one possibility:

allfiles = list.files()
csvfiles = list.files(pattern='csv')
allfiles[!allfiles %in% csvfiles]

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Fri, 11 Jun 2010, mauede at alice.it wrote:

> Actually this pattern will select the files whose name contains "csv".
> Whereas I'd like to exscude them.
> Maura
>
> -----Messaggio originale-----
> Da: Jorge Ivan Velez [mailto:jorgeivanvelez at gmail.com]
> Inviato: gio 10/06/2010 17.30
> A: mauede at alice.it
> Cc: r-help at stat.math.ethz.ch
> Oggetto: Re: [R] selecting and excluding files through a pattern
>
> Hi Maura,
>
> Try  list.files(pattern = 'csv')
>
> HTH,
> Jorge
>
>
> On Thu, Jun 10, 2010 at 11:24 AM, <> wrote:
>
>> I have the following files list:
>>
>>> list.files()
>>  [1] "Prostate-Cancer_cvs_Dir"
>>  [2] "Prostate_Cancer-miRNAs&Genes.Pathway.xml"
>>  [3] "Prostate_Cancer_Pathways-miRNAs-GeneTargets-Dir"
>>  [4] "Prostate_Cancer_Pathways-miRNAs-GeneTargets-Dir.zip"
>>  [5] "Prostate-miRNAs.OrganTargets.txt"
>>  [6] "Prostate_Organ-miRNAs-GenesTargets-Dir"
>>  [7] "Prostate_Organ-miRNAs-GenesTargets-Dir.zip"
>>  [8] "Prostate_Organ-miRNAs-Targets.xml"
>>  [9] "Prostatic_Neoplasm-miRNAs.DiseaseTargets.csv-KO"
>> [10] "Prostatic_Neoplasm-miRNAs.DiseaseTargets.txt"
>> [11] "Prostatic_Neoplasms-miRNAs-GeneTargets-Dir"
>> [12] "Prostatic_Neoplasms-miRNAs-GeneTargets-Dir.zip"
>> [13] "Prostatic_Neoplasms-miRNAs.xml"
>>
>> I'd like to find the pattern expression which selects only the directories
>> excluding the one whose
>> pathname contains "csv".
>> I tried:
>>> list.files(pattern="Prostate*Dir")
>> But I do not know how to exclude the names containing the string "csv" at
>> the same time.
>>
>> Thank you for any help,
>> Maura
>>
>>
>>
>>
>> ;
>>
>>
>> tutti i telefonini TIM!
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org 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.
>>
>
>
>
>
> tutti i telefonini TIM!
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>



More information about the R-help mailing list