[R] Regular Expressionsionism
Derek Eder
Derek.Eder at neuro.gu.se
Fri Nov 29 18:16:12 CET 2002
Isn't there a cryptic footnote somewhere in the blue book that describes regular expressions as "a funny little language ..." ? Well, I'm not laughing!
I've googled and Man paged, but the GREP-style solution to the following problem still eludes me:
... Using a regular expression in the "pattern" argument to list.files() to restrict the return to filenames which
contain both "Elstim" and "post". E.g.,
>list.files()
...
[133] "J30710_Control_msa_amplitude_5_25_s1-30w.pre"
[134] "J30710_Elstim_msa_amplitude_5_25_s1-30w.post"
[135] "J30710_Elstim_msa_amplitude_5_25_s1-30w.pre"
[136] "J30712_Control_msa_amplitude_5_25_s1-41_44-46_48w.post"
[137] "J30712_Control_msa_amplitude_5_25_s1-41_44-46_48w.pre"
[138] "J30712_Elstim_msa_amplitude_5_25_s1-17_19-43_45_48w.post"
I have not found the key to generating the logical AND equivalent of the "|" OR infix operator, a
proxy for the simpleton's dream: my.list.files(pattern="*Elstim" & "*post")
Thanks
- Derek
P.S.,
Of course I could always do this in stages:
> elstims <- list.files(pattern = "Elstim") # all the files with "Elstim"
> ElPostinos <- grep("post",elstims) # all the elstim files with "post"
> my.file.list <- elstims[ElPostinos] # result: list of filenames
But my conscience would bother me for taking the easy way out.
Derek N. Eder
Göteborgs Universitet
Institutionen för klinisk neurovetenskap
Klinisk Neurofysiologi
Sahlgrenska universitetssjukhuset SS/SU
Blå stråket 7, vån 3
SE 413 45 Göteborg
Sverige
Tlf. +46 (031) 34 244 14 (office) NYTT!
Tlf. +46 (031) 34 212 83 (laboratory)
Tlf. +46 0709 / 7 212 83 (mobil)
Fax. +46 (031) 82 81 63
derek.eder at neuro.gu.se
Gothenburg University
Institute of Clinical Neuroscience,
Department of Clinical Neurophysiology
Salhgrenska Hospital SU/SS
SE 413 45 Göteborg
Sweden
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list