Message-ID: <971536df0901091448p23d87894u406a7a9062db48d1@mail.gmail.com>
Date: 2009-01-09T22:48:53Z
From: Gabor Grothendieck
Subject: Extracting File Basename without Extension
In-Reply-To: <4967BFAF.90609@idi.ntnu.no>
On Fri, Jan 9, 2009 at 4:20 PM, Wacek Kusnierczyk
<Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
>
>> 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).
>
or:
> sub(".*[.]", ".", names)
[1] ".bar" ".zee"