[R] Extracting File Basename without Extension

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jan 9 23:48:53 CET 2009


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"




More information about the R-help mailing list