[R] Extracting File Basename without Extension

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Jan 9 15:24:34 CET 2009


Prof Brian Ripley wrote:
>
> Actually, that's a valid regex in any of the variants offered.  A more
> conventional writing of it is the second of
>
>> f <- 'foo.bar.R'
>> sub("[.][^.]*$", "", f)
> [1] "foo.bar"
>> sub("\\.[^.]*$", "", f)
> [1] "foo.bar"
>

more conventional in r, perhaps.  it's not portable, due to the 'escape
the escape to have an escape' feature of r when it comes to regexes; in
perl, for example, /\\.[^.]*$/ would hardly do the job.

vQ




More information about the R-help mailing list