The S+ basename() function has an argument called suffix and
it will remove the suffix from the result. This was based on
the Unix basename command, but I missed the special case in the
Unix basename that doesn't remove the suffix if the removal
would result in an empty string. The suffix must in
Gabor Grothendieck wrote:
> On Fri, Jan 9, 2009 at 4:28 PM, Wacek Kusnierczyk
> wrote:
>
>> Rau, Roland wrote:
>>
>>> P.S. Any suggestions how to become more proficient with regular
>>> expressions? The O'Reilly book ("Mastering...")? Whenever I tried
>>> anything more complicated than bas
Gabor Grothendieck wrote:
> On Fri, Jan 9, 2009 at 4:20 PM, Wacek Kusnierczyk
>
>
>> 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 i
On Fri, Jan 9, 2009 at 4:28 PM, Wacek Kusnierczyk
wrote:
> Rau, Roland wrote:
>>
>> P.S. Any suggestions how to become more proficient with regular
>> expressions? The O'Reilly book ("Mastering...")? Whenever I tried
>> anything more complicated than basic usage (things like ^ $ * . ) in R,
>> I w
On Fri, Jan 9, 2009 at 4:20 PM, Wacek Kusnierczyk
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 th
Rau, Roland wrote:
>
> P.S. Any suggestions how to become more proficient with regular
> expressions? The O'Reilly book ("Mastering...")? Whenever I tried
> anything more complicated than basic usage (things like ^ $ * . ) in R,
> I was way faster to write a new function (like above) instead of fin
> 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".
>>
r
on 01/09/2009 09:00 AM Duncan Murdoch wrote:
> On 1/8/2009 9:10 PM, Gundala Viswanath wrote:
>> Dear all,
>>
>> The basename() function returns the extension also:
>>
>>> myfile <- "path1/path2/myoutput.txt"
>>> basename(myfile)
>> [1] "myoutput.txt"
>>
>>
>> Is there any other function where it ju
Duncan Murdoch wrote:
> On 1/8/2009 9:10 PM, Gundala Viswanath wrote:
>> Dear all,
>>
>> The basename() function returns the extension also:
>>
>>> myfile <- "path1/path2/myoutput.txt"
>>> basename(myfile)
>> [1] "myoutput.txt"
>>
>>
>> Is there any other function where it just returns
>> plain bas
On Fri, Jan 9, 2009 at 10:23 AM, Rau, Roland wrote:
> Hi,
>
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique
>> Dallazuanna
>>
>> Try this also:
>>
>> substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
>>
>
> This, of course, assumes that the extensions are always 3 characters.
Hi,
> [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique
> Dallazuanna
>
> Try this also:
>
> substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
>
This, of course, assumes that the extensions are always 3 characters.
Sometimes there might be more ("index.html"), sometimes less
On 1/8/2009 9:10 PM, Gundala Viswanath wrote:
Dear all,
The basename() function returns the extension also:
myfile <- "path1/path2/myoutput.txt"
basename(myfile)
[1] "myoutput.txt"
Is there any other function where it just returns
plain base:
"myoutput"
i.e. without 'txt'
I'm curious ab
Right,
Other option is:
substr(nameFile, 1, tail(unlist(gregexpr("\\.", nameFile)), 1) - 1)
On Fri, Jan 9, 2009 at 1:23 PM, Rau, Roland wrote:
> Hi,
>
> > [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique
> > Dallazuanna
> >
> > Try this also:
> >
> > substr(basename(myfile), 1, nc
G'day Wacek,
On Fri, 09 Jan 2009 15:19:46 +0100
Wacek Kusnierczyk wrote:
> i think i did not suggest the original poster to learn perl.
As I see it, you didn't suggest anything to the original poster, at
least not directly. But, since these days you have to be subscribed
to r-help to post IIRC
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
Berwin A Turlach wrote:
> G'day Wacek,
>
> On Fri, 09 Jan 2009 14:22:19 +0100
> Wacek Kusnierczyk wrote:
>
>
>>> Apparently also a possibility, I guess it can be made to work with
>>> the original example and my extensions.
>>>
>>>
>> i guess it does work with the original example and
On Fri, 9 Jan 2009, Berwin A Turlach wrote:
G'day Wacek,
On Fri, 09 Jan 2009 12:52:46 +0100
Wacek Kusnierczyk wrote:
Berwin A Turlach wrote:
G'day all,
On Fri, 9 Jan 2009 08:12:18 -0200
"Henrique Dallazuanna" wrote:
Try this also:
substr(basename(myfile), 1, nchar(basename(myfile)) -
G'day Wacek,
On Fri, 09 Jan 2009 14:22:19 +0100
Wacek Kusnierczyk wrote:
> > Apparently also a possibility, I guess it can be made to work with
> > the original example and my extensions.
> >
>
> i guess it does work with the original example and your extensions.
And I thought that you woul
Berwin A Turlach wrote:
> G'day Wacek,
>
>
>
>>> Or, in case that the extension has more than three letters or
>>> "myfile" is a vector of names:
>>>
>>> R> myfile <- "path1/path2/myoutput.txt"
>>> R> sapply(strsplit(basename(myfile),"\\."), function(x)
>>> R> paste(x[1:(length(x)-1)], collapse=
G'day Wacek,
On Fri, 09 Jan 2009 12:52:46 +0100
Wacek Kusnierczyk wrote:
> Berwin A Turlach wrote:
> > G'day all,
> >
> > On Fri, 9 Jan 2009 08:12:18 -0200
> > "Henrique Dallazuanna" wrote:
> >
> >
> >> Try this also:
> >>
> >> substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
> >>
Gabor Grothendieck wrote:
> On Fri, Jan 9, 2009 at 6:52 AM, Wacek Kusnierczyk
>
>
>> or have sub do the job for you:
>>
>> filenames.ext = c("foo.bar", basename("foo/bar/hello.dolly"))
>> (filenames.noext = sub("[.][^.]*$", "", filenames.ext, perl=TRUE))
>>
>
> We can omit perl = TRUE here.
On Fri, Jan 9, 2009 at 6:52 AM, Wacek Kusnierczyk
wrote:
> Berwin A Turlach wrote:
>> G'day all,
>>
>> On Fri, 9 Jan 2009 08:12:18 -0200
>> "Henrique Dallazuanna" wrote:
>>
>>
>>> Try this also:
>>>
>>> substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
>>>
>>
>> Or, in case that the extens
Berwin A Turlach wrote:
> G'day all,
>
> On Fri, 9 Jan 2009 08:12:18 -0200
> "Henrique Dallazuanna" wrote:
>
>
>> Try this also:
>>
>> substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
>>
>
> Or, in case that the extension has more than three letters or "myfile"
> is a vector of nam
G'day all,
On Fri, 9 Jan 2009 08:12:18 -0200
"Henrique Dallazuanna" wrote:
> Try this also:
>
> substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
Or, in case that the extension has more than three letters or "myfile"
is a vector of names:
R> myfile <- "path1/path2/myoutput.txt"
R> sapp
Try this also:
substr(basename(myfile), 1, nchar(basename(myfile)) - 4)
On Fri, Jan 9, 2009 at 12:10 AM, Gundala Viswanath wrote:
> Dear all,
>
> The basename() function returns the extension also:
>
> > myfile <- "path1/path2/myoutput.txt"
> > basename(myfile)
> [1] "myoutput.txt"
>
>
> Is ther
You can use 'sub' to get rid of the extensions:
> sub("^([^.]*).*", "\\1", 'filename.extension')
[1] "filename"
> sub("^([^.]*).*", "\\1", 'filename.extension.and.more')
[1] "filename"
> sub("^([^.]*).*", "\\1", 'filename without extension')
[1] "filename without extension"
On Thu, Jan 8, 2009 a
Dear all,
The basename() function returns the extension also:
> myfile <- "path1/path2/myoutput.txt"
> basename(myfile)
[1] "myoutput.txt"
Is there any other function where it just returns
plain base:
"myoutput"
i.e. without 'txt'
- Gundala Viswanath
Jakarta - Indonesia
27 matches
Mail list logo