Skip to content
Prev 74824 / 398502 Next

regexpr and portability issue

On Tue, 2 Aug 2005, Marco Blanchette wrote:

            
Yes, use sub and backreferences.  An example from the R sources doing 
something similar:

             wfile <- sub("/chm/([^/]*)$", "", file)
             thispkg <- sub(".*/([^/]*)/chm/([^/]*)$", "\\1", file)

However, R does have functions basename() and dirname() to do this!
That is misinformation: Windows (sic) accepts either / or \ (see the 
rw-FAQ and the R FAQ).  Use chartr("\\", "/", path) to map \ to /.

The `portability problem' appears to be of your own making -- take heart 
that R itself manages to manipulate filepaths portably.