[R] regexpr and portability issue

From: Marco Blanchette <mblanche_at_uclink.berkeley.edu>
Date: Wed 03 Aug 2005 - 15:26:30 EST

Dear all--

I am still forging my first arms with R and I am fighting with regexpr() as well as portability between unix and windoz. I need to extract barcodes from filenames (which are located between a double and single underscore) as well as the directory where the filename is residing. Here is the solution I came to:

aFileName <-
"/Users/marco/Desktop/diagnosticAnalysis/test/MA__251329410021_S01_A01.txt" t <- regexpr("__\\d*_",aFileName, perl=T) t.dir <- regexpr("^.*/", aFileName, perl=T) base.name <- substr(aFileName, t+2, t-2 + attr(t,"match.length")) base.dir <- substr(aFileName, t.dir, attr(t.dir,"match.length"))

My questions are:
1) Is there a more elegant way to deal with regular expressions (read here: more easier, more like perl style).
2) I have a portability problem when I extract the base.dir Windoz is using '\' instead of '/' to separate directories.

Any suggestions/comments

Many Tx

Marco Blanchette, Ph.D.


Donald C. Rio's lab
Department of Molecular and Cell Biology 16 Barker Hall
University of California
Berkeley, CA 94720-3204

Tel: (510) 642-1084
Cell: (510) 847-0996
Fax: (510) 642-6062

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Aug 03 15:33:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:39 EST