[R] Extracting File Basename without Extension

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Jan 9 22:20:47 CET 2009


> Duncan Murdoch wrote:
>   
>>
>> I'm curious about something: does "file extension" have a standard
>> definition?  Most (all?  I haven't tried them all) of the solutions
>> presented in this thread would return an empty string for the "plain
>> base" if given the filename ".bashrc".
>>     


right;  there's a straightforward fix to my solution that accounts for
cases such as '.bashrc':

names = c("foo.bar", ".zee")
sub("(.+)[.][^.]+$", "\\1", names)

you could also use a lookbehind if possible (not in r, afaik).

vQ




More information about the R-help mailing list